Skip to content

Commit

Permalink
revise other test scenarios of grub2_argument template
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtapolasek committed Sep 11, 2024
1 parent 19c63ae commit f6e1fa3
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 18 deletions.
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# platform = Oracle Linux 7
# Removes the argument from kernel command line in /etc/default/grub
if grep -q '^GRUB_CMDLINE_LINUX_DEFAULT=.*{{{ARG_NAME}}}=.*"' '/etc/default/grub' ; then
sed -i 's/\(^GRUB_CMDLINE_LINUX_DEFAULT=".*\){{{ARG_NAME}}}=[^[:space:]]*\(.*"\)/\1 \2/' '/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=""' >> /etc/default/grub
fi
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) }}}
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ if grep -q '^.*{{{ARG_NAME}}}=.*' "$file" ; then
sed -i 's/\(^.*\){{{ARG_NAME}}}=[^[:space:]]*\(.*\)/\1 \2/' "$file"
fi

for entry in /boot/loader/entries/*.conf; do
if ! grep -q '\$kernelopts' "$entry"; then
sed -i 's/^(options.*)$/\1 \$kernelopts/' "$entry"
fi
done

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# platform = Red Hat Enterprise Linux 9,Red Hat Enterprise Linux 10,multi_platform_fedora
# platform = multi_platform_fedora,multi_platform_rhel
# packages = grub2,grubby

source common.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ else
# no arg is present, append it
sed -i 's/\(^.*\(vmlinuz\|kernelopts\).*\)/\1 {{{ARG_NAME}}}=wrong/' "$file"
fi

# Ensure that grubenv is referenced through $kernelopts
# othervise contents of grubenv are ignored
for entry in /boot/loader/entries/*.conf; do
if ! grep -q '\$kernelopts' "$entry"; then
sed -i 's/^(options.*)$/\1 \$kernelopts/' "$entry"
fi
done

0 comments on commit f6e1fa3

Please sign in to comment.