Skip to content

fix(selinux): run bootc as the booted-image unit's ExecStart; parse in a second unit - #1220

Closed
Danathar wants to merge 5 commits into
mainfrom
fix/booted-image-split-sync-unit
Closed

Danathar wants to merge 5 commits into
mainfrom
fix/booted-image-split-sync-unit

Conversation

@Danathar

@Danathar Danathar commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary: Every Utah boot logged two SELinux denials because bootc status ran inside a script, in the wrong security context. This runs bootc as the boot unit's own command, so it gets its proper context, and moves the parsing into a second unit. #1203 found the cause and had the right idea; its review found two output-handling bugs, and this fixes them.

What changes

  • ublue-booted-image.service now runs only /usr/bin/bootc status --json, with its output going to /run/ublue-os/booted-image.json. As the unit's ExecStart, bootc enters its own SELinux domain, so its chcon probe is no longer denied mac_admin.
  • ublue-booted-image-sync.service is new. It runs after the first unit (Requires=/After=) and turns that JSON into /run/ublue-os/booted-image, which fastfetch reads.
  • A tmpfiles.d entry creates /run/ublue-os before the first unit starts.
  • Enablement: the new unit is enabled in configure-services.sh, the preset and the desktop contract, and the docs are updated.

Why two units (the #1203 review)

systemd opens a unit's StandardOutput= file again for every command the unit runs:

  • An ExecStartPost= that reads the file finds it truncated.
  • An ExecStartPre= that creates the file's directory fails before it runs.

I reproduced both with transient user units, using /bin/echo as a stand-in for bootc:

Shape What the parse step saw
One unit, StandardOutput=truncate: plus ExecStartPost= (#1203) 0 bytes
Snapshot unit, then a separate parse unit (this PR) 90 bytes; wrote ghcr.io/projectbluefin/utah:testing

Tests

  • tests/test_booted_image_unit.py covers both units, the tmpfiles rule, and that the sync script never runs bootc. It also fails any shipped unit that sends StandardOutput=/StandardError= to a file and has ExecStartPre=/ExecStartPost=.
  • iso/scripts/luks-e2e.sh now checks the installed image: both units are active, /run/ublue-os/booted-image is non-empty, and there are no chcon/bootc AVC denials.
  • Locally: test_booted_image_unit, test_desktop_contract and test_check_skill_frontmatter pass. The full local suite fails exactly the same tests as main, all of which need tools this machine doesn't have.
  • Booted-image proof: I'm dispatching build.yml with review_vm on this branch, and will post the result here.

Supersedes #1203 (@kylerankin), keeping its approach.

Refs #1198 (the denials come from common's CountMe; fix: projectbluefin/common#1689)

🤖 Generated with Claude Code

https://claude.ai/code/session_01WcWm7qQa538Zjcuvv8jBtn

…n a second unit

Every boot, ublue-booted-image-sync ran `bootc status --json` inside the
unconfined service domain, and bootc's relabelling chcon probe was denied
mac_admin: two AVC denials per boot (#1198).

- ublue-booted-image.service now runs only /usr/bin/bootc status --json,
  so bootc enters its own SELinux domain, with StandardOutput=truncate: into
  /run/ublue-os/booted-image.json.
- ublue-booted-image-sync.service (new; Requires/After the snapshot) parses
  that JSON into /run/ublue-os/booted-image. It is a separate unit because
  systemd reopens a unit's StandardOutput= file for every command: an
  ExecStartPost= in the same unit reads a truncated file, and an
  ExecStartPre= cannot create the directory its own output needs.
- tmpfiles.d creates /run/ublue-os before the snapshot runs.
- The sync unit is enabled in configure-services.sh, the preset and the
  desktop contract.
- tests/test_booted_image_unit.py checks both units, and also fails any
  shipped unit that sends output to a file and also has ExecStartPre= or
  ExecStartPost=.
- luks-e2e.sh checks the installed image has /run/ublue-os/booted-image and
  no chcon/bootc AVC denials.

Supersedes #1203, whose approach (bootc as ExecStart) this keeps, with the
output handling reworked as requested in its review.

Fixes #1198

Assisted-by: Claude Opus 5.5 via Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WcWm7qQa538Zjcuvv8jBtn
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@github-actions
github-actions Bot requested review from castrojo and hanthor November 14, 2026 13:38
@github-actions github-actions Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 14, 2026
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danathar

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hivecommons-hive hivecommons-hive Bot added author/clanker A contributor's own hive authored this PR under their login dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 14, 2026
@Danathar

Copy link
Copy Markdown
Contributor Author

Stand-in review at 0db1983. The approach is right, and better than one unit with ExecStartPost=: bootc as the bare ExecStart gets its own SELinux domain, and parsing in a second unit avoids the truncate-on-reopen problem. The new LUKS e2e assertion (no chcon/bootc denials, state file non-empty) checks the real outcome.

One behavior change worth deciding on purpose:

  • A bootc failure now fails the boot units. The old script ran bootc status --json 2>/dev/null || true and always exited 0. Now bootc's exit status is the unit's. If it ever exits non-zero (a non-bootc boot such as a live session, or a transient bootc error), ublue-booted-image.service shows as failed. Because the sync unit has Requires= plus After= on it, the sync unit isn't started either (systemd.unit(5)), so the system reports degraded.
  • Fix if you want the old tolerance: ExecStart=-/usr/bin/bootc status --json. Per systemd.service(5), the - prefix makes a failing exit status count as success. systemd parses the prefix itself and doesn't wrap the command, so bootc is still the executable and keeps its domain entrypoint. The sync script already exits 0 on empty or invalid JSON, so nothing else changes.
  • If failing loudly is intended, say so in the unit comment, so nobody adds || true back through a wrapper.

Small notes:

Not approving: this is Doug's PR. CI is still running.

The old ublue-booted-image-sync ran `bootc status --json || true` and always
exited 0. As the bare ExecStart, a bootc failure would fail the unit and,
through Requires=, keep ublue-booted-image-sync.service from starting.
The "-" prefix keeps the old tolerance; systemd strips it, so bootc is
still the executable and keeps its SELinux entrypoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WcWm7tJ5iop2b4GMkKSPAv
Signed-off-by: Danathar <6772335+Danathar@users.noreply.github.com>
@Danathar

Copy link
Copy Markdown
Contributor Author

Pushed 98c1a47 (Doug asked me to apply my recommendation): ExecStart=-/usr/bin/bootc status --json, with a comment explaining why, and the matching assertion in tests/test_booted_image_unit.py. That file's 9 tests pass locally. #1203 should close once this merges.

@Danathar
Danathar marked this pull request as draft November 14, 2026 13:54
@hivecommons-hive hivecommons-hive Bot removed the stage/050-review-pending Review swarm requested; awaiting a verdict for the current head label Nov 14, 2026
Danathar and others added 2 commits November 14, 2026 09:32
review_vm run 43600763520 on 0db1983 wrote /run/ublue-os/booted-image, but
the boot still logged both chcon mac_admin denials, from
unconfined_service_t. Running bootc as the unit's ExecStart does not move it
into another SELinux domain; any boot service runs it as
unconfined_service_t, where its relabelling probe is denied.

So no boot unit runs bootc now:

- ublue-booted-image-sync follows /proc/cmdline to the booted deployment
  (ostree= for ostree, composefs[.digest]= for composefs) and reads
  container-image-reference from its origin file, dropping the transport
  prefix. That is the ref bootc reports as .status.booted.image.image.image.
- ublue-booted-image.service is a single unit again; the separate sync unit,
  the tmpfiles entry and the "-" ExecStart prefix are gone.
- Tests run the script against ostree and composefs fixture trees, including
  three transports, a non-booted deployment, and no origin. The guard against
  file-output units with ExecStartPre=/ExecStartPost= stays.

Assisted-by: Claude Opus 5.5 via Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WcWm7qQa538Zjcuvv8jBtn
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
review_vm run 43605406732 on a3fe39d: ublue-booted-image no longer runs
bootc and wrote /run/ublue-os/booted-image, yet the boot still logged both
chcon mac_admin denials from unconfined_service_t. So #1198's attribution,
which was by timing (the denials came about 12.7 s into boot, when that unit
started), was wrong, and so was ublue-firstboot-date, which started at the
same moment but runs no chcon.

When the check fails, luks-e2e.sh now runs iso/scripts/avc-origin.sh on the
installed system. For each denial it prints the audit records sharing its
serial (SYSCALL with ppid and exe, PROCTITLE decoded to the chcon command
line), the parent's systemd unit from the journal, and the journal two
seconds either side.

Refs #1198

Assisted-by: Claude Opus 5.5 via Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WcWm7qQa538Zjcuvv8jBtn
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@Danathar

Copy link
Copy Markdown
Contributor Author

Re-review at 4496a61 (origin-file rework, supersedes my 98c1a47 - prefix): this is the better fix. If bootc's probe is denied even as the unit's own ExecStart, the only clean answer is not running bootc, and this drops the second unit and the tmpfiles entry with it.

Checked:

  • ostree path: ostree=/ostree/boot.N/<os>/<bootcsum>/<serial> → readlink -f under /sysroot lands on .../deploy/<csum>.<serial>, and the .origin keyfile sits beside it. The service runs as root, so the origin is readable.
  • Transport stripping: *docker://* first, then ostree-remote-registry:<remote>:, then ostree-*registry:, which gives the same bare ref bootc reports as .status.booted.image.image.image.
  • Failure mode: no ref means a message and exit 0 with no state file, the same tolerance as before. The write is atomic (mktemp + mv, 0644).
  • avc-origin.sh naming the process behind any remaining chcon/bootc denial on the LUKS e2e is a good failure-explainer.

Unverified from here: the composefs path (/sysroot/state/deploy/<id>/<id>.origin). The ostree path is what utah ships today, so it isn't a blocker. The PR is BEHIND now that #1219 has merged.

Run 43609614948: the image loads no audit rules, so the denials had no
SYSCALL record and no ppid. The journal window's 60-line cap also ended about
2 s before the denials (16:19:58.104 and .631). The visible part showed
bootupd's bootloader-update.service and bootc's
bootc-status-updated-onboot.target starting just before.

avc-origin.sh now lists every service whose ExecMainPID falls in the 300
PIDs before each denial (a parent's PID is almost always just below its
child's), and widens the journal window to ±1 s with a 400-line cap.

Refs #1198

Assisted-by: Claude Opus 5.5 via Claude Code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WcWm7qQa538Zjcuvv8jBtn
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@hanthor

hanthor commented Nov 16, 2026

Copy link
Copy Markdown
Member

Closing in favour of #1279. Owner decision (2026-11-16, delegated).

Thanks, @Danathar. Your diagnostics here are what pinned #1198 down: the ExecStart experiment (run 43600763520), the removal of bootc from the boot units (run 43605406732), and CountMe confirmed as the source with #1247 (run 43762243257). #1279 builds on them:

The .origin-file rework of ublue-booted-image-sync isn't needed for #1198 once the probe is dontaudited, so it isn't carried over. common#1689 is still worth landing on its own merits.

@hanthor hanthor closed this Nov 16, 2026
hanthor added a commit that referenced this pull request Nov 16, 2026
`bootc status` probes for mac_admin by running chcon with a label the
policy does not define. From a plain service (common's
projectbluefin-countme runs `bootc status --json` as root) the probe is
denied in unconfined_service_t, and every boot logs two AVC denials that
fail the testsuite's SELinux gate. bootc expects the denial and carries
on, so the fix is a policy module with one dontaudit rule, not an allow:
an allow would let every unconfined service write labels the policy does
not know and would change what the probe decides.

The module store is on read-only /usr once booted (#551), so the desktop
RUN step loads utah_bootc_probe.cil with `semodule -n -i`. A new
[selinux] section in the desktop contract makes the in-image verifier
check `semodule -l` and fail the build if the module is missing. The
installed-system e2e (review VM) now fails on any chcon/bootc AVC denial,
the check #1220 introduced.

Closes #1198

Assisted-by: Claude Opus via GitHub Copilot
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
hanthor added a commit that referenced this pull request Nov 16, 2026
`bootc status` probes for mac_admin by running chcon with a label the
policy does not define. From a plain service (common's
projectbluefin-countme runs `bootc status --json` as root) the probe is
denied in unconfined_service_t, and every boot logs two AVC denials that
fail the testsuite's SELinux gate. bootc expects the denial and carries
on, so the fix is a policy module with one dontaudit rule, not an allow:
an allow would let every unconfined service write labels the policy does
not know and would change what the probe decides.

The module store is on read-only /usr once booted (#551), so the desktop
RUN step loads utah_bootc_probe.cil with `semodule -n -i`. A new
[selinux] section in the desktop contract makes the in-image verifier
check `semodule -l` and fail the build if the module is missing. The
installed-system e2e (review VM) now fails on any chcon/bootc AVC denial,
the check #1220 introduced.

Closes #1198

Assisted-by: Claude Opus via GitHub Copilot
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
hanthor added a commit that referenced this pull request Nov 16, 2026
…1279)

* fix(selinux): dontaudit bootc's mac_admin probe from plain services

`bootc status` probes for mac_admin by running chcon with a label the
policy does not define. From a plain service (common's
projectbluefin-countme runs `bootc status --json` as root) the probe is
denied in unconfined_service_t, and every boot logs two AVC denials that
fail the testsuite's SELinux gate. bootc expects the denial and carries
on, so the fix is a policy module with one dontaudit rule, not an allow:
an allow would let every unconfined service write labels the policy does
not know and would change what the probe decides.

The module store is on read-only /usr once booted (#551), so the desktop
RUN step loads utah_bootc_probe.cil with `semodule -n -i`. A new
[selinux] section in the desktop contract makes the in-image verifier
check `semodule -l` and fail the build if the module is missing. The
installed-system e2e (review VM) now fails on any chcon/bootc AVC denial,
the check #1220 introduced.

Closes #1198

Assisted-by: Claude Opus via GitHub Copilot
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(contract): keep the desktop-contract skill within 500 lines

Assisted-by: Claude Opus via GitHub Copilot
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: mergeraptor[bot] <267480593+mergeraptor[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. author/clanker A contributor's own hive authored this PR under their login dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants