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

feature: skip_test_env #10387

Closed
wants to merge 10 commits into from
2 changes: 2 additions & 0 deletions linux_os/guide/services/base/service_psacct_enabled/rule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ template:
name: service_enabled
vars:
servicename: psacct
# needs CAP_SYS_PACCT, as podman is run using normal user, there seems to be no way to elevate
skip_test_env: podman-based
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ template:
name: service_enabled
vars:
servicename: fapolicyd
# needs CAP_DAC_OVERRIDE,CAP_SETGID,CAP_SETUID,CAP_SYS_PTRACE,CAP_SYS_ADMIN,CAP_SYS_NICE,CAP_SYS_RESOURCE,CAP_AUDIT_WRITE, as podman is run using normal user, there seems to be no way to elevate
skip_test_env: podman-based
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# packages = policycoreutils-python-utils
# platform = multi_platform_all
# selinux / restorecon does not work under podman
# skip_test_env = podman-based

truncate -s 0 /etc/security/faillock.conf
echo "dir=/var/log/faillock" > /etc/security/faillock.conf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# packages = policycoreutils-python-utils
# platform = multi_platform_all
# selinux / restorecon does not work under podman
# skip_test_env = podman-based

truncate -s 0 /etc/security/faillock.conf
echo "dir=/var/log/faillock" > /etc/security/faillock.conf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# packages = policycoreutils-python-utils
# platform = multi_platform_all
# selinux / restorecon does not work under podman
# skip_test_env = podman-based

truncate -s 0 /etc/security/faillock.conf
echo "dir=/var/log/faillock" > /etc/security/faillock.conf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# packages = policycoreutils-python-utils
# platform = multi_platform_all
# selinux / restorecon does not work under podman
# skip_test_env = podman-based

truncate -s 0 /etc/security/faillock.conf
echo "dir=/var/log/faillock" > /etc/security/faillock.conf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# packages = policycoreutils-python-utils
# platform = multi_platform_all
# selinux / restorecon does not work under podman
# skip_test_env = podman-based

truncate -s 0 /etc/security/faillock.conf
echo "dir=/var/log/faillock" > /etc/security/faillock.conf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ template:
packagename@ubuntu1804: auditd
packagename@ubuntu2004: auditd
packagename@ubuntu2204: auditd
# Testing needs CAP_AUDIT_* and those are not available under podman
skip_test_env: podman-based
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash
# packages = nfs-utils
# This test fails under podman as there seems to be problems setupping nfs
# server, nfsd kernel module might not be loaded and so on
# skip_test_env = podman-based

mkdir -p /tmp/testdir/testdir2
mkdir /tmp/testmount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ template:
sysctlvar: kernel.perf_event_paranoid
sysctlval: '2'
datatype: int
skip_test_env: podman-based
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
# selinux / restorecon does not work under podman
# skip_test_env = podman-based

touch /dev/foo
restorecon -F /dev/foo
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
# selinux / restorecon does not work under podman
# skip_test_env = podman-based

ln -s /dev/cpu /dev/foo
restorecon -F /dev/foo
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# platform = Not Applicable
{{% endif%}}
# packages = {{{ PACKAGENAME }}}
# skip_test_env = {{{ SKIP_TEST_ENV }}}

SYSTEMCTL_EXEC='/usr/bin/systemctl'
"$SYSTEMCTL_EXEC" stop '{{{ DAEMONNAME }}}.service'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# platform = Not Applicable
{{% endif%}}
# packages = {{{ PACKAGENAME }}}
# skip_test_env = {{{ SKIP_TEST_ENV }}}

SYSTEMCTL_EXEC='/usr/bin/systemctl'
"$SYSTEMCTL_EXEC" unmask '{{{ DAEMONNAME }}}.service'
Expand Down
1 change: 1 addition & 0 deletions shared/templates/sysctl/tests/comment.fail.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
1 change: 1 addition & 0 deletions shared/templates/sysctl/tests/correct_value.pass.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
1 change: 1 addition & 0 deletions shared/templates/sysctl/tests/line_not_there.fail.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
1 change: 1 addition & 0 deletions shared/templates/sysctl/tests/symlink_conflicting.fail.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
1 change: 1 addition & 0 deletions shared/templates/sysctl/tests/symlink_same_option.pass.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
1 change: 1 addition & 0 deletions shared/templates/sysctl/tests/two_sysctls_on_d.pass.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
1 change: 1 addition & 0 deletions shared/templates/sysctl/tests/wrong_runtime.fail.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
1 change: 1 addition & 0 deletions shared/templates/sysctl/tests/wrong_value.fail.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# skip_test_env = {{{ SKIP_TEST_ENV }}}
{{% if SYSCTLVAL == "" %}}
# variables = sysctl_{{{ SYSCTLID }}}_value={{{ SYSCTL_CORRECT_VALUE }}}
{{% endif %}}
Expand Down
9 changes: 9 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ The header consists of comments (starting by `#`). Possible keys are:
remediation breaks test environment (for example unmounting /tmp in a test
scenario would break test runs, because OpenSCAP generates reports into the
/tmp directory).
- `skip_test_env` is a string specifying comma separated list of `test_env`
names where the running a test is skipped. Possible values are:
`libvirt-based`, `docker-based`, `podman-based`. Main usage is a test case
where feature-under-test uses something where there is some kind of (security)
limitation in place in testing environment. And the limitation is impossible
or not a good idea to remove. Especially you should not give unlimited
permissions to containerized testing environments, environments are not
superprivileged containers. For example currently containers do not have
SELinux, so any test trying to `restorecon` is going to fail.
- `templates` has no effect at the moment.
- `variables` is a comma-separated list of XCCDF values that sets a different
default value for XCCDF variables in a form `<variable name>=<value>`.
Expand Down
6 changes: 6 additions & 0 deletions tests/ssg_test_suite/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ def _change_variable_value(self, varname, value):
os.unlink(xslt_filename)

def _check_rule_scenario(self, scenario, remote_rule_dir, rule_id, remediation_available):
if self.test_env.name in scenario.script_params["skip_test_env"]:
logging.warning('Script {0} is not applicable on given test_env {1}'
.format(scenario.script, self.test_env.name))
return

if not _apply_script(
remote_rule_dir, self.test_env, scenario.script):
logging.error("Environment failed to prepare, skipping test")
Expand Down Expand Up @@ -584,6 +589,7 @@ def _parse_parameters(self):
'platform': ['multi_platform_all'],
'remediation': ['all'],
'variables': [],
'skip_test_env': [],
}

for parameter in params:
Expand Down