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 special conditions for bootable containers #12531

Merged

Conversation

jan-cerny
Copy link
Collaborator

@jan-cerny jan-cerny commented Oct 23, 2024

This commit adds 2 new Jinja macros: bootc_build and not_bootc_build. These macros define Bash conditional expressions that are evaluated as true or false if the remediation is performed during a build of a bootable container image or not performed during a build of a bootable container image. These macros can be used in Bash remediation code. They can be used to control the remediation behavior in the bootable container build environment.

The code relies on new OpenSCAP feature implemented in OpenSCAP/openscap#2170.

This commit changes the Bash remediation in rule
disable_ctrlaltdel_reboot to demonstrate usefulness of the new macros.

This commit adds 2 new Jinja macros: `bootc_build` and
`not_bootc_build`.  These macros define Bash conditional expressions
that are evaluated as true or false if the remediation is performed
during a build of a bootable container image or not performed during a
build of a bootable container image. These macros can be used in Bash
remediation code.  They can be used to control the remediation behavior
in the bootable container build environment.

This commit changes the Bash remediation in rule
`disable_ctrlaltdel_reboot` to demonstrate usefulness of the new macros.
@jan-cerny jan-cerny added the Image Mode Bootable containers and Image Mode RHEL label Oct 23, 2024
Copy link

Start a new ephemeral environment with changes proposed in this pull request:

rhel8 (from CTF) Environment (using Fedora as testing environment)
Open in Gitpod

Fedora Testing Environment
Open in Gitpod

Oracle Linux 8 Environment
Open in Gitpod

@jan-cerny jan-cerny added this to the 0.1.75 milestone Oct 23, 2024
Copy link

This datastream diff is auto generated by the check Compare DS/Generate Diff

Click here to see the full diff
bash remediation for rule 'xccdf_org.ssgproject.content_rule_disable_ctrlaltdel_reboot' differs.
--- xccdf_org.ssgproject.content_rule_disable_ctrlaltdel_reboot
+++ xccdf_org.ssgproject.content_rule_disable_ctrlaltdel_reboot
@@ -1,8 +1,13 @@
 # Remediation is applicable only in certain platforms
 if rpm --quiet -q kernel; then
 
-systemctl disable --now ctrl-alt-del.target
-systemctl mask --now ctrl-alt-del.target
+if [[ "$OSCAP_BOOTC_BUILD" == "YES" ]] ; then
+    systemctl disable ctrl-alt-del.target
+    systemctl mask ctrl-alt-del.target
+else
+    systemctl disable --now ctrl-alt-del.target
+    systemctl mask --now ctrl-alt-del.target
+fi
 
 else
     >&2 echo 'Remediation is not applicable, nothing was done'

@jan-cerny
Copy link
Collaborator Author

/retest

@Mab879 Mab879 self-assigned this Oct 24, 2024
This macro defines a conditional expression that is evaluated as true
if the remediation is performed during a build of a bootable container image.
#}}
{{%- macro bootc_build() -%}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we prefix with bash_?

@jan-cerny
Copy link
Collaborator Author

I have add bash_ prefix.

Copy link

codeclimate bot commented Oct 25, 2024

Code Climate has analyzed commit 0834570 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 60.9% (0.0% change).

View more on Code Climate.

Copy link
Member

@Mab879 Mab879 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Mab879
Copy link
Member

Mab879 commented Oct 25, 2024

/retest

@Mab879 Mab879 merged commit 4804243 into ComplianceAsCode:master Oct 25, 2024
91 of 104 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Image Mode Bootable containers and Image Mode RHEL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants