|
| 1 | +# Verify that correct labels are applied after a deployment |
| 2 | +use std assert |
| 3 | +use tap.nu |
| 4 | + |
| 5 | +# This code runs on *each* boot. |
| 6 | +# Here we just capture information. |
| 7 | +bootc status |
| 8 | + |
| 9 | +# Run on the first boot |
| 10 | +def initial_build [] { |
| 11 | + tap begin "local image push + pull + upgrade" |
| 12 | + |
| 13 | + let td = mktemp -d |
| 14 | + cd $td |
| 15 | + |
| 16 | + bootc image copy-to-storage |
| 17 | + |
| 18 | + # A simple derived container that customizes selinux policy for random dir |
| 19 | + "FROM localhost/bootc |
| 20 | +RUN mkdir /opt123; echo \"/opt123 /opt\" >> /etc/selinux/targeted/contexts/files/file_contexts.subs_dist |
| 21 | +" | save Dockerfile |
| 22 | + # Build it |
| 23 | + podman build -t localhost/bootc-derived . |
| 24 | + |
| 25 | + bootc switch --soft-reboot=auto --transport containers-storage localhost/bootc-derived |
| 26 | + |
| 27 | + assert (not ("/opt123" | path exists)) |
| 28 | + |
| 29 | + # https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test |
| 30 | + tmt-reboot |
| 31 | +} |
| 32 | + |
| 33 | +# The second boot; verify we're in the derived image and directory has correct selinux label |
| 34 | +def second_boot [] { |
| 35 | + tap begin "Verify directory exists and has correct SELinux label" |
| 36 | + |
| 37 | + assert ("/opt123" | path exists) |
| 38 | + |
| 39 | + # Verify the directories have the correct SELinux labels |
| 40 | + let opt123_label = (^stat --format=%C /opt123 | str trim) |
| 41 | + let opt_label = (^stat --format=%C /opt | str trim) |
| 42 | + |
| 43 | + print $"opt123 SELinux label: ($opt123_label)" |
| 44 | + print $"opt SELinux label: ($opt_label)" |
| 45 | + |
| 46 | + # Both should have the same label (system_u:object_r:usr_t:s0) |
| 47 | + assert ($opt123_label | str contains "system_u:object_r:usr_t:s0") $"Expected system_u:object_r:usr_t:s0 label for /opt123, got: ($opt123_label)" |
| 48 | + assert ($opt_label | str contains "system_u:object_r:usr_t:s0") $"Expected system_u:object_r:usr_t:s0 label for /opt, got: ($opt_label)" |
| 49 | + |
| 50 | + # Verify both labels are the same |
| 51 | + assert ($opt123_label == $opt_label) $"Labels should be the same: opt123=($opt123_label) vs opt=($opt_label)" |
| 52 | + |
| 53 | + tap ok |
| 54 | +} |
| 55 | + |
| 56 | +def main [] { |
| 57 | + # See https://tmt.readthedocs.io/en/stable/stories/features.html#reboot-during-test |
| 58 | + match $env.TMT_REBOOT_COUNT? { |
| 59 | + null | "0" => initial_build, |
| 60 | + "1" => second_boot, |
| 61 | + $o => { error make { msg: $"Invalid TMT_REBOOT_COUNT ($o)" } }, |
| 62 | + } |
| 63 | +} |
0 commit comments