Repository navigation
fix(service): run the Linux system unit in the installer's SELinux context - #17151
Conversation
Design Review (Opus 5.5) — ✅ human override accepted@iamwhatever overrode this lane for |
First Principles Review (Opus 5.5) — ✅ human override accepted@iamwhatever overrode this lane for |
GPT 6.1 Review — ✅ human override acceptedHuman judgment by @iamwhatever overrides the GPT 6.1 finding for [GPT-OVERRIDE] a7de433 This comment is updated in place on each push. The model was not re-run because an authorized human decision supersedes it. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ human override acceptedReviewed Human judgment by @iamwhatever overrides the Opus 5.5 finding for [OPUS-OVERRIDE] a7de433 Verdict recorded from an authorized human decision for commit False positive or not applicable? A repository writer can comment: |
|
|
|
da4e84b to
15ba083
Compare
|
|
|
This is #17117 (a transient Windows sharing violation on the post-hook identity re-read). The fix is open as #17130. This PR waits for it, then rebases onto it; no override is being asked for this red. |
15ba083 to
81bd945
Compare
|
|
|
81bd945 to
c3b4a49
Compare
c3b4a49 to
c9f3476
Compare
c9f3476 to
4cc9b3d
Compare
|
4cc9b3d to
a7de433
Compare
|
/ai-review override all a7de433: Maintainer accepts the policy-gated SELinuxContext= line without an enforcing-host start; the line is emitted only when a libselinux policy query allows the transition and the entrypoint, and on no/unknown the unit renders exactly as today, so the start-failure mode the reviewers describe is not reachable. |
Human judgment recorded@iamwhatever marked the all AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
UX Review (Opus 5.5) — ✅ human override accepted@iamwhatever overrode this lane for |
Problem / Motivation
Goal: On an SELinux host, files the Linux system service writes under the user's home carry the user's own SELinux user, so the user's shell can keep using those caches.
The system unit runs the gateway as
User=<you>but in a system SELinux domain, so its SELinux user issystem_u. Every cache it or its agents create under$HOME(~/.npm/_cacache,~/.gradle,~/.cache/pip) is labelledsystem_u, and the user'sunconfined_ushell is then refused hardlinks inside it: npm fails withEPERM/syscall linkand calls it "root-owned files".Why it matters
Any RHEL/Fedora/AL2023 user who installs the service gets their npm, Brazil, Gradle or pip caches broken by the agent's builds, with a misleading error, and wiping the cache does not stick while the agent keeps building.
Not a goal
staff_u,user_u): local policy may refuse PID 1 the switch into their context; the unit then fails to start and the existing start-failure hint points at the per-user unit.system_u; the install guide says how.$HOME: the existing pre-flight refusal still handles them.What changed (motivation → approach → change)
SELinuxContext=line (unchanged)SELinuxContext=<installer context>system_uA new file takes its SELinux user from the process that creates it, so the fix is to start the gateway in the user's own context.
installer_context()insrc/kiro_crew/service/selinux.pyreads the installing process's context from/proc/self/attr/current(the user's login context, kept throughsudo). Before handing it out it asks the loaded policy, through the same/sys/fs/selinux/accessquery the existing pre-flight uses, whether PID 1 mayprocess transitioninto it and whether it hasfile entrypointon the binary and its shebang interpreter (the same file list the pre-flight checks,_exec_candidates). Any no or unanswered question leaves the line out, so a unit that starts today keeps starting.render_unit()insrc/kiro_crew/service/linux.pywrites the context into the system unit asSELinuxContext=. The install guide (docs/guides/install.md) explains the line, when it is left out, and how to clean an already-poisoned cache.Scope this reaches, from this AL2023 host's targeted policy: a kirocrew labelled
bin_t/usr_t(e.g./usr/local/bin) gets the line; one labelledhome_bin_t(~/.local/bin) orinitrc_exec_tdoes not, becauseunconfined_thas no entrypoint there, and keeps today's behaviour.Backwards compatibility
Compatible: the line is written only when the loaded policy says the unit can start with it; everywhere else the unit renders byte-for-byte as before, and an existing install keeps its old unit until
kirocrew service installis re-run.Removes nothing: no directive, key or path is taken away.
Tests
test/test_service_selinux_context.pypoints the module at a tmp selinuxfs, a fake/proc/self/attr/currentand a fake policy answer (_compute_av, the one kernel call), so the result never depends on the CI host. It pins: policy allows → the context (enforcing and permissive);process transitiondenied,file entrypointdenied on the binary or on its interpreter, an unanswered query, and a missing/sys/fs/selinux/accessnode (the real query path) → no context; one INFO line naming why; no SELinux, unreadable,system_uand malformed contexts → none; the rendered system unit carries the line inside[Service]only when allowed, and the user-scope unit never does. A gate that always answers "allowed" fails 7 of them.Manual verification
On this AL2023 host (SELinux permissive, not switched) the real policy was queried through
/sys/fs/selinux/access:init_t -> unconfined_u:unconfined_r:unconfined_tprocess transitionis allowed;unconfined_tfile entrypointis allowed onbin_t,usr_t,user_home_tand denied onhome_bin_t,initrc_exec_t,default_t. Not installed and started on an enforcing host (none available); the policy gate is what keeps that untested path from stopping a unit.Related Issues
Closes #17150
Internal ticket: Mesh-3268
Pattern harvest
Not generalizable: the defect is specific to how a systemd system unit picks the SELinux user for its process; no other code path here launches a long-lived process through PID 1.
Checklist