Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic detection of platform_package_overrides when using automatus #9897

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#!/bin/bash
# platform = multi_platform_ubuntu,multi_platform_rhel
{{% if "ubuntu" in product %}}
# packages = libpam-pkcs11
{{% elif "rhel7" == product %}}
# packages = pam_pkcs11
{{% else %}}
# packages = openssl-pkcs11
{{% endif %}}

if [ ! -f /etc/pam_pkcs11/pam_pkcs11.conf ]; then
cp /usr/share/doc/libpam-pkcs11/examples/pam_pkcs11.conf.example /etc/pam_pkcs11/pam_pkcs11.conf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#!/bin/bash
# platform = multi_platform_ol,multi_platform_rhel,multi_platform_ubuntu
{{% if "ubuntu" in product %}}
# packages = libpam-pkcs11
{{% elif product in ["ol7", "rhel7"] %}}
# packages = pam_pkcs11
{{% else %}}
# packages = openssl-pkcs11
{{% endif %}}

if [ ! -f /etc/pam_pkcs11/pam_pkcs11.conf ]; then
cp /usr/share/doc/libpam-pkcs11/examples/pam_pkcs11.conf.example /etc/pam_pkcs11/pam_pkcs11.conf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#!/bin/bash
# platform = multi_platform_ol,multi_platform_rhel,multi_platform_ubuntu
{{% if "ubuntu" in product %}}
# packages = libpam-pkcs11
{{% elif product in ["ol7", "rhel7"] %}}
# packages = pam_pkcs11
{{% else %}}
# packages = openssl-pkcs11
{{% endif %}}

if [ ! -f /etc/pam_pkcs11/pam_pkcs11.conf ]; then
cp /usr/share/doc/libpam-pkcs11/examples/pam_pkcs11.conf.example /etc/pam_pkcs11/pam_pkcs11.conf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

rm -f /etc/audit/rules.d/*
> /etc/audit/audit.rules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

rm -f /etc/audit/rules.d/*
> /etc/audit/audit.rules
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

rm -f /etc/audit/rules.d/*
> /etc/audit/audit.rules\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

rm -f /etc/audit/rules.d/*
> /etc/audit/audit.rules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

{{% if product in ["ol7", "ol8"] or 'rhel' in product %}}
echo "-a always,exit -F arch=b32 -S finit_module -F auid>=1000 -F auid!=unset -k modules" >> /etc/audit/rules.d/modules.rules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/bash
# remediation = bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

rm -f /etc/audit/rules.d/*
> /etc/audit/audit.rules
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

{{% if product in ["ol7", "ol8"] or 'rhel' in product %}}
echo "-a always,exit -F arch=b32 -S init_module -F auid>=1000 -F auid!=unset -k modules" >> /etc/audit/rules.d/modules.rules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/bash
# remediation = bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

rm -f /etc/audit/rules.d/*
> /etc/audit/audit.rules
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product %}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

source common.sh

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product %}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

source common.sh

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product %}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}
# platform = multi_platform_rhel

if grep -iwq "log_file" /etc/audit/auditd.conf; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product %}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

source common.sh

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product %}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

source common.sh

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product %}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}
# platform = multi_platform_rhel

if grep -iwq "log_file" /etc/audit/auditd.conf; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

source common.sh

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}
# variables = var_auditd_disk_full_action=action1|action2|action3

source common.sh
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}
# variables = var_auditd_disk_full_action=action1

source common.sh
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}
# variables = var_auditd_disk_full_action=action1|action2|action3

source common.sh
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}
# variables = var_auditd_disk_full_action=halt

source common.sh
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

source common.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash
{{% if "ubuntu" in product%}}
# packages = auditd
{{% else %}}
# packages = audit
{{% endif %}}

source common.sh

Expand Down
1 change: 1 addition & 0 deletions products/ol7/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cpes:
# Mapping of CPE platform to package
platform_package_overrides:
login_defs: "shadow-utils"
openssl-pkcs11: "pam_pkcs11"

reference_uris:
cis: 'https://www.cisecurity.org/benchmark/oracle_linux/'
1 change: 1 addition & 0 deletions products/rhel7/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ cpes:
# Mapping of CPE platform to package
platform_package_overrides:
login_defs: "shadow-utils"
openssl-pkcs11: "pam_pkcs11"

centos_pkg_release: "53a7ff4b"
centos_pkg_version: "f4a80eb5"
Expand Down
2 changes: 2 additions & 0 deletions products/ubuntu1604/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ cpes:
check_id: installed_OS_is_ubuntu1604

platform_package_overrides:
audit: auditd
gdm: gdm3
grub2: grub2-common
net-snmp: snmp
nss-pam-ldapd: libpam-ldap
pam: libpam-runtime
shadow: login
sssd: sssd-common
openssl-pkcs11: libpam-pkcs11

reference_uris:
cis: 'https://www.cisecurity.org/benchmark/ubuntu_linux/'
2 changes: 2 additions & 0 deletions products/ubuntu1804/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ cpes:
check_id: installed_OS_is_ubuntu1804

platform_package_overrides:
audit: auditd
gdm: gdm3
grub2: grub2-common
net-snmp: snmp
nss-pam-ldapd: libpam-ldap
pam: libpam-runtime
shadow: login
sssd: sssd-common
openssl-pkcs11: libpam-pkcs11

reference_uris:
cis: 'https://www.cisecurity.org/benchmark/ubuntu_linux/'
1 change: 1 addition & 0 deletions products/ubuntu2004/product.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ platform_package_overrides:
pam: libpam-runtime
shadow: login
sssd: sssd-common
openssl-pkcs11: libpam-pkcs11

reference_uris:
cis: 'https://www.cisecurity.org/benchmark/ubuntu_linux/'
6 changes: 5 additions & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ test runs. After the header, arbitrary Bash commands can follow.

The header consists of comments (starting by `#`). Possible keys are:

- `packages` is a comma-separated list of packages to install.
- `packages` is a comma-separated list of packages to install. Note that each
package can be overridden by its platform-specific alternative if listed
under `platform_package_overrides` in the product YAML. You should use
the most common package names in this field and provide an alternative
for any platform-specific names in the `platform_package_overrides` field.
- `platform` is a comma-separated list of platforms where the test scenario can
be run. This is similar to `platform` used in our remediations. Examples of
values: `multi_platform_rhel`, `Red Hat Enterprise Linux 7`,
Expand Down
18 changes: 17 additions & 1 deletion tests/ssg_test_suite/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,31 @@ def _rule_matches_rule_spec(self, rule_short_id):
def _rule_matches_template_spec(self, template):
return True

def _replace_platform_specific_packages(self, packages):
""" Returns the provided package list with names
updated according to the platform alternatives
listed in platform_package_overrides product field """
product_yaml = common.get_product_context(self.test_env.product)
platform_package_overrides = product_yaml["platform_package_overrides"]
packages_with_alternatives = set()
for package in packages:
if package in platform_package_overrides and platform_package_overrides[package]:
packages_with_alternatives.add(platform_package_overrides[package])
else:
packages_with_alternatives.add(package)
return packages_with_alternatives

def _ensure_package_present_for_all_scenarios(
self, test_content_by_rule_id):
packages_required = set()

for rule_test_content in test_content_by_rule_id.values():
for s in rule_test_content.scenarios:
scenario_packages = s.script_params["packages"]
packages_required.update(scenario_packages)
if packages_required:
common.install_packages(self.test_env, packages_required)
packages_to_install = self._replace_platform_specific_packages(packages_required)
common.install_packages(self.test_env, packages_to_install)

def _prepare_environment(self, test_content_by_rule_id):
try:
Expand Down