-
Notifications
You must be signed in to change notification settings - Fork 150
Soft reboot: Detect SELinux policy deltas #1768
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
Merged
cgwalters
merged 1 commit into
bootc-dev:main
from
gursewak1997:fix-1760-detect-selinux-policy-deltas-soft-reboot
Nov 21, 2025
+172
−1
Merged
Changes from all commits
Commits
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
This file contains hidden or 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 hidden or 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 hidden or 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,104 @@ | ||
| # Verify that soft reboot is blocked when SELinux policies differ | ||
| use std assert | ||
| use tap.nu | ||
|
|
||
| let soft_reboot_capable = "/usr/lib/systemd/system/soft-reboot.target" | path exists | ||
| if not $soft_reboot_capable { | ||
| echo "Skipping, system is not soft reboot capable" | ||
| return | ||
| } | ||
|
|
||
| # Check if SELinux is enabled | ||
| let selinux_enabled = "/sys/fs/selinux/enforce" | path exists | ||
| if not $selinux_enabled { | ||
| echo "Skipping, SELinux is not enabled" | ||
| return | ||
| } | ||
|
|
||
| # This code runs on *each* boot. | ||
| bootc status | ||
|
|
||
| # Run on the first boot | ||
| def initial_build [] { | ||
| tap begin "Build base image and test soft reboot with SELinux policy change" | ||
|
|
||
| let td = mktemp -d | ||
| cd $td | ||
|
|
||
| bootc image copy-to-storage | ||
|
|
||
| # Create a derived container that installs a custom SELinux policy module | ||
| # Installing a policy module will change the compiled policy checksum | ||
| # Following Colin's suggestion and the composefs-rs example | ||
| # We create a minimal policy module and install it | ||
| "FROM localhost/bootc | ||
| # Install tools needed to build and install SELinux policy modules | ||
| RUN dnf install -y selinux-policy-devel checkpolicy policycoreutils | ||
|
|
||
| # Create a minimal SELinux policy module that will change the policy checksum | ||
| # We install it to ensure it's part of the deployment filesystem | ||
| RUN <<EORUN | ||
| set -eux | ||
| mkdir -p /tmp/bootc-test-policy | ||
| cd /tmp/bootc-test-policy | ||
| echo 'module bootc_test_policy 1.0;' > bootc_test_policy.te | ||
| echo 'require {' >> bootc_test_policy.te | ||
| echo ' type unconfined_t;' >> bootc_test_policy.te | ||
| echo ' class file { read write };' >> bootc_test_policy.te | ||
| echo '}' >> bootc_test_policy.te | ||
| echo 'type bootc_test_t;' >> bootc_test_policy.te | ||
| checkmodule -M -m -o bootc_test_policy.mod bootc_test_policy.te | ||
| semodule_package -o bootc_test_policy.pp -m bootc_test_policy.mod | ||
| semodule -i bootc_test_policy.pp | ||
| rm -rf /tmp/bootc-test-policy | ||
| # Clean up dnf cache and logs, and SELinux policy generation artifacts to satisfy lint checks | ||
| dnf clean all | ||
| rm -rf /var/log/dnf* /var/log/hawkey.log /var/log/rhsm | ||
| rm -rf /var/cache/dnf /var/lib/dnf | ||
| rm -rf /var/lib/sepolgen /var/lib/rhsm /var/cache/ldconfig | ||
| EORUN | ||
| " | save Dockerfile | ||
|
|
||
| # Build the derived image | ||
| podman build --quiet -t localhost/bootc-derived-policy . | ||
|
|
||
| # Verify soft reboot preparation hasn't happened yet | ||
| assert (not ("/run/nextroot" | path exists)) | ||
|
|
||
| # Try to soft reboot - this should fail because policies differ | ||
| bootc switch --soft-reboot=auto --transport containers-storage localhost/bootc-derived-policy | ||
| let st = bootc status --json | from json | ||
|
|
||
| # Verify staged deployment exists | ||
| assert ($st.status.staged != null) "Expected staged deployment to exist" | ||
|
|
||
| # The staged deployment should NOT be soft-reboot capable because policies differ | ||
| assert (not $st.status.staged.softRebootCapable) "Expected soft reboot to be blocked due to SELinux policy difference, but softRebootCapable is true" | ||
|
|
||
| # Verify soft reboot preparation didn't happen | ||
| assert (not ("/run/nextroot" | path exists)) "Soft reboot should not be prepared when policies differ" | ||
|
|
||
| # Do a full reboot | ||
| tmt-reboot | ||
| } | ||
|
|
||
| # The second boot; verify we're in the derived image | ||
| def second_boot [] { | ||
| tap begin "Verify deployment with different SELinux policy" | ||
|
|
||
| # Verify we're in the new deployment | ||
| let st = bootc status --json | from json | ||
| let booted = $st.status.booted.image | ||
| assert ($booted.image.image | str contains "bootc-derived-policy") $"Expected booted image to contain 'bootc-derived-policy', got: ($booted.image.image)" | ||
|
|
||
| tap ok | ||
| } | ||
|
|
||
| def main [] { | ||
| # See https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test | ||
| match $env.TMT_REBOOT_COUNT? { | ||
| null | "0" => initial_build, | ||
| "1" => second_boot, | ||
| $o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } }, | ||
| } | ||
| } | ||
This file contains hidden or 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,3 @@ | ||
| summary: Test soft reboot with SELinux policy changes | ||
| test: nu booted/test-soft-reboot-selinux-policy.nu | ||
| duration: 30m |
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.
I would say "Ask for a soft reboot, but we won't get one because policies differ"