From ea05d5e6c85f7c4ab7f3abc9dc655ea0f7a6db0d Mon Sep 17 00:00:00 2001 From: kylerankin Date: Fri, 13 Nov 2026 03:38:07 +0000 Subject: [PATCH] fix(selinux): run bootc status as the booted-image unit's ExecStart ublue-booted-image.service recorded the booted image ref by running `bootc status --json` from the ublue-booted-image-sync script. bootc then ran in the script's unconfined service domain instead of its own SELinux domain, so its relabelling chcon probe was denied mac_admin, logging two AVC denials in every boot. Run bootc as the unit's bare ExecStart so it enters bootc's install_exec_t domain, truncate its JSON to a file, and parse that file in ExecStartPost with the existing sync script. /run/ublue-os/booted-image still holds the same reference for fastfetch. Hive-Run: projectbluefin/utah#1198 Hive-Plan: selinux-booted-image-avc-denials Hive-Spec: projectbluefin/utah#1198 Signed-off-by: kylerankin --- .../desktop-contract/references/image-info.md | 9 ++- .../shared/usr/bin/ublue-booted-image-sync | 12 ++-- .../systemd/system/ublue-booted-image.service | 10 ++- tests/test_booted_image_unit.py | 72 +++++++++++++++++++ 4 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 tests/test_booted_image_unit.py diff --git a/docs/skills/desktop-contract/references/image-info.md b/docs/skills/desktop-contract/references/image-info.md index 2b39447dd..1e1bd86d6 100644 --- a/docs/skills/desktop-contract/references/image-info.md +++ b/docs/skills/desktop-contract/references/image-info.md @@ -10,8 +10,13 @@ upstream script requires review. Common's script asks `/usr/libexec/ublue-booted-image` for the tag, and that reader falls back to the boot-time snapshot (`/run/ublue-os/booted-image`) when -unprivileged `bootc status` fails. The build patches nothing there; it fails if -image-info stops calling the reader or the reader loses the snapshot fallback. +unprivileged `bootc status` fails. The snapshot is written by +`ublue-booted-image.service`, which runs `bootc status` as its own bare +`ExecStart`, not from the `ublue-booted-image-sync` script: inside the script +the call ran in the unconfined service domain and bootc's relabelling `chcon` +probe was denied `mac_admin`, logging two AVC denials per boot (#1198). The +build patches nothing there; it fails if image-info stops calling the reader +or the reader loses the snapshot fallback. `tests/test_image_info_patch.py` exercises these paths without a composed image. Never suppress fastfetch stderr to clean up a screenshot. Historical verification screenshots remain evidence of their diff --git a/system_files/shared/usr/bin/ublue-booted-image-sync b/system_files/shared/usr/bin/ublue-booted-image-sync index edb350e04..2d81f2836 100755 --- a/system_files/shared/usr/bin/ublue-booted-image-sync +++ b/system_files/shared/usr/bin/ublue-booted-image-sync @@ -1,14 +1,14 @@ #!/usr/bin/bash # Record the booted bootc image ref where unprivileged consumers (Common's # /usr/libexec/ublue-booted-image, used by fastfetch's ublue-image-info.sh) -# can read it. `bootc status` requires root on bootc >= 1.14, so the live -# query is dead in user sessions, and the baked image tag is the compose-time -# tag. The booted ref cannot change within a boot, so one write per boot is -# always accurate. Parity with Dakota (projectbluefin/utah#675). +# can read it. The booted ref cannot change within a boot, so one write per +# boot is always accurate. bootc status runs as the unit's ExecStart, not here, +# so it enters bootc's SELinux domain instead of being denied mac_admin by its +# relabelling chcon probe (projectbluefin/utah#1198). Parity with Dakota (#675). set -euo pipefail -bootc_json="$(bootc status --json 2>/dev/null || true)" -ref="$(jq -r '.status.booted.image.image.image // empty' <<<"${bootc_json}" 2>/dev/null || true)" +json="${1:-/run/ublue-os/booted-image.json}" +ref="$(jq -r '.status.booted.image.image.image // empty' "${json}" 2>/dev/null || true)" if [ -z "${ref}" ]; then echo "no booted bootc image found; leaving no state file" >&2 exit 0 diff --git a/system_files/shared/usr/lib/systemd/system/ublue-booted-image.service b/system_files/shared/usr/lib/systemd/system/ublue-booted-image.service index 7512ebfd7..c187979cf 100644 --- a/system_files/shared/usr/lib/systemd/system/ublue-booted-image.service +++ b/system_files/shared/usr/lib/systemd/system/ublue-booted-image.service @@ -8,7 +8,15 @@ Before=systemd-user-sessions.service [Service] Type=oneshot RemainAfterExit=yes -ExecStart=/usr/bin/ublue-booted-image-sync +# Create the state dir before bootc's StandardOutput truncates its JSON there. +ExecStartPre=/usr/bin/install -d -m 0755 /run/ublue-os +# ExecStart must stay the bare bootc binary: its install_exec_t label is the +# entrypoint into bootc's SELinux domain. Run from the sync script in the +# unconfined service domain, bootc's relabelling chcon probe was denied +# mac_admin, logging two AVC denials every boot (projectbluefin/utah#1198). +ExecStart=/usr/bin/bootc status --json +StandardOutput=truncate:/run/ublue-os/booted-image.json +ExecStartPost=/usr/bin/ublue-booted-image-sync /run/ublue-os/booted-image.json [Install] WantedBy=multi-user.target diff --git a/tests/test_booted_image_unit.py b/tests/test_booted_image_unit.py new file mode 100644 index 000000000..a3bc9a234 --- /dev/null +++ b/tests/test_booted_image_unit.py @@ -0,0 +1,72 @@ +"""ublue-booted-image.service must not log SELinux denials on boot. + +The unit recorded the booted image ref by running `bootc status --json` from +the `ublue-booted-image-sync` script. bootc started inside that script's +`unconfined_service_t` domain, so its `mac_admin` relabelling probe (a +`chcon` call) was denied, logging two AVC entries every boot. The fix runs +bootc as the unit's own `ExecStart`, where its `install_exec_t` label is the +entrypoint into bootc's SELinux domain, and leaves the script to parse the +JSON the unit writes. +""" +import configparser +from pathlib import Path +import unittest + +UNIT = Path(__file__).resolve().parents[1] / ( + "system_files/shared/usr/lib/systemd/system/ublue-booted-image.service") +SCRIPT = Path(__file__).resolve().parents[1] / ( + "system_files/shared/usr/bin/ublue-booted-image-sync") +STATE_FILE = "/run/ublue-os/booted-image" + + +def load() -> configparser.ConfigParser: + parser = configparser.ConfigParser(strict=False, interpolation=None) + parser.optionxform = str + parser.read_string(UNIT.read_text()) + return parser + + +class BootedImageUnitTests(unittest.TestCase): + def test_runs_bootc_directly(self): + # bootc's install_exec_t label is its SELinux entrypoint; running it + # from the script ran it in the unconfined service domain and its + # chcon probe was denied mac_admin (projectbluefin/utah#1198). + service = load()["Service"] + self.assertEqual(service["ExecStart"], "/usr/bin/bootc status --json") + self.assertEqual(service["Type"], "oneshot") + + def test_captures_bootc_json_then_parses_it(self): + service = load()["Service"] + # bootc writes its JSON here; the sync script reads that file next. + self.assertEqual( + service["StandardOutput"], + "truncate:/run/ublue-os/booted-image.json", + ) + self.assertTrue( + service["ExecStartPost"].endswith( + "/run/ublue-os/booted-image.json" + ) + ) + + def test_execstart_pre_makes_the_state_dir(self): + # StandardOutput=truncate writes before any script runs, so the dir + # must exist first or the unit fails to start. + self.assertEqual( + load()["Service"]["ExecStartPre"], + "/usr/bin/install -d -m 0755 /run/ublue-os", + ) + + def test_script_does_not_run_bootc(self): + # The bug was the script running bootc itself. The bare binary must be + # the only place bootc status runs. + script = SCRIPT.read_text() + self.assertNotIn("bootc status --json", script) + + def test_script_writes_the_state_file_the_reader_reads(self): + script = SCRIPT.read_text() + self.assertIn(STATE_FILE, script) + self.assertIn(".status.booted.image.image.image", script) + + +if __name__ == "__main__": + unittest.main()