Skip to content

Commit 36a99f0

Browse files
committed
Fix crypto policy settings in RHEL 8 CIS
Add a new rule `crypto_sub_policies_cis_rhel8` that configures multiple custom crypto sub policy modules for RHEL 8 CIS. The new rule is very similar to `fips_custom_stig_sub_policy`. It configures new modules for system wide crypto policies that reduces the set of usable ciphers in sshd, MACs, and others. The rule is templated by a new template `crypto_sub_policies` that is also introduced in this commit so that the code can be reused in other similar rules. This change aligns the RHEL 8 CIS profiles in CaC with the CIS RHEL 8 Benchmark v4.0.0 requirements. All crypto requirements of this profile are now covered by this single rule. The reason for merging all of the sub module configuration is to prevent overriding crypto policy settings. If there would be multiple rules, each of them would call the `update-crypto-policies` commands with a different sub policy, overriding each other. This supersedes ComplianceAsCode#14050 Resolves: https://issues.redhat.com/browse/RHEL-111896
1 parent 98b7a95 commit 36a99f0

File tree

23 files changed

+238
-44
lines changed

23 files changed

+238
-44
lines changed

components/crypto-policies.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ rules:
1212
- configure_openssl_crypto_policy
1313
- configure_openssl_tls_crypto_policy
1414
- configure_ssh_crypto_policy
15+
- crypto_sub_policies_cis_rhel8
1516
- harden_openssl_crypto_policy
1617
- harden_ssh_client_crypto_policy
1718
- harden_sshd_ciphers_openssh_conf_crypto_policy

components/openssh.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ packages:
99
- openssh-clients
1010
- openssh-server
1111
rules:
12+
- crypto_sub_policies_cis_rhel8
1213
- directory_groupowner_sshd_config_d
1314
- directory_owner_sshd_config_d
1415
- directory_permissions_sshd_config_d

controls/cis_rhel8.yml

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,7 @@ controls:
537537
- l1_workstation
538538
status: automated
539539
rules:
540-
- configure_crypto_policy
541-
- var_system_crypto_policy=default_nosha1
540+
- crypto_sub_policies_cis_rhel8
542541

543542
- id: 1.6.2
544543
title: Ensure system wide crypto policy disables sha1 hash and signature support (Automated)
@@ -549,31 +548,25 @@ controls:
549548
notes: |-
550549
This requirement is already satisfied by 1.6.1.
551550
related_rules:
552-
- configure_crypto_policy
551+
- crypto_sub_policies_cis_rhel8
553552

554553
- id: 1.6.3
555554
title: Ensure system wide crypto policy disables cbc for ssh (Automated)
556555
levels:
557556
- l1_server
558557
- l1_workstation
559-
status: pending
560-
notes: |-
561-
It is necessary a new rule to ensure a module disabling CBC in
562-
/etc/crypto-policies/policies/modules/ so it can be used by update-crypto-policies command.
563-
related_rules:
564-
- configure_crypto_policy
558+
status: automated
559+
rules:
560+
- crypto_sub_policies_cis_rhel8
565561

566562
- id: 1.6.4
567563
title: Ensure system wide crypto policy disables macs less than 128 bits (Automated)
568564
levels:
569565
- l1_server
570566
- l1_workstation
571-
status: pending
572-
notes: |-
573-
It is necessary a new rule to ensure a module disabling weak MACs in
574-
/etc/crypto-policies/policies/modules/ so it can be used by update-crypto-policies command.
575-
related_rules:
576-
- configure_crypto_policy
567+
status: automated
568+
rules:
569+
- crypto_sub_policies_cis_rhel8
577570

578571
- id: 1.7.1
579572
title: Ensure message of the day is configured properly (Automated)
@@ -1504,8 +1497,7 @@ controls:
15041497
notes: |-
15051498
Introduced in CIS RHEL8 v3.0.0
15061499
rules:
1507-
- sshd_use_approved_ciphers
1508-
- sshd_approved_ciphers=cis_rhel8
1500+
- crypto_sub_policies_cis_rhel8
15091501

15101502
- id: 4.2.7
15111503
title: Ensure sshd ClientAliveInterval and ClientAliveCountMax are configured (Automated)
@@ -1594,8 +1586,7 @@ controls:
15941586
- l1_workstation
15951587
status: automated
15961588
rules:
1597-
- sshd_use_strong_macs
1598-
- sshd_strong_macs=cis_rhel8
1589+
- crypto_sub_policies_cis_rhel8
15991590

