Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/skills/desktop-contract/references/image-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions system_files/shared/usr/bin/ublue-booted-image-sync
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
72 changes: 72 additions & 0 deletions tests/test_booted_image_unit.py
Original file line number Diff line number Diff line change
@@ -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()
Loading