Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion build-scripts/compile_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import sys
import os.path
from copy import deepcopy
from glob import glob

import ssg.build_yaml
Expand Down Expand Up @@ -36,7 +37,8 @@ def resolve(self, all_profiles):
updated_variables.update(self.variables)
self.variables = updated_variables

updated_refinements = dict(extended_profile.refine_rules)
extended_refinements = deepcopy(extended_profile.refine_rules)
updated_refinements = self._subtract_refinements(extended_refinements)
updated_refinements.update(self.refine_rules)
self.refine_rules = updated_refinements

Expand All @@ -50,6 +52,18 @@ def resolve(self, all_profiles):

self.resolved = True

def _subtract_refinements(self, extended_refinements):
"""
Given a dict of rule refinements from the extended profile,
"undo" every refinement prefixed with '!' in this profile.
"""
for rule, refinements in list(self.refine_rules.items()):
if rule.startswith("!"):
for prop, val in refinements:
extended_refinements[rule[1:]].remove((prop, val))
del self.refine_rules[rule]
return extended_refinements


def create_parser():
parser = argparse.ArgumentParser()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ rationale: |-

severity: medium

identifiers:
cce@rhel8: 83321-0

ocil_clause: 'auditing is not enabled at boot time'

ocil: |-
Expand All @@ -28,3 +31,9 @@ ocil: |-
No line should be returned, each line returned is a boot entry that doesn't enable audit.

platform: machine

template:
name: zipl_bls_entries_option
vars:
arg_name: audit
arg_value: '1'
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ rationale: |-

severity: medium

identifiers:
cce@rhel8: 83341-8

ocil_clause: 'audit backlog limit is not configured'