16001591
- id: 4.2.15
16011592
title: Ensure sshd MaxAuthTries is configured (Automated)

docs/templates/template_reference.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,27 @@
253253

254254
- Languages: OVAL, Kubernetes
255255

256+
#### crypto_sub_policies
257+
- Configures a sub policy for system wide crypto policies. Creates a module
258+
file `module_name.pmod` in `/etc/crypto-policies/policies/modules/` that
259+
contains `key = value`. Then, it applies this module. The template allows
260+
to specify multiple crypto policy sub modules at once, which is convenient
261+
for use in benchmarks that require multiple custom crypto settings.
262+
263+
- Parameters:
264+
265+
- **base_policy** - The base system wide crypto policy, eg. `DEFAULT`
266+
267+
- **sub_policies** - A list of dictionaries. Each dictionary represents one custom crypto sub policy module. The dictionary has the following members:
268+
269+
- **module_name** - crypto sub policy name, eg. `NO-SSHWEAKCIPHERS`
270+
271+
- **key** - entry key, eg. `cipher@SSH`
272+
273+
- **value** - entry value, eg. `-3DES-CBC -AES-128-CBC -AES-192-CBC -AES-256-CBC -CHACHA20-POLY1305`
274+
275+
- Languages: Ansible, Bash, OVAL
276+
256277
#### dconf_ini_file
257278
- Checks for `dconf` configuration. Additionally checks if the
258279
configuration is locked so it cannot be overridden by the user.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
documentation_complete: true
2+
3+
title: Implement Custom Crypto Policy Modules for CIS Benchmark for Red Hat Enterprise Linux 8
4+
5+
{{% set sub_policies = [
6+
{
7+
"module_name": "NO-SSHCBC",
8+
"key": "cipher@SSH",
9+
"value": "-*-CBC"
10+
},
11+
{
12+
"module_name": "NO-SSHWEAKCIPHERS",
13+
"key": "cipher@SSH",
14+
"value": "-3DES-CBC -AES-128-CBC -AES-192-CBC -AES-256-CBC -CHACHA20-POLY1305"
15+
},
16+
{
17+
"module_name": "NO-SSHWEAKMACS",
18+
"key": "mac@SSH",
19+
"value": "-HMAC-MD5* -UMAC-64* -UMAC-128*"
20+
},
21+
{
22+
"module_name": "NO-WEAKMAC",
23+
"key": "mac",
24+
"value": "-*-128*"
25+
},
26+
] %}}
27+
28+
description: |-
29+
Create a custom crypto policy module to enforce the use of strong ciphers and MACs in SSHD, disable CBC mode ciphers in SSHD and disable the use of weak MACs globally.
30+
{{% for sub_policy in sub_policies %}}
31+
{{{ describe_crypto_sub_policy(sub_policy.module_name, sub_policy.key, sub_policy.value) }}}
32+
{{% endfor %}}
33+
Then, set the system wide crypto policy to use the custom policy.
34+
<pre>
35+
$ sudo update-crypto-policies --set DEFAULT:NO-SHA1:NO-SSHCBC:NO-SSHWEAKCIPHERS:NO-SSHWEAKMACS:NO-WEAKMAC
36+
</pre>
37+
38+
rationale: |-
39+
CBC mode ciphers are vulnerable to certain attacks, such as the BEAST attack.
40+
Disabling CBC mode ciphers helps protect against these attacks and ensures that only
41+
strong, proven cryptographic algorithms are used to protect SSH communications.
42+
Weak ciphers that are used for authentication to the cryptographic module cannot be
43+
relied upon to provide confidentiality or integrity, and system data may be compromised.
44+
Message Authentication Codes (MACs) are cryptographic mechanisms used to verify the
45+
integrity and authenticity of data transmitted over SSH connections. Weak MACs that
46+
are used for authentication to the cryptographic module cannot be relied upon to
47+
provide integrity, and system data may be compromised. Implementing a custom crypto
48+
policy that disables weak MAC algorithms helps ensure that only strong, proven
49+
cryptographic algorithms are used to protect SSH communications.
50+
51+
severity: medium
52+
53+
identifiers:
54+
cce@rhel8: CCE-86707-7
55+
56+
ocil_clause: 'the custom crypto policy modules do not exist'
57+
58+
ocil: |-
59+
{{% for sub_policy in sub_policies %}}
60+
{{{ ocil_crypto_sub_policy(sub_policy.module_name, sub_policy.key, sub_policy.value) }}}
61+
{{% endfor %}}
62+
63+
template:
64+
name: crypto_sub_policies
65+
vars:
66+
base_policy: "DEFAULT:NO-SHA1"
67+
sub_policies: {{{ sub_policies }}}

