Skip to content

fix(selinux): stop two harmless security warnings on every boot - #1203

Closed
kylerankin wants to merge 2 commits into
projectbluefin:testingfrom
kylerankin:fix/selinux-booted-image-avc-denials-2
Closed

kylerankin wants to merge 2 commits into
projectbluefin:testingfrom
kylerankin:fix/selinux-booted-image-avc-denials-2

Conversation

@kylerankin

@kylerankin kylerankin commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary: Every time Utah starts, a small service that records which version of Utah is running makes the tool that updates Utah run in the wrong security context. That writes two harmless "denied" warnings to the security log on every boot. Nothing breaks, but those warnings are alarming to see, and now that Utah's automated tests read that log, they would fail every test run. This change runs the update tool the way Utah already runs it elsewhere — as the service's own startup command instead of from inside a helper script — so it gets the correct security context and the warnings stop, while still recording the same image for fastfetch to show.

What I need from you: Approve it.


What changed

  • The service that records the booted image now runs the update tool directly as its own startup command (ExecStart), so the tool runs in its own SELinux domain instead of inside the helper script's broad, unrestricted domain.
  • The helper script no longer runs the update tool. It only reads the output the service saved and writes it, unchanged, where fastfetch can find it.
  • A startup step creates the folder for the saved output first, so the tool has somewhere to write before it runs.

Why

  • The two warnings come from the update tool's own self-check, which probes whether it may relabel files. That probe is allowed only when the tool runs in its own SELinux domain. Wrapped inside the helper script it ran in the unrestricted service domain, so the probe was denied and logged two SELinux "denied" entries every boot.
  • Utah already runs this same tool the correct way in one other service, whose notes say exactly this: the tool must stay the bare startup command, and wrapping it in a script put it in the wrong context.
  • Evidence: a testsuite run on ghcr.io/projectbluefin/utah:testing failed its SELinux gate on exactly these two records — two chcon calls denied mac_admin, 134 ms apart, about 12.7 s into boot, from ublue-booted-image.service.

Acceptance

  • No chcon "denied" entries in the boot log or audit log of a booted :testing build.
  • /run/ublue-os/booted-image still holds the same reference bootc status reports, so fastfetch shows the right image.
  • The reader that fastfetch uses still works.

Tests

  • Added a unit test (tests/test_booted_image_unit.py) that pins the service's shape: the update tool runs directly as ExecStart, its output is truncated to a file, a startup step makes the folder first, the helper script reads that file, and the helper script no longer runs the tool itself. All 5 cases pass.

Note for a maintainer

  • The SELinux gate in the testsuite is only reachable on a built image. If you can, run testsuite manual.yml with suites=common on this PR's built image (testsuite fix(tuned): keep TuneD off the bootc sysroot lock #1171, or the main branch) and link the run so the AVC gate is confirmed green.

Closes #1198

— hive: backend=pi model=lemonade/ornith-1.5-35b-a3b-gguf-q6_k

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign ahmedadan after the PR has been reviewed.
You can assign the PR to them by writing /assign @ahmedadan in a comment when ready.

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

Copy link
Copy Markdown
Contributor

/ok-to-test

@github-actions

Copy link
Copy Markdown
Contributor

Cannot /ok-to-test because Error: hivecommons-hive[bot] is not a reviewer or approver for any changed file

@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 13, 2026

@Danathar Danathar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tracking down the AVC source; running bootc status as the bare ExecStart is the right idea. Two problems with how the output is captured, though. Both reproduce on systemd 259 with a transient unit.

1. ExecStartPost truncates the JSON before the sync script reads it.
StandardOutput= applies to every process the unit runs, not just ExecStart. Each command opens truncate:/run/ublue-os/booted-image.json again when it starts, so by the time ublue-booted-image-sync runs, the file is empty. jq finds no ref, and the script exits 0 with "no booted bootc image found", so /run/ublue-os/booted-image is never written.

Repro: systemd-run --user --wait -p Type=oneshot -p StandardOutput=truncate:/var/tmp/t/out.json -p "ExecStartPost=/bin/sh -c 'wc -c < /var/tmp/t/out.json > /var/tmp/t/post.txt'" /bin/echo '{"hello":"world"}'. post.txt says 0, and out.json ends at 0 bytes.

2. ExecStartPre can't create the directory its own stdout needs.
For the same reason, systemd opens /run/ublue-os/booted-image.json for the install -d command too, before it runs. If /run/ublue-os doesn't exist, that open fails and the unit fails. Nothing in utah creates /run/ublue-os earlier in boot; today only the sync script does. Repro: same command with -p "ExecStartPre=/usr/bin/install -d …/newdir" and stdout pointed into newdir. Result: Finished with result: exit-code, and newdir is never created.

The new unit test passes because it checks the unit file's shape, not what systemd does with it.

