Skip to content

Commit 63fe653

Browse files
authored
Merge pull request #14454 from jan-cerny/fix_configure_custom_crypto_policy_cis
Set rpm crypto only if rpm scope exists
2 parents 0ef5e55 + 67891ca commit 63fe653

5 files changed

Lines changed: 59 additions & 11 deletions

File tree

linux_os/guide/system/software/integrity/crypto/configure_custom_crypto_policy_cis/rule.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ title: Implement Custom Crypto Policy Modules for CIS Benchmark
5252
{
5353
"module_name": "NO-RPMSHA1",
5454
"key": "hash@rpm",
55-
"value": "-SHA1"
55+
"value": "-SHA1",
56+
"scope": "rpm-sequoia"
5657
},
5758
] %}}
5859
{{% elif product == "rhel10" or product == "fedora" %}}

shared/templates/crypto_sub_policies/ansible.template

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@
44
# complexity = low
55
# disruption = low
66

7+
- name: "{{{ rule_title }}} - Set the base crypto policy"
8+
ansible.builtin.set_fact:
9+
expected_crypto_policy: "{{{ BASE_POLICY }}}"
10+
711
{{% for sub_policy in SUB_POLICIES %}}
12+
{{% if "scope" in sub_policy %}}
13+
- name: "{{{ rule_title }}} - Check That /etc/crypto-policies/back-ends/{{{ sub_policy.scope }}}.config Exists"
14+
ansible.builtin.stat:
15+
path: /etc/crypto-policies/back-ends/{{{ sub_policy.scope }}}.config
16+
register: crypto_{{{ sub_policy.scope | replace("-", "_") }}}_scope
17+
{{% endif %}}
18+
819
- name: "{{{ rule_title }}} - Create custom crypto policy module {{{ sub_policy.module_name }}}"
920
ansible.builtin.lineinfile:
1021
path: /etc/crypto-policies/policies/modules/{{{ sub_policy.module_name }}}.pmod
@@ -14,6 +25,16 @@
1425
line: {{{ sub_policy.key }}} = {{{ sub_policy.value }}}
1526
create: true
1627
regexp: "{{{ sub_policy.key }}}"
28+
{{% if "scope" in sub_policy %}}
29+
when: crypto_{{{ sub_policy.scope | replace("-", "_") }}}_scope.stat.exists
30+
{{% endif %}}
31+
32+
- name: "{{{ rule_title }}} - Update the expected policy"
33+
ansible.builtin.set_fact:
34+
expected_crypto_policy: "{{ expected_crypto_policy + ':{{{ sub_policy.module_name }}}' }}"
35+
{{% if "scope" in sub_policy %}}
36+
when: crypto_{{{ sub_policy.scope | replace("-", "_") }}}_scope.stat.exists
37+
{{% endif %}}
1738
{{% endfor %}}
1839

1940
- name: "{{{ rule_title }}} - Check current crypto policy"
@@ -24,5 +45,5 @@
2445
check_mode: false
2546

2647
- 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 }}}"
48+
ansible.builtin.command: update-crypto-policies --set {{ expected_crypto_policy }}
49+
when: current_crypto_policy.stdout.strip() != expected_crypto_policy

shared/templates/crypto_sub_policies/bash.template

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,22 @@
44
# complexity = low
55
# disruption = low
66

7-
{{% for sub_policy in SUB_POLICIES %}}
8-
{{{ bash_file_contents("/etc/crypto-policies/policies/modules/" ~ sub_policy.module_name ~ ".pmod", sub_policy.key ~ " = " ~ sub_policy.value) }}}
9-
{{% endfor %}}
7+
expected_crypto_policy="{{{ BASE_POLICY }}}"
8+
9+
{{% for sub_policy in SUB_POLICIES -%}}
10+
{{% if "scope" in sub_policy %}}
11+
# this module is applicable only if {{{ sub_policy.scope }}} scope is available in crypto-policies
12+
if [[ -f /etc/crypto-policies/back-ends/{{{ sub_policy.scope }}}.config ]] ; then
13+
{{%- endif %}}
14+
expected_crypto_policy="${expected_crypto_policy}:{{{ sub_policy.module_name }}}"
15+
{{{ bash_file_contents("/etc/crypto-policies/policies/modules/" ~ sub_policy.module_name ~ ".pmod", sub_policy.key ~ " = " ~ sub_policy.value) | trim }}}
16+
{{% if "scope" in sub_policy -%}}
17+
fi
18+
{{% endif %}}
19+
{{%- endfor %}}
1020