products/rhel8/profiles/default.profile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,3 +726,4 @@ selections:
726726
- service_rlogin_disabled
727727
- service_zebra_disabled
728728
- package_rsh-server_removed
729+
- sshd_use_strong_macs

shared/macros/01-general.jinja

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,3 +1446,20 @@ Create a rule description for rules using the `audit_rules_kernel_module_loading
14461446
If the <tt>auditd</tt> daemon is configured to use the <tt>auditctl</tt> utility,
14471447
add the line to file <tt>/etc/audit/audit.rules</tt>.
14481448
{{% endmacro %}}
1449+
1450+
{{#
1451+
Create a description text for rules that use the crypto_sub_policies template.
1452+
1453+
:param module_name: crypto sub policy name, eg. `NO-SSHWEAKCIPHERS`
1454+
:type module_name: str
1455+
:param key: The entry key, eg. cipher@SSH
1456+
:type key: str
1457+
:param value: The entry value, eg. -3DES-CBC -AES-128-CBC -AES-192-CBC -AES-256-CBC -CHACHA20-POLY1305
1458+
:type value: str
1459+
#}}
1460+
{{% macro describe_crypto_sub_policy(module_name, key, value) %}}
1461+
Add the following line to the file <tt>/etc/crypto-policies/policies/modules/{{{ module_name }}}.pmod</tt>:
1462+
<pre>
1463+
{{{ key }}} = {{{ value }}}
1464+
</pre>
1465+
{{%- endmacro %}}

shared/macros/10-ocil.jinja

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,3 +1538,20 @@ Create an OCIL text for rules that use the audit_rules_watch platform.
15381538
-w {{{ path }}} -p wa -k {{{ key }}}
15391539
{{% endif %}}
15401540
{{% endmacro %}}
1541+
1542+
{{#
1543+
Create an OCIL text for rules that use the crypto_sub_policies template.
1544+
1545+
:param module_name: crypto sub policy name, eg. `NO-SSHWEAKCIPHERS`
1546+
:type module_name: str
1547+
:param key: The entry key, eg. cipher@SSH
1548+
:type key: str
1549+
:param value: The entry value, eg. -3DES-CBC -AES-128-CBC -AES-192-CBC -AES-256-CBC -CHACHA20-POLY1305
1550+
:type value: str
1551+
#}}
1552+
{{% macro ocil_crypto_sub_policy(module_name, key, value) %}}
1553+
Verify that <tt>/etc/crypto-policies/policies/modules/{{{ module_name }}}.pmod</tt> exists and has the following content:
1554+
<pre>
1555+
{{{ key }}} = {{{ value }}}
1556+
</pre>
1557+
{{% endmacro %}}

shared/references/cce-redhat-avail.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ CCE-86702-8
7272
CCE-86703-6
7373
CCE-86704-4
7474
CCE-86706-9
75-
CCE-86707-7
7675
CCE-86708-5
7776
CCE-86709-3
7877
CCE-86710-1
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# platform = multi_platform_all
2+
# reboot = true
3+
# strategy = configure
4+
# complexity = low
5+
# disruption = low
6+
7+
{{% for sub_policy in SUB_POLICIES %}}
8+
- name: "{{{ rule_title }}} - Create custom crypto policy module {{{ sub_policy.module_name }}}"
9+
ansible.builtin.lineinfile:
10+
path: /etc/crypto-policies/policies/modules/{{{ sub_policy.module_name }}}.pmod
11+
owner: root
12+
group: root
13+
mode: '0644'
14+
line: {{{ sub_policy.key }}} = {{{ sub_policy.value }}}
15+
create: true
16+
regexp: "{{{ sub_policy.key }}}"
17+
{{% endfor %}}
18+
19+
- name: "{{{ rule_title }}} - Check current crypto policy"
20+
ansible.builtin.command: update-crypto-policies --show
21+
register: current_crypto_policy
22+
changed_when: false
23+
failed_when: false
24+
check_mode: false
25+
26+
- name: "{{{ rule_title }}} - Update crypto-policies"
27+
ansible.builtin.command: update-crypto-policies --set {{{ BASE_POLICY }}}:{{{ CONFIGURE_CRYPTO_POLICY_MODULES }}}
28+
when: current_crypto_policy.stdout.strip() != "{{{ BASE_POLICY }}}:{{{ CONFIGURE_CRYPTO_POLICY_MODULES }}}"

0 commit comments

Comments
 (0)