-
Notifications
You must be signed in to change notification settings - Fork 706
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
enhance the grub2_argument template to cover more use cases #12375
Merged
jan-cerny
merged 7 commits into
ComplianceAsCode:master
from
vojtapolasek:fix_grub2_argument_locations
Sep 23, 2024
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
70e1a50
merge JInja booleans for checking of referenced options in /boot/load…
vojtapolasek b4736f5
modify the oval of grub2_argument template so that it is aligned with…
vojtapolasek 19c63ae
add test scenarios testing newly introduced OVAL tests
vojtapolasek f6e1fa3
revise other test scenarios of grub2_argument template
vojtapolasek 1d6427f
rename or remove test scenarios of grub2_audit_argument rule
vojtapolasek 09b5b00
rewrite the common.sh helper script
vojtapolasek c3b668f
modify test scenarios to use the new common.sh script efficiently
vojtapolasek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
11 changes: 0 additions & 11 deletions
11
linux_os/guide/auditing/grub2_audit_argument/tests/blank_grubenv_rhel8.fail.sh
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
linux_os/guide/auditing/grub2_audit_argument/tests/correct_recovery_disabled.pass.sh
This file was deleted.
Oops, something went wrong.
File renamed without changes.
11 changes: 0 additions & 11 deletions
11
linux_os/guide/auditing/grub2_audit_argument/tests/wrong_value_etcdefaultgrub.fail.sh
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
.../auditing/grub2_audit_argument/tests/wrong_value_etcdefaultgrub_recovery_disabled.fail.sh
This file was deleted.
Oops, something went wrong.
File renamed without changes.
12 changes: 0 additions & 12 deletions
12
linux_os/guide/auditing/grub2_audit_argument/tests/wrong_value_rhel8.fail.sh
This file was deleted.
Oops, something went wrong.
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
14 changes: 14 additions & 0 deletions
14
shared/templates/grub2_bootloader_argument/tests/arg_not_in_entries.fail.sh
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,14 @@ | ||
#!/bin/bash | ||
|
||
# platform = multi_platform_fedora,multi_platform_rhel | ||
# packages = grub2,grubby | ||
|
||
source common.sh | ||
|
||
# Removes argument from kernel command line in /boot/loader/entries/*.conf | ||
|
||
for file in /boot/loader/entries/*.conf ; do | ||
if grep -q '^.*{{{ ESCAPED_ARG_NAME }}}=.*' "$file" ; then | ||
sed -i 's/\(^.*\){{{ARG_NAME}}}=[^[:space:]]*\(.*\)/\1 \2/' "$file" | ||
fi | ||
done |
7 changes: 1 addition & 6 deletions
7
...ests/arg_not_there_etcdefaultgrub.fail.sh → ...t/tests/arg_not_in_etcdefaultgrub.fail.sh
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
13 changes: 8 additions & 5 deletions
13
..._etcdefaultgrub_recovery_disabled.fail.sh → ..._etcdefaultgrub_recovery_disabled.fail.sh
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
28 changes: 28 additions & 0 deletions
28
...d/templates/grub2_bootloader_argument/tests/arg_not_in_grubenv_and_not_referenced.pass.sh
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,28 @@ | ||
#!/bin/bash | ||
|
||
# platform = Oracle Linux 8,Red Hat Enterprise Linux 8 | ||
# packages = grub2,grubby | ||
|
||
{{%- if ARG_VARIABLE %}} | ||
# variables = {{{ ARG_VARIABLE }}}=correct_value | ||
{{%- set ARG_NAME_VALUE= ARG_NAME ~ "=correct_value" %}} | ||
{{%- endif %}} | ||
|
||
|
||
source common.sh | ||
|
||
# Removes audit argument from kernel command line in /boot/grub2/grubenv | ||
file="/boot/grub2/grubenv" | ||
if grep -q '^.*{{{ARG_NAME}}}=.*' "$file" ; then | ||
sed -i 's/\(^.*\){{{ARG_NAME}}}=[^[:space:]]*\(.*\)/\1 \2/' "$file" | ||
fi | ||
|
||
# ensure that the grubenv entry is not referenced | ||
for entry in /boot/loader/entries/*.conf; do | ||
if ! grep -q '\$kernelopts' "$entry"; then | ||
sed -i 's/^(options.*)$/\1 \$kernelopts/' "$entry" | ||
fi | ||
done | ||
|
||
# remediate with grubby, this ill ensure expanded options are in /boot/loader/entries/*.conf | ||
{{{ grub2_bootloader_argument_remediation(ARG_NAME, ARG_NAME_VALUE) }}} |
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
43 changes: 43 additions & 0 deletions
43
shared/templates/grub2_bootloader_argument/tests/correct_recovery_disabled.pass.sh
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,43 @@ | ||
#!/bin/bash | ||
# platform = multi_platform_all | ||
|
||
{{%- if 'ubuntu' in product %}} | ||
# packages = grub2 | ||
{{%- else %}} | ||
# packages = grub2,grubby | ||
{{%- endif %}} | ||
|
||
source common.sh | ||
|
||
# configure the argument in kernel command line in /boot/grub2/grubenv | ||
#file="/boot/grub2/grubenv" | ||
#if grep -q '^.*{{{ARG_NAME}}}=.*' "$file"; then | ||
# modify the GRUB command-line if the arg already exists | ||
# sed -i 's/\(^.*\){{{ARG_NAME}}}=[^[:space:]]*\(.*\)/\1 {{{ARG_NAME_VALUE}}} \2/' "$file" | ||
#else | ||
# no arg is present, append it | ||
# sed -i 's/\(^.*\(vmlinuz\|kernelopts\).*\)/\1 {{{ARG_NAME_VALUE}}}/' "$file" | ||
#fi | ||
|
||
|
||
# Correct the form of default kernel command line in GRUB /etc/default/grub and applies value through Grubby | ||
if grep -q '^GRUB_CMDLINE_LINUX_DEFAULT=.*{{{ ESCAPED_ARG_NAME }}}=.*"' '/etc/default/grub' ; then | ||
# modify the GRUB command-line if an arg=value already exists | ||
sed -i 's/\(^GRUB_CMDLINE_LINUX_DEFAULT=".*\){{{ ARG_NAME }}}=[^[:space:]]*\(.*"\)/\1 {{{ ARG_NAME_VALUE }}} \2/' '/etc/default/grub' | ||
else | ||
# no audit=arg is present, append it | ||
sed -i 's/\(^GRUB_CMDLINE_LINUX_DEFAULT=".*\)"/\1 {{{ ARG_NAME_VALUE }}}"/' '/etc/default/grub' | ||
fi | ||
|
||
# removing the parameter from the no recovery kernel parameters as well | ||
sed -i 's/\(^GRUB_CMDLINE_LINUX=".*\){{{ ARG_NAME }}}=[^[:space:]]*\(.*"\)/\1 \2/' '/etc/default/grub' | ||
|
||
# disabling recovery | ||
sed -i 's/\(^.*GRUB_DISABLE_RECOVERY=\).*/\1true/' '/etc/default/grub' | ||
|
||
#if the line is not present at all, add it | ||
if ! grep -q '^GRUB_CMDLINE_LINUX_DEFAULT=.*$' '/etc/default/grub'; then | ||
echo 'GRUB_CMDLINE_LINUX_DEFAULT="{{{ ARG_NAME_VALUE }}}"' >> /etc/default/grub | ||
fi | ||
|
||
{{{ grub2_bootloader_argument_remediation(ARG_NAME, ARG_NAME_VALUE) }}} |
44 changes: 44 additions & 0 deletions
44
shared/templates/grub2_bootloader_argument/tests/correct_value_grubenv_only.pass.sh
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,44 @@ | ||
#!/bin/bash | ||
|
||
# platform = Oracle Linux 8,Red Hat Enterprise Linux 8 | ||
# packages = grub2,grubby | ||
|
||
{{%- if ARG_VARIABLE %}} | ||
# variables = {{{ ARG_VARIABLE }}}=correct_value | ||
{{%- set ARG_NAME_VALUE= ARG_NAME ~ "=correct_value" %}} | ||
{{%- endif %}} | ||
|
||
|
||
source common.sh | ||
|
||
# adds argument from kernel command line into /etc/default/grub | ||
file="/etc/default/grub" | ||
if grep -q '^GRUB_CMDLINE_LINUX=.*{{{ARG_NAME}}}=.*"' "$file"; then | ||
sed -i 's/\(^GRUB_CMDLINE_LINUX=".*\){{{ARG_NAME}}}=[^[:space:]]*\(.*"\)/\1 {{{ARG_NAME_VALUE}}} \2/' "$file" | ||
else | ||
sed -i 's/^GRUB_CMDLINE_LINUX=".*/GRUB_CMDLINE_LINUX="{{{ARG_NAME_VALUE}}}"/' "$file" | ||
fi | ||
|
||
# configure the argument in kernel command line in /boot/grub2/grubenv | ||
file="/boot/grub2/grubenv" | ||
if grep -q '^.*{{{ARG_NAME}}}=.*' "$file"; then | ||
# modify the GRUB command-line if the arg already exists | ||
sed -i 's/\(^.*\){{{ARG_NAME}}}=[^[:space:]]*\(.*\)/\1 {{{ARG_NAME_VALUE}}} \2/' "$file" | ||
else | ||
# no arg is present, append it | ||
sed -i 's/\(^.*\(vmlinuz\|kernelopts\).*\)/\1 {{{ARG_NAME_VALUE}}}/' "$file" | ||
fi | ||
|
||
|
||
rm -f /boot/loader/entries/*.conf | ||
|
||
# create an entry which references grubenv | ||
{ | ||
echo 'title OS 1' | ||
echo 'version 5.0' | ||
echo 'linux /vmlinuz' | ||
echo 'initrd /initramfs' | ||
echo 'options root=UUID=abc-def rhgb ro quiet mock $kernelopts' | ||
echo 'grub_users $grub_users' | ||
echo 'grub_arg --unrestricted' | ||
} > /boot/loader/entries/mock2.conf |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it probably should be removed instead of having it commented out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the latest commit.