Suggested shape:

  • Create the directory before the unit runs, with a tmpfiles.d entry (d /run/ublue-os 0755 root root -), and drop the ExecStartPre.
  • Keep ublue-booted-image.service as only ExecStart=/usr/bin/bootc status --json plus StandardOutput=truncate:…json.
  • Move the parse step into its own oneshot unit that has no StandardOutput override. For example, ublue-booted-image-sync.service with Requires=/After=ublue-booted-image.service, the same Before=systemd-user-sessions.service, and ExecStart=/usr/bin/ublue-booted-image-sync /run/ublue-os/booted-image.json.
  • Add a test that fails when a unit with StandardOutput=file:/truncate: also has ExecStartPre=/ExecStartPost=.
  • If possible, show /run/ublue-os/booted-image populated on a booted image (the acceptance line in the description).

#1201 and #1203 have identical diffs, so I'm closing #1201 as a duplicate. Please carry on in #1203.

@hivecommons-hive hivecommons-hive Bot added stage/072-returned-to-contributor Contributor PR: CI red, changes requested or conflicting; diagnosis posted, author must act and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 13, 2026
@hivecommons-hive

hivecommons-hive Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

@kylerankin this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Review asks:

  • the review swarm requested changes

Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path.

Queued in your relay fix queue (4 waiting): fixes are handed out before new work as soon as you have capacity.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@kylerankin the hive has adopted this PR (stage/074-adopted-by-hive): the review asks stayed open (a maintainer requested changes; the hive is pushing the fix) for 2h after the nudge and the relay nudge went unanswered. The hive will rebase this branch on testing here; your commits and sign-off stay. Push a new head yourself at any time and the hive yields it back to you.

@hivecommons-hive hivecommons-hive Bot added stage/074-adopted-by-hive Contributor PR adopted: author unavailable after red CI; the hive is finishing it (takeover path) and removed stage/072-returned-to-contributor Contributor PR: CI red, changes requested or conflicting; diagnosis posted, author must act labels Nov 13, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

The hive adopted this PR (stage/074-adopted-by-hive) but its head c8d1ae87964a has not moved for 12h1m and the hive has nothing it can push: adoption-stalled:human-changes-requested.

Blocker: lane reason contributor-lane:changes-requested on this head and nothing changed.

Moving to stage/085-needs-decision so a person sees it. This is not a merge-approval wait: the lane has not admitted this head.

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#1198
Hive-Plan: selinux-booted-image-avc-denials
Hive-Spec: projectbluefin#1198

Signed-off-by: kylerankin <kylerankin@users.noreply.github.com>
@kylerankin
kylerankin force-pushed the fix/selinux-booted-image-avc-denials-2 branch from c8d1ae8 to 851bff0 Compare November 14, 2026 20:03
@kylerankin

Copy link
Copy Markdown
Contributor Author

hive-base-moved: base rebased onto 5c2986e (testing tip). behind_by is now 0; branch is clean and mergeable. Continuing to review comments.


🐝 Hive Agent: contributor | SHA: 851bff0

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@kylerankin this PR has a new head without confirmed hive push evidence, so the hive has handed this PR back to you (stage/074-adopted-by-hive → stage/072-returned-to-contributor). It will nudge again if CI stays red.

@hivecommons-hive hivecommons-hive Bot added stage/072-returned-to-contributor Contributor PR: CI red, changes requested or conflicting; diagnosis posted, author must act and removed stage/085-needs-decision A human decision is owed: sentinel alert, hold/needs-decision label, human-only rule or parked issue labels Nov 14, 2026
…1203)

ublue-booted-image.service recorded the booted bootc image by truncating
`bootc status --json` to a file and parsing it in ExecStartPost. That broke
two ways on systemd 259: StandardOutput=truncate: applies to every Exec* of
the unit, so the ExecStartPost parse step opened the same path and truncated
it to empty before the script read it, and the ExecStartPre that created
/run/ublue-os also opened the stdout file before the directory existed.

Move the parse into a new ublue-booted-image-sync.service unit that has no
StandardOutput override, keyed Requires=/After= the bootc unit. Create
/run/ublue-os early with a tmpfiles.d rule instead of ExecStartPre, so it
exists before bootc's StandardOutput truncates its JSON there. A test now
fails if any unit truncates stdout while also running ExecStartPre/Post.

Hive-Run: projectbluefin#1203
Hive-Plan: selinux-booted-image-avc-denials-2
Hive-Spec: projectbluefin#1203

Signed-off-by: kylerankin <kylerankin@users.noreply.github.com>
@kylerankin

Copy link
Copy Markdown
Contributor Author

