Skip to content

Commit c20b290

Browse files
authored
Merge pull request #13168 from jan-cerny/package_bind_removed
Update rule package_bind_removed for RHEL 9.6
2 parents e2a95f4 + 39b0611 commit c20b290

15 files changed

+74
-28
lines changed

docs/templates/template_reference.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,12 @@ The only way to remediate is to recompile and reinstall the kernel, so no remedi
579579
- Languages: Anaconda, Ansible, Bash, OVAL, Puppet, Blueprint, Kickstart, Bootc
580580

581581
#### package_removed
582-
- Checks if the given package is not installed.
582+
- Checks if the given package(s) are not installed.
583583

584584
- Parameters:
585585

586-
- **pkgname** - name of the RPM or DEB package, eg. `tmux`
586+
- **pkgname** - name of the RPM or DEB package, eg. `tmux`.
587+
Can be either a name of a single package or a list of names.
587588

588589
- Languages: Anaconda, Ansible, Bash, OVAL, Puppet, Kickstart, Bootc
589590

linux_os/guide/services/dns/disabling_dns_server/package_bind_removed/rule.yml

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ title: 'Uninstall bind Package'
55
description: |-
66
The <tt>named</tt> service is provided by the <tt>bind</tt> package.
77
{{{ describe_package_remove(package="bind") }}}
8+
{{% if product == "rhel9" %}}
9+
On Red Hat Enterprise Linux 9.6 and newer, the <tt>bind</tt> command is also provided by the <tt>bind9.18</tt> package.
10+
{{{ describe_package_remove(package="bind9.18") }}}
11+
{{% endif %}}
812
913
rationale: |-
1014
If there is no need to make DNS server software available,
@@ -41,6 +45,9 @@ template:
4145
name: package_removed
4246
vars:
4347
pkgname: bind
48+
pkgname@rhel9:
49+
- bind
50+
- bind9.18
4451
pkgname@ubuntu1604: bind9
4552
pkgname@ubuntu1804: bind9
4653
pkgname@ubuntu2004: bind9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
# platform = Red Hat Enterprise Linux 9
3+
4+
dnf install -y bind9.18 || dnf install -y bind
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
# platform = Red Hat Enterprise Linux 8, Red Hat Enterprise Linux 10, multi_platform_fedora, multi_platform_debian, multi_platform_ol, multi_platform_sle
3+
4+
{{{ bash_package_install("bind") }}}
5+
{{{ bash_package_remove("bind") }}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
# platform = Red Hat Enterprise Linux 8, Red Hat Enterprise Linux 10, multi_platform_fedora, multi_platform_debian, multi_platform_ol, multi_platform_sle
3+
4+
{{{ bash_package_install("bind") }}}

shared/templates/package_removed/anaconda.template

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
# complexity = low
55
# disruption = low
66

7-
package --remove={{{ PKGNAME }}}
7+
{{% for package in PACKAGES %}}
8+
package --remove={{{ package }}}
9+
{{% endfor %}}

shared/templates/package_removed/ansible.template

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
# strategy = disable
44
# complexity = low
55
# disruption = low
6-
- name: Ensure {{{ PKGNAME }}} is removed
7-
package:
8-
name: "{{{ PKGNAME }}}"
9-
state: absent
106

7+
{{% for package in PACKAGES %}}
8+
- name: "{{{ rule_title }}}: Ensure {{{ package }}} is removed"
9+
ansible.builtin.package:
10+
name: "{{{ package }}}"
11+
state: absent
12+
{{% endfor %}}

shared/templates/package_removed/bash.template

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
# complexity = low
55
# disruption = low
66

7-
# CAUTION: This remediation script will remove {{{ PKGNAME }}}
8-
# from the system, and may remove any packages
9-
# that depend on {{{ PKGNAME }}}. Execute this
10-
# remediation AFTER testing on a non-production
11-
# system!
7+
# CAUTION: This remediation script will remove {{{ PACKAGES | join(" and ") }}}
8+
# from the system, and may remove any packages
9+
# that depend on {{{ PACKAGES | join(" and ") }}}. Execute this
10+
# remediation AFTER testing on a non-production
11+
# system!
1212

13-
{{{ bash_package_remove(package=PKGNAME) }}}
13+
{{% for package in PACKAGES %}}
14+
{{{ bash_package_remove(package=package) }}}
15+
{{% endfor %}}

shared/templates/package_removed/bootc.template

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
# complexity = low
55
# disruption = low
66

7-
dnf remove {{{ PKGNAME }}}
7+
{{% for package in PACKAGES %}}
8+
dnf remove {{{ package }}}
9+
{{% endfor %}}

shared/templates/package_removed/kickstart.template

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
# complexity = low
55
# disruption = low
66

7-
package remove {{{ PKGNAME }}}
7+
{{% for package in PACKAGES %}}
8+
package remove {{{ package }}}
9+
{{% endfor %}}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<def-group>
2-
<definition class="compliance" id="{{{ _RULE_ID }}}"
3-
version="1">
4-
{{{ oval_metadata("The " + pkg_system|upper + " package " + PKGNAME + " should be removed.", affected_platforms=["multi_platform_all"]) }}}
5-
<criteria>
6-
<criterion comment="package {{{ PKGNAME }}} is removed"
7-
test_ref="test_package_{{{ PKGNAME }}}_removed" />
8-
</criteria>
9-
</definition>
10-
{{{ oval_test_package_removed(package=PKGNAME, test_id="test_package_"+PKGNAME+"_removed") }}}
2+
<definition class="compliance" id="{{{ _RULE_ID }}}" version="1">
3+
{{{ oval_metadata("The " + pkg_system|upper + " package " + PACKAGES | join(" and ") + " should be removed.", affected_platforms=["multi_platform_all"]) }}}
4+
<criteria>
5+
{{% for package in PACKAGES %}}
6+
<criterion comment="package {{{ package }}} is removed" test_ref="test_package_{{{ package }}}_removed" />
7+
{{% endfor %}}
8+
</criteria>
9+
</definition>
10+
{{% for package in PACKAGES %}}
11+
{{{ oval_test_package_removed(package=package, test_id="test_package_"+package+"_removed") }}}
12+
{{% endfor %}}
13+
1114
</def-group>

shared/templates/package_removed/puppet.template

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
# strategy = disable
44
# complexity = low
55
# disruption = low
6-
include remove_{{{ PKGNAME }}}
6+
{{% for package in PACKAGES %}}
7+
include remove_{{{ package }}}
78

8-
class remove_{{{ PKGNAME }}} {
9-
package { '{{{ PKGNAME }}}':
9+
class remove_{{{ package }}} {
10+
package { '{{{ package }}}':
1011
ensure => 'purged',
1112
}
1213
}
14+
{{% endfor %}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def preprocess(data, lang):
2+
if isinstance(data["pkgname"], list):
3+
data["packages"] = data["pkgname"]
4+
else:
5+
data["packages"] = [data["pkgname"]]
6+
return data
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#!/bin/bash
22

3-
{{{ bash_package_remove(PKGNAME) }}}
3+
{{% for package in PACKAGES %}}
4+
{{{ bash_package_remove(package) }}}
5+
{{% endfor %}}

tests/test_components.py

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def test_template_package(
4040
template_vars = template["vars"]
4141
if template_name in ["package_installed", "package_removed"]:
4242
package = template_vars["pkgname"]
43+
if isinstance(package, list):
44+
package = package[0]
4345
component = package_to_component.get(package, [package])[0]
4446
reason = (
4547
"rule uses template '%s' with 'pkgname' parameter set to '%s' "

0 commit comments

Comments
 (0)