-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt sysctl template for bootable containers
Add an SCE check to the sysctl template special for bootable containers. We don't want to use OVAL check in this template because the OVAL check checks runtime status using OpenSCAP sysctl probe. The probe doesn't return meaningful results during podman build process and also it doesn't make sense to check runtime during the build. We need to check only the static configuration. Moreover, we update the Bash remediation to not set the runtime status during podman build process.
- Loading branch information
Showing
4 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env bash | ||
# check-import = stdout | ||
{{% if SYSCTLVAL == "" %}} | ||
# check-export = sysctl_{{{ SYSCTLID }}}_value=sysctl_{{{ SYSCTLID }}}_value | ||
{{% endif %}} | ||
|
||
{{% if product not in [ "ol7", "ol8", "ol9", "rhcos4", "rhel8", "rhel9", "rhel10", "ubuntu2004", "ubuntu2204"] %}} | ||
FILES_NOT_MANAGED_BY_PACKAGES=("/etc/sysctl.conf" "/etc/sysctl.d/*.conf" "/lib/sysctl.d/*.conf" "/usr/local/lib/sysctl.d/*.conf" "/run/sysctl.d/*.conf") | ||
{{% else %}} | ||
FILES_NOT_MANAGED_BY_PACKAGES=("/etc/sysctl.conf" "/etc/sysctl.d/*.conf" "/usr/local/lib/sysctl.d/*.conf" "/run/sysctl.d/*.conf") | ||
{{% endif %}} | ||
FILES_MANAGED_BY_PACKAGES=("/usr/lib/sysctl.d/*.conf") | ||
|
||
regex="^\s*{{{ SYSCTLVAR }}}\s*=\s*(.*)\s*" | ||
{{% if SYSCTLVAL == "" %}} | ||
expected_value="$XCCDF_VALUE_sysctl_{{{ SYSCTLID }}}_value" | ||
{{% else %}} | ||
expected_value="{{{ SYSCTLVAL }}}" | ||
{{%- endif %}} | ||
|
||
# kernel static parameter {{{ SYSCTLVAR }}} set to {{{ COMMENT_VALUE }}} in sysctl files not managed by packages | ||
found=0 | ||
for files in ${FILES_NOT_MANAGED_BY_PACKAGES[@]} ; do | ||
[[ -e "$files" ]] || continue | ||
found_value=$(grep -P "$regex" $files | sed -E "s/$regex/\1/") | ||
if [[ -n "$found_value" ]] ; then | ||
if [[ "$found_value" == "$expected_value" ]] ; then | ||
found=1 | ||
else | ||
exit $XCCDF_RESULT_FAIL | ||
fi | ||
fi | ||
done | ||
if [[ $found != 0 ]] ; then | ||
exit $XCCDF_RESULT_PASS | ||
fi | ||
|
||
|
||
# kernel static parameter {{{ SYSCTLVAR }}} missing in sysctl files not managed by packages | ||
for files in ${FILES_NOT_MANAGED_BY_PACKAGES[@]} ; do | ||
[[ -e "$files" ]] || continue | ||
if grep -P "$regex" $files ; then | ||
exit $XCCDF_RESULT_FAIL | ||
fi | ||
done | ||
|
||
# kernel static parameter {{{ SYSCTLVAR }}} set to {{{ COMMENT_VALUE }}} in sysctl files managed by packages | ||
found=0 | ||
for files in ${FILES_MANAGED_BY_PACKAGES[@]} ; do | ||
[[ -e "$files" ]] || continue | ||
if [[ -n "$found_value" ]] ; then | ||
if [[ "$found_value" == "$expected_value" ]] ; then | ||
found=1 | ||
else | ||
exit $XCCDF_RESULT_FAIL | ||
fi | ||
fi | ||
done | ||
if [[ $found != 0 ]] ; then | ||
exit $XCCDF_RESULT_PASS | ||
fi | ||
|
||
exit $XCCDF_RESULT_FAIL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ supported_languages: | |
- ansible | ||
- bash | ||
- oval | ||
- sce-bash |