Addressed on the new head (85d5615). Both bugs were real StandardOutput=truncate:-applies-to-every-Exec* issues, so I split the work across two units:

  1. ExecStartPost no longer truncates the JSON. The parse moved to a new ublue-booted-image-sync.service (ExecStart only, no StandardOutput), keyed Requires=/After=ublue-booted-image.service. The bootc unit keeps only ExecStart=/usr/bin/bootc status --json + StandardOutput=truncate:…json.

  2. /run/ublue-os now exists before bootc runs. Added utah-booted-image.conf with d /run/ublue-os 0755 root root -; dropped the ExecStartPre. The sync script still mkdirs defensively, but the tmpfiles rule is what guarantees the dir before the bootc unit opens its stdout.

Tests (tests/test_booted_image_unit.py, all pass): the sync unit has no StandardOutput, the dir comes from tmpfiles, and a regression guard (test_no_unit_truncates_what_it_also_runs) fails if any unit sets StandardOutput=file:/truncate: while also running ExecStartPre/ExecStartPost.

The remaining acceptance line — show /run/ublue-os/booted-image populated on a booted image — needs a real factory boot (unprivileged bootc status on the live image), which I can't run here; flagging it as the runtime check before merge.


🐝 Hive Agent: contributor | SHA: 85d5615

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@kylerankin the hive has adopted this PR (stage/074-adopted-by-hive): the review asks stayed open (the review swarm requested changes) for 2h after the nudge and the relay nudge went unanswered. The hive will rebase this branch on testing here; your commits and sign-off stay. Push a new head yourself at any time and the hive yields it back to you.

@hivecommons-hive hivecommons-hive Bot added stage/074-adopted-by-hive Contributor PR adopted: author unavailable after red CI; the hive is finishing it (takeover path) and removed stage/072-returned-to-contributor Contributor PR: CI red, changes requested or conflicting; diagnosis posted, author must act labels Nov 14, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

The hive adopted this PR (stage/074-adopted-by-hive) but its head 85d5615bf5ca has not moved for 12h1m and the hive has nothing it can push: adoption-stalled:contributor-lane:changes-requested.

Blocker: lane reason contributor-lane:changes-requested on this head and nothing changed.

Moving to stage/085-needs-decision so a person sees it. This is not a merge-approval wait: the lane has not admitted this head.

@hivecommons-hive hivecommons-hive Bot added stage/085-needs-decision A human decision is owed: sentinel alert, hold/needs-decision label, human-only rule or parked issue and removed stage/074-adopted-by-hive Contributor PR adopted: author unavailable after red CI; the hive is finishing it (takeover path) labels Nov 15, 2026

@Danathar Danathar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stand-in re-review at 85d5615 (the hive's reviewers are out of quota). The two-unit split fixes the truncate bugs from my last review. But test-VM runs show this approach doesn't stop the #1198 denials, so it can't close that issue.

Evidence: #1220 tried the same design at 0db1983: ublue-booted-image.service with ExecStart=/usr/bin/bootc status --json and the parse in a second unit. Its review-VM run 43600763520 still logged both denials: { mac_admin } for pid=… comm="chcon" capability=33 scontext=system_u:system_r:unconfined_service_t. Running bootc as a unit's bare ExecStart doesn't move it into another domain. Then a3fe39d removed bootc from boot units entirely, and run 43605406732 logged the same two denials anyway. So #1198's attribution to this unit, which was by timing, looks wrong. Something else runs that chcon, and #1220 is now adding diagnostics (iso/scripts/avc-origin.sh) to find it.

Also: ExecStart=/usr/bin/bootc status --json has no - prefix. A bootc failure would now fail the unit and, through Requires=, skip ublue-booted-image-sync.service, which the old || true script never did.

Suggestion: park this until #1220's diagnostics name the real source. If the boot unit turns out not to be involved, this PR isn't needed. That's Doug's call as maintainer.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

The hive adopted this PR (stage/074-adopted-by-hive) but its head 85d5615bf5ca has not moved for 18h7m and the hive has nothing it can push: adoption-stalled:human-changes-requested.

Blocker: lane reason contributor-lane:changes-requested on this head and nothing changed.

Moving to stage/085-needs-decision so a person sees it. This is not a merge-approval wait: the lane has not admitted this head.

@hanthor

hanthor commented Nov 16, 2026

Copy link
Copy Markdown
Member

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

Thanks, @kylerankin. This PR's two-unit split, and the truncate-on-reopen analysis behind it, was the right way to run bootc as a bare ExecStart. The review-VM evidence showed that this doesn't change bootc's domain, though: run 43600763520 still logged both mac_admin denials. The boot-time source turned out to be common's CountMe (#1247).

#1279 handles #1198 at the policy level instead: a build-time module, dontaudit unconfined_service_t self:capability2 mac_admin, checked with semodule -l by the desktop contract. It covers any plain service that runs bootc.

@hanthor hanthor closed this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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/085-needs-decision A human decision is owed: sentinel alert, hold/needs-decision label, human-only rule or parked issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

selinux: ublue-booted-image runs bootc status from a script, so bootc's capability probe logs two chcon AVC denials every boot

3 participants