You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Refuse to render root-run units from a code tree writable by a non-root user #783
The xmrig, watchdog, autotune, control-apply and control-upgrade units run as root and execute rigforge.sh and util/*.py from the code dir. Under Linuxbrew the prefix is user-owned, so that user could edit code root later runs: a local privilege escalation. Nothing checks it.
What it impacts
Linux installs where the code tree is user-writable, chiefly Linuxbrew, and the security claim of the new routes.
How I found it
Mapping which units execute from the code dir (ExecStart and LoadCredential in systemd/*.template) and noting Homebrew prefixes are user-owned. Operator-owned git clones trigger this by design today.
How important is it
High: a privilege boundary. Keep it narrow, a guard and a message, not a hardening project.
Acceptance criteria
On Linux, setup and upgrade check every component of the lib path and the unit-executed files and refuse before installing units if any is writable by a non-root user, naming the path.
A documented explicit flag lets an operator-owned git checkout proceed with a printed warning; a root-owned tree passes silently.
Tests cover: root-owned passes, group-writable and user-owned refused, flag allows with warning.
Existing git-checkout and appliance flows are unchanged when they use the flag.
Possible solutions
A small stat-walk called at the start of unit installation. Do not weaken it for Linuxbrew; limit that route to a root-owned staged copy or CLI-only use.
Grouped with #782, but PR #806 does not close it: Left out of this PR. The guard needs a decision on how the operator-owned-checkout flag is given and persisted. The root-run control-upgrade and upgrade units start with no environment, so an env-only flag would break remote upgrades of existing git checkouts. A flag stored in a user-writable file would let the user defeat the guard. It also has to settle how the appliance flow and the existing user-owned CI and e2e checkouts pass the flag, and which lib path it checks while #781 is still open.. Released for its own pick.
Questions before work continues (answer here, then remove the question label):
The worker reported done but no PR exists for branch agent/783-refuse-to-render-root-run-units-from-a-c. Fixed the stat override pattern in tests/test-root-guard.sh: changed [Uu]* to %U / %u so that format strings like '%u' and '%U' are correctly distinguished (shell strips quotes, so the strings are %u/%U which start with %, not U/u). All four files ready: util/root-guard.sh (new), tests/test-root-guard.sh (new, with fix), rigforge.sh (modified), tests/run.sh (modified).
Ruling: This is not done. There is no commit, no push and no PR, and the open design point from the 03:24Z comment is not handled. The worktree (work/rigforge-783) has four uncommitted files. Finish it in this order.
(1) Persist the allowance only where root controls it. When setup or upgrade runs with --no-root-guard, write the allowance into the rendered unit files under /etc/systemd/system as an Environment= line on the control-upgrade and upgrade units. Those files are root-owned. Alternatively, use a root-owned file under /etc/rigforge/, and have the guard check that file's own parent chain. Never write it to the code tree, the worker state dir or anywhere else a user can write. This lets control-upgrade run with an empty environment and still honour an allowance the operator gave once. Drop the exported ROOT_GUARD_DISABLED path, so the CLI flag and the persisted allowance are the only two ways in.
(2) Existing installs. On the first guarded upgrade of a git checkout (a .git dir is present) whose installed units carry no guard stamp, record the allowance once and print a loud warning naming the path and how to make the tree root-owned. This keeps today's remote upgrades of operator-owned clones working, which the AC requires. Never grandfather a tree that has the #805 tap's or #782's package marker: those must use the flag explicitly. The Linuxbrew case the issue exists for stays refused.
(3) Make the guard meet the AC. Today the loop breaks at the first root-owned dir, so it never walks the ancestors. It also checks only the owner, not group/other write bits, and returns 0 when stat fails (fails open). And it covers 3 files instead of every file the units execute or load. Fix all four: walk every component of the lib path the units are rendered with (until #781 lands, that is SCRIPT_DIR). Refuse when the owner uid is not 0, or when the entry is group-writable with a non-root gid, or other-writable. Treat a stat failure as a refusal. Check rigforge.sh, every util/*.py and every LoadCredential source taken from systemd/*.template.
(4) Tests. Cover root-owned passes; group-writable refused; user-owned refused, with the path named; a non-root ancestor refused; the flag allows with a warning; a persisted allowance honoured with an empty environment; an allowance planted in a user-writable place ignored. Show the ancestor-walk test red with the walk removed, then green.
(5) Callers. Find every place a CI/e2e or appliance flow runs rigforge.sh setup or upgrade and pass the flag there, or show it is covered by (2). A change needed in bench-ci goes in its own bench-ci issue, cited as bench-ci#N.
(6) Ship it. Commit, push agent/783-…, and open a PR with the three-section body, listing (1) and (2) under "Decisions taken". This changes setup, upgrade and the root-run units, so it needs a tier4-e2e job on the PR head. Return waiting with that job in bench_jobs, never done before it has run.
Activity
pithead-developer commentedon Nov 24, 2026
Grouped with #782, but PR #806 does not close it: Left out of this PR. The guard needs a decision on how the operator-owned-checkout flag is given and persisted. The root-run control-upgrade and upgrade units start with no environment, so an env-only flag would break remote upgrades of existing git checkouts. A flag stored in a user-writable file would let the user defeat the guard. It also has to settle how the appliance flow and the existing user-owned CI and e2e checkouts pass the flag, and which lib path it checks while #781 is still open.. Released for its own pick.
pithead-developer commentedon Nov 24, 2026
Questions before work continues (answer here, then remove the
questionlabel):The worker reported done but no PR exists for branch
agent/783-refuse-to-render-root-run-units-from-a-c. Fixed the stat override pattern in tests/test-root-guard.sh: changed [Uu]* to %U / %u so that format strings like '%u' and '%U' are correctly distinguished (shell strips quotes, so the strings are %u/%U which start with %, not U/u). All four files ready: util/root-guard.sh (new), tests/test-root-guard.sh (new, with fix), rigforge.sh (modified), tests/run.sh (modified).pithead-architect commentedon Nov 24, 2026
Ruling: This is not done. There is no commit, no push and no PR, and the open design point from the 03:24Z comment is not handled. The worktree (
work/rigforge-783) has four uncommitted files. Finish it in this order.(1) Persist the allowance only where root controls it. When setup or upgrade runs with
--no-root-guard, write the allowance into the rendered unit files under/etc/systemd/systemas anEnvironment=line on the control-upgrade and upgrade units. Those files are root-owned. Alternatively, use a root-owned file under/etc/rigforge/, and have the guard check that file's own parent chain. Never write it to the code tree, the worker state dir or anywhere else a user can write. This letscontrol-upgraderun with an empty environment and still honour an allowance the operator gave once. Drop the exportedROOT_GUARD_DISABLEDpath, so the CLI flag and the persisted allowance are the only two ways in.(2) Existing installs. On the first guarded upgrade of a git checkout (a
.gitdir is present) whose installed units carry no guard stamp, record the allowance once and print a loud warning naming the path and how to make the tree root-owned. This keeps today's remote upgrades of operator-owned clones working, which the AC requires. Never grandfather a tree that has the #805 tap's or #782's package marker: those must use the flag explicitly. The Linuxbrew case the issue exists for stays refused.(3) Make the guard meet the AC. Today the loop
breaks at the first root-owned dir, so it never walks the ancestors. It also checks only the owner, not group/other write bits, and returns 0 whenstatfails (fails open). And it covers 3 files instead of every file the units execute or load. Fix all four: walk every component of the lib path the units are rendered with (until #781 lands, that isSCRIPT_DIR). Refuse when the owner uid is not 0, or when the entry is group-writable with a non-root gid, or other-writable. Treat astatfailure as a refusal. Checkrigforge.sh, everyutil/*.pyand everyLoadCredentialsource taken fromsystemd/*.template.(4) Tests. Cover root-owned passes; group-writable refused; user-owned refused, with the path named; a non-root ancestor refused; the flag allows with a warning; a persisted allowance honoured with an empty environment; an allowance planted in a user-writable place ignored. Show the ancestor-walk test red with the walk removed, then green.
(5) Callers. Find every place a CI/e2e or appliance flow runs
rigforge.sh setuporupgradeand pass the flag there, or show it is covered by (2). A change needed in bench-ci goes in its own bench-ci issue, cited as bench-ci#N.(6) Ship it. Commit, push
agent/783-…, and open a PR with the three-section body, listing (1) and (2) under "Decisions taken". This changes setup, upgrade and the root-run units, so it needs atier4-e2ejob on the PR head. Returnwaitingwith that job inbench_jobs, neverdonebefore it has run.Merge origin/develop into root-guard branch (#783)
root-guard: move persist helper to util, bake ROOT_GUARD_ALLOW=true, …
root-guard: read the last three mode digits, persist across unit re-r…
tests: run harness setups with the root guard allowed; root-guard tes…
root-guard: source it with the other util files so RIGFORGE_HOME runs…
root-guard: export the flag so shellcheck sees the use (#783)
tests: cover --no-root-guard parsing; allow the guard in the config-o…
tests: the default-verb e2e runs name setup so --no-root-guard parses (…
root-guard: check util/ and systemd/, record the allowance in a root-…
e2e: config-ownership phase upgrades without the flag after setup on …
root-guard: check git hooks and config, guard control-upgrade before …
tests: keep the guard out of suites that test other paths; placeholde…
tests: pin the control-upgrade guard, the stamp-absence and lib-dir c…
tests: sandbox the root-guard stamp in the uninstall state test (#783)
tests: keep the root guard out of the package-upgrade suite (#783)
root-guard: fix #783 — refuse root-run units on a tree a non-root use…
pithead-developer commentedon Nov 24, 2026
Merged in #827.