ocil: |-
To check that all boot entries extend the backlog limit;
Check that all boot entries extend the log events queue:
<pre>sudo grep -L "^options\s+.*\baudit_backlog_limit=0\b" /boot/loader/entries/*.conf</pre>
<pre>sudo grep -L "^options\s+.*\baudit_backlog_limit=8192\b" /boot/loader/entries/*.conf</pre>
No line should be returned, each line returned is a boot entry that does not extend the log events queue.

platform: machine

template:
name: zipl_bls_entries_option
vars:
arg_name: audit_backlog_limit
arg_value: '8192'
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ rationale: |-

severity: medium

identifiers:
cce@rhel8: 83351-7

ocil_clause: 'page allocator poisoning is not enabled'

ocil: |-
Expand All @@ -28,3 +31,9 @@ ocil: |-
No line should be returned, each line returned is a boot entry that doesn't enable page poisoning.

platform: machine

template:
name: zipl_bls_entries_option
vars:
arg_name: page_poison
arg_value: '1'
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ rationale: |-

severity: medium

identifiers:
cce@rhel8: 83361-6

ocil_clause: 'Kernel page-table isolation is not enabled'

ocil: |-
Expand All @@ -27,3 +30,9 @@ ocil: |-
No line should be returned, each line returned is a boot entry that doesn't enable page-table isolation .

platform: machine

template:
name: zipl_bls_entries_option
vars:
arg_name: pti
arg_value: 'on'
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: |-
To enable poisoning of SLUB/SLAB objects,
check that all boot entries in <tt>/boot/loader/entries/*.conf</tt> have <tt>slub_debug=P</tt>
included in its options.<br />
To ensure that new kernels and boot entries continue to extend the audit log events queue,
To ensure that new kernels and boot entries continue to enable poisoning of SLUB/SLAB objects,
add <tt>slub_debug=P</tt> to <tt>/etc/kernel/cmdline</tt>.

rationale: |-
Expand All @@ -20,6 +20,9 @@ rationale: |-

severity: medium

identifiers:
cce@rhel8: 83371-5

ocil_clause: 'SLUB/SLAB poisoning is not enabled'

ocil: |-
Expand All @@ -28,3 +31,9 @@ ocil: |-
No line should be returned, each line returned is a boot entry that does not enable poisoning.

platform: machine

template:
name: zipl_bls_entries_option
vars:
arg_name: slub_debug
arg_value: 'P'
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ rationale: |-

severity: medium

identifiers:
cce@rhel8: 83381-4

ocil_clause: 'vsyscalls are enabled'

ocil: |-
Expand All @@ -25,3 +28,9 @@ ocil: |-
No line should be returned, each line returned is a boot entry that doesn't disable virtual syscalls.

platform: machine

template:
name: zipl_bls_entries_option
vars:
arg_name: vsyscall
arg_value: 'none'
8 changes: 8 additions & 0 deletions rhel8/profiles/ospp.profile
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,11 @@ selections:
# zIPl specific rules
- zipl_bls_entries_only
- zipl_bootmap_is_up_to_date
- zipl_audit_argument
- zipl_audit_backlog_limit_argument
- zipl_slub_debug_argument
- zipl_page_poison_argument
- zipl_vsyscall_argument
- zipl_vsyscall_argument.role=unscored
- zipl_vsyscall_argument.severity=info
- zipl_pti_argument
8 changes: 8 additions & 0 deletions rhel8/profiles/stig.profile
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ selections:
# Unselect zIPL rules from OSPP
- "!zipl_bls_entries_only"
- "!zipl_bootmap_is_up_to_date"
- "!zipl_audit_argument"
- "!zipl_audit_backlog_limit_argument"
- "!zipl_page_poison_argument"
- "!zipl_pti_argument"
- "!zipl_slub_debug_argument"
- "!zipl_vsyscall_argument"
- "!zipl_vsyscall_argument.role=unscored"
- "!zipl_vsyscall_argument.severity=info"
6 changes: 0 additions & 6 deletions shared/references/cce-redhat-avail.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ CCE-83317-8
CCE-83318-6
CCE-83319-4
CCE-83320-2
CCE-83321-0
CCE-83322-8
CCE-83327-7
CCE-83328-5
Expand All @@ -32,22 +31,19 @@ CCE-83333-5
CCE-83336-8
CCE-83339-2
CCE-83340-0
CCE-83341-8
CCE-83342-6
CCE-83343-4
CCE-83344-2
CCE-83345-9
CCE-83346-7
CCE-83349-1
CCE-83350-9
CCE-83351-7
CCE-83352-5
CCE-83353-3
CCE-83354-1
CCE-83355-8
CCE-83356-6
CCE-83358-2
CCE-83361-6
CCE-83362-4
CCE-83363-2
CCE-83364-0
Expand All @@ -57,7 +53,6 @@ CCE-83367-3
CCE-83368-1
CCE-83369-9
CCE-83370-7
CCE-83371-5
CCE-83372-3
CCE-83373-1
CCE-83374-9
Expand All @@ -66,7 +61,6 @@ CCE-83376-4
CCE-83377-2
CCE-83378-0
CCE-83379-8
CCE-83381-4
CCE-83382-2
CCE-83383-0
CCE-83384-8
Expand Down
48 changes: 48 additions & 0 deletions shared/templates/template_ANSIBLE_zipl_bls_entries_option
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# platform = Red Hat Enterprise Linux 8
# reboot = true
# strategy = configure
# complexity = medium
# disruption = low

- name: "Ensure BLS boot entries options contain {{{ ARG_NAME_VALUE }}}"
block:
- name: "Check if any boot entry misses {{{ ARG_NAME_VALUE }}}"
find:
paths: "/boot/loader/entries/"
contains: "^options .*{{{ ARG_NAME_VALUE }}}.*$"
patterns: "*.conf"
register: entries_options

- name: "Update boot entries options"
command: grubby --update-kernel=ALL --args="{{{ ARG_NAME_VALUE }}}"
when: entries_options is defined and entries_options.examined != entries_options.matched
# The conditional above assumes that only *.conf files are present in /boot/loader/entries
Comment thread
yuumasato marked this conversation as resolved.
Outdated
# Then, the number of conf files is the same as examined files

- name: "Check if /etc/kernel/cmdline exists"
stat:
path: /etc/kernel/cmdline
register: cmdline_stat

- name: "Check if /etc/kernel/cmdline contains {{{ ARG_NAME_VALUE }}}"
find:
paths: "/etc/kernel/"
patterns: "cmdline"
contains: "^.*{{{ ARG_NAME_VALUE }}}.*$"
register: cmdline_find

- name: "Add /etc/kernel/cmdline contains {{{ ARG_NAME_VALUE }}}"
lineinfile:
create: yes
path: "/etc/kernel/cmdline"
line: '{{{ ARG_NAME_VALUE }}}'
when: cmdline_stat is defined and not cmdline_stat.stat.exists

- name: "Append /etc/kernel/cmdline contains {{{ ARG_NAME_VALUE }}}"
lineinfile:
path: "/etc/kernel/cmdline"
backrefs: yes
regexp: "^(.*)$"
line: '\1 {{{ ARG_NAME_VALUE }}}'
when: cmdline_stat is defined and cmdline_stat.stat.exists and cmdline_find is defined and cmdline_find.matched == 0

12 changes: 12 additions & 0 deletions shared/templates/template_BASH_zipl_bls_entries_option
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# platform = Red Hat Enterprise Linux 8

# Correct BLS option using grubby, which is a thin wrapper around BLS operations
grubby --update-kernel=ALL --args="{{{ ARG_NAME_VALUE }}}"

# Ensure new kernels and boot entries retain the boot option
if [ ! -f /etc/kernel/cmdline ]; then
echo "{{{ ARG_NAME_VALUE }}}" >> /etc/kernel/cmdline
elif ! grep -q '^(.*\s)?{{{ ARG_NAME_VALUE }}}(\s.*)?$' /etc/kernel/cmdline; then
echo " audit=1" >> /etc/kernel/cmdline
Comment thread
yuumasato marked this conversation as resolved.
Outdated
sed -Ei 's/^(.*)$/\1 audit=1/' /etc/kernel/cmdline
Comment thread
yuumasato marked this conversation as resolved.
Outdated
Comment thread
yuumasato marked this conversation as resolved.
Outdated
fi
47 changes: 47 additions & 0 deletions shared/templates/template_OVAL_zipl_bls_entries_option
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<def-group>
<definition class="compliance" id="{{{ _RULE_ID }}}" version="1">
<metadata>
<title>Ensure that BLS-compatible boot loader is configured to run Linux operating system with argument {{{ ARG_NAME_VALUE }}}</title>
{{{- oval_affected(products) }}}
<description>Ensure {{{ ARG_NAME_VALUE }}} option is configured in the 'options' line in /boot/loader/entries/*.conf.</description>
</metadata>
<criteria operator="AND">
<criterion test_ref="test_bls_{{{ SANITIZED_ARG_NAME }}}_options"
comment="Check if {{{ ARG_NAME_VALUE }}} is present in the 'options' line in /boot/loader/entries/*" />
Comment thread
yuumasato marked this conversation as resolved.
Outdated
<criterion test_ref="test_kernel_update_{{{ SANITIZED_ARG_NAME }}}_option"
comment="Make sure that newly installed kernels will retain {{{ ARG_NAME_VALUE }}} option" />
</criteria>
</definition>

<ind:textfilecontent54_test id="test_bls_{{{ SANITIZED_ARG_NAME }}}_options"
comment="check for kernel option {{{ ARG_NAME_VALUE }}} for all snippets in /boot/loader/entries"
check="all" check_existence="all_exist" version="1">
<ind:object object_ref="object_bls_{{{ SANITIZED_ARG_NAME }}}_options" />
<ind:state state_ref="state_bls_{{{ SANITIZED_ARG_NAME }}}_option" />
</ind:textfilecontent54_test>

<ind:textfilecontent54_object id="object_bls_{{{ SANITIZED_ARG_NAME }}}_options"
version="1">
<ind:filepath operation="pattern match">^/boot/loader/entries/.*\.conf$</ind:filepath>
<ind:pattern operation="pattern match">^options (.*)$</ind:pattern>
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
</ind:textfilecontent54_object>

<ind:textfilecontent54_test id="test_kernel_update_{{{ SANITIZED_ARG_NAME }}}_option"
comment="Check for option {{{ ARG_NAME_VALUE }}} in /etc/kernel/cmdline"
check="all" check_existence="all_exist" version="1">
<ind:object object_ref="object_kernel_update_{{{ SANITIZED_ARG_NAME }}}_option" />
<ind:state state_ref="state_bls_{{{ SANITIZED_ARG_NAME }}}_option" />
</ind:textfilecontent54_test>
<ind:textfilecontent54_object id="object_kernel_update_{{{ SANITIZED_ARG_NAME }}}_option"
version="1">
<ind:filepath>/etc/kernel/cmdline</ind:filepath>
<ind:pattern operation="pattern match">^(.*)$</ind:pattern>
<ind:instance datatype="int" operation="greater than or equal">1</ind:instance>
</ind:textfilecontent54_object>

<ind:textfilecontent54_state id="state_bls_{{{ SANITIZED_ARG_NAME }}}_option"
version="1">
<ind:subexpression datatype="string" operation="pattern match">^(?:.*\s)?{{{ ESCAPED_ARG_NAME_VALUE }}}(?:\s.*)?$</ind:subexpression>
</ind:textfilecontent54_state>
</def-group>
5 changes: 5 additions & 0 deletions ssg/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ def bls_entries_option(data, lang):
return data


@template(["ansible", "bash", "oval"])
def zipl_bls_entries_option(data, lang):
return bls_entries_option(data, lang)


class Builder(object):
"""
Class for building all templated content for a given product.
Expand Down
Loading