1121
current_crypto_policy=$(update-crypto-policies --show)
12-
expected_crypto_policy="{{{ BASE_POLICY }}}:{{{ CONFIGURE_CRYPTO_POLICY_MODULES }}}"
22+
1323
if [[ "$current_crypto_policy" != "$expected_crypto_policy" ]] ; then
1424
update-crypto-policies --set "$expected_crypto_policy"
1525
fi

shared/templates/crypto_sub_policies/oval.template

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@
33
{{{ oval_metadata("Ensure that the custom crypto policy module is configured", rule_title=rule_title) }}}
44
<criteria operator="AND" comment="Ensure that all of the correct lines are in the file.">
55
{{% for sub_policy in SUB_POLICIES %}}
6-
<criterion comment="Check that {{{ sub_policy.key }}} is configured in {{{ sub_policy.module_name }}}.pmod"
6+
{{% if "scope" in sub_policy %}}
7+
<criteria operator="OR" comment="If {{{ sub_policy.scope }}} scope is available then {{{ sub_policy.key }}} must be configured in {{{ sub_policy.module_name }}}.pmod">
8+
<criterion comment="Check that {{{ sub_policy.scope }}} scope is not available" negate="true" test_ref="test_{{{ rule_id }}}_{{{ sub_policy.scope }}}" />
9+
<criteria operator="AND" comment="Check that {{{ sub_policy.scope }}} scope is available AND {{{ sub_policy.key }}} is configured in {{{ sub_policy.module_name }}}.pmod">
10+
<criterion comment="Check that {{{ sub_policy.scope }}} scope is available" test_ref="test_{{{ rule_id }}}_{{{ sub_policy.scope }}}" />
11+
<criterion comment="Check that {{{ sub_policy.key }}} is configured in {{{ sub_policy.module_name }}}.pmod" test_ref="test_{{{ rule_id }}}_{{{ sub_policy.module_name }}}"/>
12+
</criteria>
13+
</criteria>
14+
{{% else %}}
15+
<criterion comment="Check that {{{ sub_policy.key }}} is configured in {{{ sub_policy.module_name }}}.pmod"
716
test_ref="test_{{{ rule_id }}}_{{{ sub_policy.module_name }}}"/>
17+
{{% endif %}}
818
{{% endfor %}}
919
</criteria>
1020
</definition>
@@ -21,5 +31,14 @@
2131
<ind:pattern operation="pattern match">^{{{ sub_policy.key }}} = {{{ sub_policy.value | escape_regex }}}$</ind:pattern>
2232
<ind:instance datatype="int">1</ind:instance>
2333
</ind:textfilecontent54_object>
34+
{{% if "scope" in sub_policy %}}
35+
<unix:file_test comment="Check that {{{ sub_policy.scope }}} scope is available" id="test_{{{ rule_id }}}_{{{ sub_policy.scope }}}" check="all" check_existence="all_exist" version="1">
36+
<unix:object object_ref="object_{{{ rule_id }}}_{{{ sub_policy.scope }}}" />
37+
</unix:file_test>
38+
39+
<unix:file_object comment="/etc/crypto-policies/back-ends/{{{ sub_policy.scope }}}.config" id="object_{{{ rule_id }}}_{{{ sub_policy.scope }}}" version="1">
40+
<unix:filepath>/etc/crypto-policies/back-ends/{{{ sub_policy.scope }}}.config</unix:filepath>
41+
</unix:file_object>
42+
{{% endif %}}
2443
{{% endfor %}}
2544
</def-group>

shared/templates/crypto_sub_policies/template.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)