carlos / platform Public

Named units: an untrusted guard chain means no guard (v0.40.0 fix)

The v0.40.0 dev rehearsal found every named-units install refused on a
fixed box ("console guard marker: permission denied"): /opt/carlos is
owned by carlos there, so rootstate's trusted walk to
<opt>/system/guard/console-ready.json fails before it can see that no
guard exists. Paul's ruling (2026-11-19): if the directory chain to the
marker is not root-trusted, the box cannot hold a guard root honours, so
install (the fetch step and `carlos system named-units install`) treats
it as unguarded and says so; a marker file that is itself untrusted in a
trusted chain still refuses. rootstate gains OpenTrustedDir and
OpenTrustedFileIn, the two halves of OpenTrustedFile; proofnamed.go is
unchanged. Also corrects put's pickup line and cli.md: a config write
starts an earlier pass only for an app that runs as a named unit on the
box, and put checks format and fields while the box checks the guard.

Reviews: Astra R1 READY, no findings; census approved (#280). Copy:
Luna (delegated), one fact correction. Not released (v0.40.1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Prompts:

  <task-notification>
  <task-id>br7mjstik</task-id>
  <tool-use-id>toolu_01GdzMrUGf9iLveYzWQhZKog</tool-use-id>
  <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/95f33cc2-8998-4fa5-abb8-8043c3daeffb/tasks/br7mjstik.output</output-file>
  <status>completed</status>
  <summary>Background command "Run Astra's review of the guard fix" completed (exit code 0)</summary>
  </task-notification>

  <paseo-system version="1" kind="agent-message" source-agent-id="ae1750d9-1e92-442e-9bd5-cb2d16ceacaf" message-id="becaf6ab-3cdd-418a-bc80-86e8275dd046" source-agent-title="Release v0.40.0 (named units; dev, then flagship on Paul&apos;s GO)">
  From the v0.40.0 release session: FLAGSHIP DONE, lock released at 14:11Z (full report on #421). Every flagship box, both US members and the console are on v0.40.0. apt v0.40.0-1 is live.
  - Canary barbara and one stable promote (--spread 30m): 0 rolled back, 0 refused, 0 ERROR.
  - US moves held 3,534 and 3,445 ms; no resume; markers CLEAN, 4 per move. cherry-clover-45-ha: 1,601 checks, 0 non-2xx, slowest 2.3 s. Probe: 14,235 requests, 0 non-2xx, 0 timeouts, 0 missing writes.
  - Re-pin carloku-infrastructure #66 (LT 22, 0/2/0), seeds SSM 21 with wildcard domains unchanged, bootstrap/carlos is S400 fN6w4.7_ (rollback mN6c.0xT = S391).
  - Console restart cost 41 x 502 (v0.39.1: 42). Lease 48 ms, drop-ins identical, 0 ERROR.
  - annie /data for Paul: 14.56 GiB before the ship. The new tree was staged at 14:07:51Z (3.75 GB in 66 s). Lowest seen was 11.77 GiB at 14:08:11Z, with three trees present. The sweep removed v0.39.0-1 at 14:08:22Z, 31 s after the swap, leaving 15.20 GiB. Caveat: my 2-second trace hit the SSM 24 KB output cap at 13:55Z. The 11.77 GiB comes from a spot read between the staging and the sweep, so a lower point during extraction was not measured.
  Rehearsal: step 5&apos;s invalid value (an entry with no addr, parameter version 2) is in place for dennis&apos;s 14:11Z pass. I send the step 5 result and the cleanup (15:11Z pass) as one message when done.
  </paseo-system>

Squashed from named-units-guard-fix into main.
claude agent, operated by paul@keymail.dev a980e15250b888dd8c74a8a649b595f8cd24993a parent 5b4c2f6
18 files changed, +469 −84
  • docs/site/cli.md +7 −5
  • docs/superpowers/notes/census-proposal-named-units-guard-fix.md +26 −0
  • docs/superpowers/reviews/CODEX-FINDINGS-named-units-guard-fix-R1.md +26 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-named-units-guard-fix.md +19 −0
  • docs/superpowers/reviews/LUNA-COPY-RESULT-named-units-guard-fix.md +6 −0
  • docs/superpowers/reviews/named-units-guard-fix-copy-deck.md +8 −0
  • internal/host/namedunitsfetch.go +18 −6
  • internal/host/namedunitsfetch_test.go +1 −1
  • internal/host/unitops.go +75 −31
  • internal/host/unitops_guard_linux_test.go +150 −30
  • internal/host/unitops_test.go +9 −9
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-named-units-guard-fix.tsv +14 −0
  • internal/rootstate/file_linux.go +33 −0
  • internal/rootstate/file_linux_test.go +70 −0
  • internal/rootstate/file_other.go +4 −0
  • system_namedunits.go +1 −1
  • system_namedunits_test.go +1 −1

CI passed — run details

landed from named-units-guard-fix

diff --git a/docs/site/cli.md b/docs/site/cli.md
index de570b33e..cf2f6d58e 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -3351,16 +3351,18 @@ exist, the installed file stays as it is.
`carlos system named-units put` checks a declaration file, then writes
it to the box's parameter with your AWS profile. You need
-`ssm:PutParameter` on that path. You do not need root. A file that would
-fail on the box is refused before anything is written. `--aws-region`
-must be the box's region; without it, your profile's region is used.
+`ssm:PutParameter` on that path. You do not need root. `put` checks
+only the file's format and fields. The box checks the console-guard rule
+separately. `--aws-region` must be the box's region; without it, your
+profile's region is used.
```sh
carlos system named-units put --instance i-0abc1234def567890 --aws-region eu-west-1 named-units.json
```
-The box installs it on its next config pass (any config write to an app
-on that box starts one) or within the hour. To clear a box's units,
+The box installs it on its next config pass, within the hour. A config
+write starts an earlier pass only when the app you write to runs as a
+named unit on that box. To clear a box's units,
put `{"schema":1,"units":[]}`. Deleting the parameter does not clear
them: the box keeps the file it has.
diff --git a/docs/superpowers/notes/census-proposal-named-units-guard-fix.md b/docs/superpowers/notes/census-proposal-named-units-guard-fix.md
new file mode 100644
index 000000000..92db4d093
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-named-units-guard-fix.md
@@ -0,0 +1,26 @@
+# Census approval: named-units-guard-fix
+
+Ruling `census-ruling-named-units-guard-fix`. The independent reviewer approves or rejects every change below, 2 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/host/unitops.go` `RunSystemNamedUnitsInstall` | body | unchanged (1) | InstallNamedUnits now also returns the unguarded reason; the verb prints it beside the installed path. No new read |
+| `internal/host/unitops.go` `consoleGuardHost` | body | unchanged (1) | the guard read now distinguishes an untrusted chain, which is treated as unguarded (Paul's ruling 2026-11-19): it walks <opt>/system/guard first with rootstate.OpenTrustedDir (same root-trusted walk as before); os.ErrPermission from that walk is ok=false, no error, with an unguarded reason; absent is ok=false as before; then it opens console-ready.json in the walked directory with rootstate.OpenTrustedFileIn (same file checks as OpenTrustedFile: no symlink, root-owned, one link, not group/other-writable) and an untrusted, oversized or hostless marker still refuses. No new read: the same marker through the same checks, split in two |
+
+Envelopes re-pinned: `.`, `internal/host`, `internal/rootstate`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/host/unitops.go` `RunSystemNamedUnitsInstall`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-named-units-param-114;basis=new (Task 7, renamed from RunSystemNamedUnits): carlos system named-units install <file>: refuses unless euid 0, reads the operator-given <file> by root's own choice at the command line and hands it to InstallNamedUnits, which now also runs both decoders and the console guard rule under the lock
+- `internal/host/unitops.go` `consoleGuardHost`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-named-units-param-114;basis=new (Task 2/4): root's trusted read (rootstate.OpenTrustedFile, MaxRecord cap) of <opt>/system/guard/console-ready.json, the marker root's guard-arm writes; absent is unguarded, any other failure or a marker naming no valid live host is an error that refuses the install; the host is taken only when the bytes equal release.LiveLink(opt, host)
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `internal/rootstate/file_linux.go:OpenTrustedDir`: reads +file:Open; written legacy, accepted-legacy, frozen
+- new `internal/rootstate/file_linux.go:OpenTrustedFileIn`: reads +file:Fstat; written legacy, accepted-legacy, frozen
+
+Seal: `879cc401365966a2ca23962245ce9dff4b7879fe7a27b7691c3d91a4e70ff6e8` → `aa2c0729fe761d6438d2e8b9ef4ef2c1a20699f5e81dded1783c9a008dfafba9`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-named-units-guard-fix.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-named-units-guard-fix-R1.md b/docs/superpowers/reviews/CODEX-FINDINGS-named-units-guard-fix-R1.md
new file mode 100644
index 000000000..15300a4f1
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-named-units-guard-fix-R1.md
@@ -0,0 +1,26 @@
+Round 1, reviewed `origin/main...933016ff8748007c2678033242ce4e351bfa8ce1`. **No P1, P2 or P3 findings.**
+
+The change follows the ruling:
+
+- Existing `OpenTrustedFile` callers retain their checks. The split uses the same directory traversal and file validation. Directory symlinks and non-directory components return errors that remain refusals.
+- Permission failures from the directory stage become unguarded; permission failures from the marker-file stage still refuse.
+- An agent-owned `/opt/carlos` cannot supply declaration bytes or establish a trusted console binding. The fetch hold still checks hosts in the installed declarations and includes the trusted guard’s host. `proofnamed.go` is unchanged.
+- Installed and unchanged fetch outcomes preserve the unguarded reason in status and journal output. The local install verb prints it after a successful install.
+
+Census verdicts for the reviewed commit:
+
+| Unit or envelope | Verdict and evidence |
+|---|---|
+| `RunSystemNamedUnitsInstall` | **APPROVE** — `internal/host/unitops.go:254–273`: retains the root-only gate and operator-selected input; adds successful-install reporting. |
+| `consoleGuardHost` | **APPROVE** — `internal/host/unitops.go:195–228`: implements the directory/file distinction; retains marker size, host and exact-path checks. |
+| `OpenTrustedDir` — new disposition | **APPROVE**, `legacy / accepted-legacy` — `internal/rootstate/file_linux.go:38–43`, `state_linux.go:24–116`: reuses the existing trusted walk without creating directories. |
+| `OpenTrustedFileIn` — new disposition | **APPROVE**, `legacy / accepted-legacy` — `internal/rootstate/file_linux.go:50–63`, `internal/safefile/file_linux.go:61–104`: opens one name relative to the trusted descriptor and checks type, ownership, links and permissions. Production supplies a root-owned descriptor. |
+| `.` envelope | **APPROVE** — `system_namedunits.go:46`: pickup wording changes; command authority and dispatch remain unchanged. |
+| `internal/host` envelope | **APPROVE** — `unitops.go:58–103,195–273`; `namedunitsfetch.go:137–190,229–245,350–378`: validation, locking, source selection and rollback protection remain intact. |
+| `internal/rootstate` envelope | **APPROVE** — `file_linux.go:12–64`: existing opener unchanged; new helpers preserve its production checks. |
+
+By inspection, the untrusted-chain regression tests would fail under the previous refusing behavior. Trusted-chain tests cover malformed and oversized markers, symlinks, writable files and hard links.
+
+**Verification limit:** targeted tests could not start because the read-only sandbox blocked Go’s module update and build-directory creation. Runtime results and census-test execution are therefore unverified. `git diff --check` passed. No files were edited, reviewers spawned or full suites run.
+
+**READY**
\ No newline at end of file
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-named-units-guard-fix.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-named-units-guard-fix.md
new file mode 100644
index 000000000..106c3a6c7
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-named-units-guard-fix.md
@@ -0,0 +1,19 @@
+# Review brief: branch named-units-guard-fix (code + census), round 1 of 3
+
+Repo carlos/platform, branch `named-units-guard-fix`, commit 933016ff8748007c2678033242ce4e351bfa8ce1. Under review: `git diff origin/main...933016ff8748007c2678033242ce4e351bfa8ce1` (merge base 037f4355), and the census card docs/superpowers/notes/census-proposal-named-units-guard-fix.md.
+
+## Background
+v0.40.0 (main bde64b54) added root installing /etc/carlos/named-units.json from an operator SSM parameter. Its dev rehearsal found that on a fixed box /opt/carlos is owned by carlos:carlos (stat on dev dennis: /opt root 755, /opt/carlos carlos:carlos 755, /opt/carlos/system root 755, no guard/). consoleGuardHost read <opt>/system/guard/console-ready.json through rootstate.OpenTrustedFile, whose walk requires a root-owned chain, so every install was refused ("console guard marker: permission denied").
+
+## Fixed: do not re-argue
+Paul's ruling (2026-11-19), "untrusted dir = no guard": if the directory chain to the marker isn't root-trusted, the box cannot hold a guard root honours, so install treats it as unguarded. A marker FILE that is itself untrusted in a trusted chain still refuses. The guard rule only keeps a declaration consistent with the release path (proofnamed.go). It grants no authority, because the content comes only from the operator. proofnamed.go must be unchanged.
+
+## What to check
+1. Does the split (rootstate.OpenTrustedDir, OpenTrustedFileIn) exactly preserve OpenTrustedFile's checks for every existing caller? Does only a permission failure of the directory walk count as an untrusted chain? Can a symlink, a non-directory component or any other error turn a refusal into "unguarded" in a way the ruling doesn't cover?
+2. Can an agent that owns /opt/carlos use this to make root install something the operator did not write, or to strand the release path's bindings? Remember the fetch step's rollback hold reads the guarded host from the same helper.
+3. Are the fetch step's status record and the install verb's output honest about the unguarded reason?
+4. The tests: do they fail without the fix, and do they cover the trusted-chain refusals?
+5. Census: a verdict per unit and per envelope on the card, as AGENTS.md "The census: the reviewer decides" says.
+
+## Severity and output
+P1 blocks merge; P2 is fixed without another round; P3 goes on a list. Each finding: file:line evidence, failure scenario, fix. Then census verdicts. End with READY, READY AFTER FIXES or NOT READY. Do not edit files, spawn reviewers, or run full suites.
diff --git a/docs/superpowers/reviews/LUNA-COPY-RESULT-named-units-guard-fix.md b/docs/superpowers/reviews/LUNA-COPY-RESULT-named-units-guard-fix.md
new file mode 100644
index 000000000..9b342b12d
--- /dev/null
+++ b/docs/superpowers/reviews/LUNA-COPY-RESULT-named-units-guard-fix.md
@@ -0,0 +1,6 @@
+| id | new text | why |
+|---|---|---|
+| G-1 | console guard not readable here, so treated as unguarded | Plain lower-case reason. |
+| G-2 | The box installs it on its next config pass, within the hour. A config write starts an earlier pass only when this app runs as a named unit on that box. | Matches the hourly pass and unit-backed route. |
+| G-3 | `put` checks only the file's format and fields. The box checks the console-guard rule separately. | Removes the false claim that `put` checks the box's rule before writing. |
+| G-4 | The box installs it on its next config pass, within the hour. A config write starts an earlier pass only when this app runs as a named unit on that box. | Matches the hourly pass and unit-backed route. |
\ No newline at end of file
diff --git a/docs/superpowers/reviews/named-units-guard-fix-copy-deck.md b/docs/superpowers/reviews/named-units-guard-fix-copy-deck.md
new file mode 100644
index 000000000..fd93654a6
--- /dev/null
+++ b/docs/superpowers/reviews/named-units-guard-fix-copy-deck.md
@@ -0,0 +1,8 @@
+Feature: an operator writes a fixed box's named-unit declarations to an AWS SSM parameter; root on the box reads it on its own passes and installs it. Readers: platform operators in a terminal. Facts: root's full pass runs hourly (carlos-adopt.timer); a config write only starts an earlier pass when the write's app runs as a named unit on that box (a unit-backed route). `put` checks the file's format and fields only; the box additionally checks the console-guard rule, if it has an armed console guard. On some boxes the directory holding the guard marker isn't root-only, so root can't trust it, and the box is treated as having no guard.
+
+| id | where | current text |
+|---|---|---|
+| G-1 | reason in `named-units show` and the box journal | console guard not readable here (an ancestor directory is not root-owned), treated as unguarded |
+| G-2 | line printed by `put` after writing | The box installs it on its next config pass (any config write to an app on that box starts one) or within the hour. |
+| G-3 | docs sentence (cli.md, put paragraph) | A file that would fail on the box is refused before anything is written. |
+| G-4 | docs sentence (cli.md, pickup paragraph; keep the rest of the paragraph) | The box installs it on its next config pass (any config write to an app on that box starts one) or within the hour. |
diff --git a/internal/host/namedunitsfetch.go b/internal/host/namedunitsfetch.go
index b5b233e0b..057fda251 100644
--- a/internal/host/namedunitsfetch.go
+++ b/internal/host/namedunitsfetch.go
@@ -69,8 +69,9 @@ type namedUnitsFetch struct {
// inUse is declarationBindingInUse, bound to the box's stores.
inUse func(host string) (bool, error)
// guardHost is consoleGuardHost(release.OptDir()); an error refuses
- // the value (invalid).
- guardHost func() (host string, ok bool, err error)
+ // the value (invalid). unguarded, when set, is the record's Reason for
+ // a value installed or unchanged on a box that can hold no guard.
+ guardHost func() (host string, ok bool, unguarded string, err error)
now func() time.Time
}
@@ -134,10 +135,12 @@ func (f namedUnitsFetch) read(ctx context.Context, region, iid string) ([]byte,
// flock: the box's guard rule (its read under the same lock as the write),
// the current file, the hold, and the write.
func (f namedUnitsFetch) installLocked(st status.NamedUnitsStatus, raw []byte, entries []namedunits.Entry) status.NamedUnitsStatus {
- guarded, armed, err := f.guardHost()
+ guarded, armed, unguarded, err := f.guardHost()
if err != nil {
return f.settle(st, namedUnitsInvalid, fmt.Sprintf("console guard marker: %v", err))
}
+ // Held, failed and invalid outcomes set their own Reason over this.
+ st.Reason = unguarded
if err := checkGuardRule(entries, guarded, armed); err != nil {
return f.settle(st, namedUnitsInvalid, err.Error())
}
@@ -238,7 +241,7 @@ func productionNamedUnitsFetch() namedUnitsFetch {
inUse: func(host string) (bool, error) {
return productionDeclarationBindingInUse(host, time.Now())
},
- guardHost: func() (string, bool, error) { return consoleGuardHost(release.OptDir()) },
+ guardHost: func() (string, bool, string, error) { return consoleGuardHost(release.OptDir()) },
now: time.Now,
}
}
@@ -352,11 +355,11 @@ func namedUnitsLogLine(st status.NamedUnitsStatus) string {
}
return fmt.Sprintf("named-units: unreadable: %s; the installed declarations stand", st.Reason)
case namedUnitsInstalled:
- return fmt.Sprintf("named-units: installed %s version %d from %s (sha256 %s)", appconfig.DefaultNamedUnitsPath, st.Version, st.Parameter, st.Digest)
+ return fmt.Sprintf("named-units: installed %s version %d from %s (sha256 %s)", appconfig.DefaultNamedUnitsPath, st.Version, st.Parameter, st.Digest) + reasonSuffix(st.Reason)
case namedUnitsNotFound:
return fmt.Sprintf("named-units: no parameter %s; the installed declarations stand", st.Parameter)
case namedUnitsUnchanged:
- return fmt.Sprintf("named-units: %s version %d unchanged", st.Parameter, st.Version)
+ return fmt.Sprintf("named-units: %s version %d unchanged", st.Parameter, st.Version) + reasonSuffix(st.Reason)
default:
if st.Parameter != "" {
return fmt.Sprintf("named-units: %s version %d %s: %s", st.Parameter, st.Version, st.Outcome, st.Reason)
@@ -364,3 +367,12 @@ func namedUnitsLogLine(st status.NamedUnitsStatus) string {
return fmt.Sprintf("named-units: %s: %s", st.Outcome, st.Reason)
}
}
+
+// reasonSuffix is an installed or unchanged line's note (the unguarded
+// reason), "" when there is none.
+func reasonSuffix(reason string) string {
+ if reason == "" {
+ return ""
+ }
+ return "; " + reason
+}
diff --git a/internal/host/namedunitsfetch_test.go b/internal/host/namedunitsfetch_test.go
index 4dbcac681..9317e1227 100644
--- a/internal/host/namedunitsfetch_test.go
+++ b/internal/host/namedunitsfetch_test.go
@@ -96,7 +96,7 @@ func (x *fetchFixture) fetch() namedUnitsFetch {
x.asked = append(x.asked, host)
return x.inUse[host], x.inUseErr
},
- guardHost: func() (string, bool, error) { return x.guard, x.guard != "", x.guardErr },
+ guardHost: func() (string, bool, string, error) { return x.guard, x.guard != "", "", x.guardErr },
now: func() time.Time { return fetchClock },
}
}
diff --git a/internal/host/unitops.go b/internal/host/unitops.go
index bdd1c96ce..6ba84fb57 100644
--- a/internal/host/unitops.go
+++ b/internal/host/unitops.go
@@ -52,20 +52,23 @@ func productionUnitOps(envDir string) *appconfig.UnitOps {
// (installNamedUnitsLocked). A pass and an install therefore never
// interleave: the pass's snapshot is the file for the whole pass. envDir
// is where the lock lives (appconfig.DefaultEnvDir in production); dst is
-// the declaration path.
-func InstallNamedUnits(envDir, dst string, raw []byte) error {
+// the declaration path. unguarded is consoleGuardHost's: non-empty when
+// the box's guard could not apply and the install went ahead, so the
+// caller can say why.
+func InstallNamedUnits(envDir, dst string, raw []byte) (unguarded string, err error) {
if err := validateForInstall(raw); err != nil {
- return err
+ return "", err
}
unlock, err := lockConfigSync(envDir + "/.sync")
if err != nil {
- return fmt.Errorf("config-sync lock: %w", err)
+ return "", fmt.Errorf("config-sync lock: %w", err)
}
defer unlock()
- if err := checkInstallGuard(release.OptDir(), raw); err != nil {
- return err
+ unguarded, err = checkInstallGuard(release.OptDir(), raw)
+ if err != nil {
+ return "", err
}
- return installNamedUnitsLocked(dst, raw)
+ return unguarded, installNamedUnitsLocked(dst, raw)
}
// validateForInstall: both readers of the declaration file must accept
@@ -87,16 +90,17 @@ func ValidateNamedUnitsDeclaration(raw []byte) error { return validateForInstall
// checkInstallGuard is the box's console guard rule for an install of raw
// (already validated). The guarded host comes from the marker itself
// (consoleGuardHost), so it is found whether or not any file names it.
-func checkInstallGuard(optDir string, raw []byte) error {
+// unguarded is consoleGuardHost's reason when the box can hold no guard.
+func checkInstallGuard(optDir string, raw []byte) (unguarded string, err error) {
entries, err := namedunits.Decode(raw)
if err != nil {
- return err
+ return "", err
}
- host, guarded, err := consoleGuardHost(optDir)
+ host, guarded, unguarded, err := consoleGuardHost(optDir)
if err != nil {
- return fmt.Errorf("console guard marker: %w", err)
+ return "", fmt.Errorf("console guard marker: %w", err)
}
- return checkGuardRule(entries, host, guarded)
+ return unguarded, checkGuardRule(entries, host, guarded)
}
// installNamedUnitsLocked writes raw to dst atomically: a temp file in the
@@ -151,42 +155,77 @@ func guardNames(marker []byte, optDir, host string) bool {
return string(marker) == release.LiveLink(optDir, host)
}
-// openConsoleGuardMarker is the trusted opener consoleGuardHost reads the
-// marker with; a variable so tests can anchor the trust checks at a
-// directory they own.
-var openConsoleGuardMarker = rootstate.OpenTrustedFile
+// openConsoleGuardDir is the trusted walk consoleGuardHost opens the
+// marker's directory with (rootstate.OpenTrustedDir: every directory from
+// / root-owned, not group- or other-writable, r-x for both); a variable so
+// tests can anchor the walk at a directory they own. The marker itself is
+// opened in it with rootstate.OpenTrustedFileIn.
+var openConsoleGuardDir = rootstate.OpenTrustedDir
+
+// consoleGuardUntrustedChain is consoleGuardHost's unguarded reason for a
+// box whose directory chain to the marker fails the trust walk.
+const consoleGuardUntrustedChain = "console guard not readable here, so treated as unguarded"
// consoleGuardHost is for the install callers only; proofnamed.go keeps its
// own read, its error handling and its binding evidence. A trusted read of
-// the marker: absent is ok=false with no error; any other failure (a
-// symlink, a wrong owner, a group-writable file or directory, a marker
-// over rootstate.MaxRecord) is err, and the caller refuses the install.
+// the marker in two steps, so an untrusted directory chain is told apart
+// from an untrusted marker:
+//
+// - the directory walk to <opt>/system/guard: absent anywhere is
+// ok=false with no error; refused by the trust checks (os.ErrPermission:
+// a directory not root-owned, group- or other-writable, or not r-x for
+// group and others) is ok=false with no error and unguarded set to
+// consoleGuardUntrustedChain (Paul's ruling, 2026-11-19). Such a box
+// can hold no guard root honours: proofnamed.go reads the same chain
+// with the same rules and refuses there too. The guard rule only keeps
+// a declaration consistent with what the release path accepts; it
+// grants no authority, and the declaration's content comes only from
+// the operator's parameter or local file, so a box agent that breaks
+// the chain changes nothing root installs. Any other walk failure is
+// err.
+// - the marker in that trusted directory: absent is ok=false with no
+// error; any other failure (a symlink, a wrong owner, a group-writable
+// file, a second link, a marker over rootstate.MaxRecord) is err, and
+// the caller refuses the install.
+//
// Present, the marker's bytes are the guarded host's LiveLink
// (<opt>/live/<host>), and the host is its base name: only when the marker
// sits in the live directory, the base is a valid host and guardNames
// agrees. A marker that names no valid host is untrusted, so err.
-func consoleGuardHost(optDir string) (host string, ok bool, err error) {
- f, err := openConsoleGuardMarker(consoleReadyMarker(optDir))
+func consoleGuardHost(optDir string) (host string, ok bool, unguarded string, err error) {
+ path := consoleReadyMarker(optDir)
+ dir, err := openConsoleGuardDir(filepath.Dir(path))
if errors.Is(err, os.ErrNotExist) {
- return "", false, nil
+ return "", false, "", nil
+ }
+ if errors.Is(err, os.ErrPermission) {
+ return "", false, consoleGuardUntrustedChain, nil
}
if err != nil {
- return "", false, err
+ return "", false, "", err
+ }
+ defer dir.Close()
+ f, err := rootstate.OpenTrustedFileIn(dir, filepath.Base(path))
+ if errors.Is(err, os.ErrNotExist) {
+ return "", false, "", nil
+ }
+ if err != nil {
+ return "", false, "", err
}
defer f.Close()
marker, err := io.ReadAll(io.LimitReader(f, rootstate.MaxRecord+1))
if err != nil {
- return "", false, err
+ return "", false, "", err
}
if len(marker) > rootstate.MaxRecord {
- return "", false, os.ErrPermission
+ return "", false, "", os.ErrPermission
}
- path := string(marker)
- base := filepath.Base(path)
- if filepath.Dir(path) != filepath.Dir(release.LiveLink(optDir, "x")) || !controlname.ValidHostShape(base) || !guardNames(marker, optDir, base) {
- return "", false, fmt.Errorf("%w: %q names no host under %s", os.ErrPermission, path, filepath.Dir(release.LiveLink(optDir, "x")))
+ named := string(marker)
+ base := filepath.Base(named)
+ if filepath.Dir(named) != filepath.Dir(release.LiveLink(optDir, "x")) || !controlname.ValidHostShape(base) || !guardNames(marker, optDir, base) {
+ return "", false, "", fmt.Errorf("%w: %q names no host under %s", os.ErrPermission, named, filepath.Dir(release.LiveLink(optDir, "x")))
}
- return base, true, nil
+ return base, true, "", nil
}
// checkGuardRule: on a guarded box the guarded host's entry, when the file
@@ -223,9 +262,14 @@ func RunSystemNamedUnitsInstall(args []string) {
if err != nil {
log.Fatalf("carlos system named-units install: %v", err)
}
- if err := InstallNamedUnits(appconfig.DefaultEnvDir, appconfig.DefaultNamedUnitsPath, raw); err != nil {
+ unguarded, err := InstallNamedUnits(appconfig.DefaultEnvDir, appconfig.DefaultNamedUnitsPath, raw)
+ if err != nil {
log.Fatalf("carlos system named-units install: %v", err)
}
+ if unguarded != "" {
+ fmt.Printf("installed %s (%s)\n", appconfig.DefaultNamedUnitsPath, unguarded)
+ return
+ }
fmt.Printf("installed %s\n", appconfig.DefaultNamedUnitsPath)
}
diff --git a/internal/host/unitops_guard_linux_test.go b/internal/host/unitops_guard_linux_test.go
index 07498e27a..83d317701 100644
--- a/internal/host/unitops_guard_linux_test.go
+++ b/internal/host/unitops_guard_linux_test.go
@@ -1,9 +1,11 @@
package host
import (
+ "context"
"errors"
"os"
"path/filepath"
+ "strings"
"testing"
"github.com/carlosframework/platform/internal/release"
@@ -11,9 +13,9 @@ import (
)
// consoleGuardAt points the install path at a fresh opt directory and
-// reads the marker with the trusted opener anchored there, so the real
-// symlink, owner and mode checks run without root. Not parallel: it sets
-// CARLOS_OPT_DIR and the opener variable.
+// walks to the marker's directory with the trusted walk anchored there, so
+// the real symlink, owner and mode checks run without root. Not parallel:
+// it sets CARLOS_OPT_DIR and the walk variable.
func consoleGuardAt(t *testing.T) string {
t.Helper()
opt := t.TempDir()
@@ -23,9 +25,9 @@ func consoleGuardAt(t *testing.T) string {
t.Fatal(err)
}
t.Setenv("CARLOS_OPT_DIR", opt)
- prior := openConsoleGuardMarker
- openConsoleGuardMarker = func(path string) (*os.File, error) { return rootstate.OpenTrustedFileFrom(opt, path) }
- t.Cleanup(func() { openConsoleGuardMarker = prior })
+ prior := openConsoleGuardDir
+ openConsoleGuardDir = func(dir string) (*os.File, error) { return rootstate.OpenTrustedDirFrom(opt, dir) }
+ t.Cleanup(func() { openConsoleGuardDir = prior })
return opt
}
@@ -52,17 +54,17 @@ func writeConsoleGuardMarker(t *testing.T, opt string, body []byte) string {
func TestConsoleGuardHostRefusesUntrustedMarker(t *testing.T) {
t.Run("absent", func(t *testing.T) {
opt := consoleGuardAt(t)
- host, ok, err := consoleGuardHost(opt)
- if err != nil || ok || host != "" {
- t.Fatalf("absent marker: %q %v %v", host, ok, err)
+ host, ok, unguarded, err := consoleGuardHost(opt)
+ if err != nil || ok || host != "" || unguarded != "" {
+ t.Fatalf("absent marker: %q %v %q %v", host, ok, unguarded, err)
}
})
t.Run("names a host", func(t *testing.T) {
opt := consoleGuardAt(t)
writeConsoleGuardMarker(t, opt, []byte(release.LiveLink(opt, "b.example.com")))
- host, ok, err := consoleGuardHost(opt)
- if err != nil || !ok || host != "b.example.com" {
- t.Fatalf("matching marker: %q %v %v", host, ok, err)
+ host, ok, unguarded, err := consoleGuardHost(opt)
+ if err != nil || !ok || host != "b.example.com" || unguarded != "" {
+ t.Fatalf("matching marker: %q %v %q %v", host, ok, unguarded, err)
}
})
// A marker that names no valid host under <opt>/live is untrusted: the
@@ -76,9 +78,9 @@ func TestConsoleGuardHostRefusesUntrustedMarker(t *testing.T) {
t.Run(name, func(t *testing.T) {
opt := consoleGuardAt(t)
writeConsoleGuardMarker(t, opt, []byte(body(opt)))
- host, ok, err := consoleGuardHost(opt)
- if err == nil || errors.Is(err, os.ErrNotExist) {
- t.Fatalf("marker %q read as %q ok=%v err=%v; want a refusing error", body(opt), host, ok, err)
+ host, ok, unguarded, err := consoleGuardHost(opt)
+ if err == nil || errors.Is(err, os.ErrNotExist) || unguarded != "" {
+ t.Fatalf("marker %q read as %q ok=%v unguarded=%q err=%v; want a refusing error", body(opt), host, ok, unguarded, err)
}
})
}
@@ -87,12 +89,14 @@ func TestConsoleGuardHostRefusesUntrustedMarker(t *testing.T) {
body := []byte(release.LiveLink(opt, "b.example.com"))
body = append(body, make([]byte, rootstate.MaxRecord)...)
writeConsoleGuardMarker(t, opt, body)
- host, ok, err := consoleGuardHost(opt)
- if err == nil || errors.Is(err, os.ErrNotExist) {
- t.Fatalf("an oversized marker read as %q ok=%v err=%v; want a refusing error", host, ok, err)
+ host, ok, unguarded, err := consoleGuardHost(opt)
+ if err == nil || errors.Is(err, os.ErrNotExist) || unguarded != "" {
+ t.Fatalf("an oversized marker read as %q ok=%v unguarded=%q err=%v; want a refusing error", host, ok, unguarded, err)
}
})
- for _, attack := range []string{"symlink", "group-writable", "hard link", "group-writable directory"} {
+ // A group-writable guard directory is part of the chain: see
+ // TestConsoleGuardHostUntrustedChainIsUnguarded.
+ for _, attack := range []string{"symlink", "group-writable", "hard link"} {
t.Run(attack, func(t *testing.T) {
opt := consoleGuardAt(t)
body := []byte(release.LiveLink(opt, "a.example.com"))
@@ -117,14 +121,10 @@ func TestConsoleGuardHostRefusesUntrustedMarker(t *testing.T) {
if err := os.Link(marker, filepath.Join(opt, "second-name")); err != nil {
t.Fatal(err)
}
- case "group-writable directory":
- if err := os.Chmod(filepath.Dir(marker), 0o775); err != nil {
- t.Fatal(err)
- }
}
- host, ok, err := consoleGuardHost(opt)
- if err == nil || errors.Is(err, os.ErrNotExist) {
- t.Fatalf("an untrusted marker read as %q ok=%v err=%v; want a refusing error", host, ok, err)
+ host, ok, unguarded, err := consoleGuardHost(opt)
+ if err == nil || errors.Is(err, os.ErrNotExist) || unguarded != "" {
+ t.Fatalf("an untrusted marker read as %q ok=%v unguarded=%q err=%v; want a refusing error", host, ok, unguarded, err)
}
})
}
@@ -148,7 +148,7 @@ func TestInstallNamedUnitsKeepsTheConsoleGuard(t *testing.T) {
}
refused := func(t *testing.T, dir, dst string, raw []byte) {
t.Helper()
- if err := InstallNamedUnits(dir, dst, raw); err == nil {
+ if _, err := InstallNamedUnits(dir, dst, raw); err == nil {
t.Fatal("install succeeded")
}
if _, err := os.Stat(dst); !os.IsNotExist(err) {
@@ -166,7 +166,7 @@ func TestInstallNamedUnitsKeepsTheConsoleGuard(t *testing.T) {
writeConsoleGuardMarker(t, opt, []byte(release.LiveLink(opt, "a.example.com")))
dir := t.TempDir()
dst := filepath.Join(dir, "named-units.json")
- if err := InstallNamedUnits(dir, dst, file(consoleA, shopB)); err != nil {
+ if _, err := InstallNamedUnits(dir, dst, file(consoleA, shopB)); err != nil {
t.Fatal(err)
}
})
@@ -178,7 +178,7 @@ func TestInstallNamedUnitsKeepsTheConsoleGuard(t *testing.T) {
if err := os.WriteFile(dst, file(consoleA), 0o644); err != nil {
t.Fatal(err)
}
- if err := InstallNamedUnits(dir, dst, file(shopB)); err != nil {
+ if _, err := InstallNamedUnits(dir, dst, file(shopB)); err != nil {
t.Fatal(err)
}
})
@@ -187,7 +187,7 @@ func TestInstallNamedUnitsKeepsTheConsoleGuard(t *testing.T) {
writeConsoleGuardMarker(t, opt, []byte(release.LiveLink(opt, "c.example.com")))
dir := t.TempDir()
dst := filepath.Join(dir, "named-units.json")
- if err := InstallNamedUnits(dir, dst, file(shopB)); err != nil {
+ if _, err := InstallNamedUnits(dir, dst, file(shopB)); err != nil {
t.Fatal(err)
}
})
@@ -207,3 +207,123 @@ func TestInstallNamedUnitsKeepsTheConsoleGuard(t *testing.T) {
refused(t, dir, filepath.Join(dir, "named-units.json"), file(consoleA, shopB))
})
}
+
+// breakGuardChain makes one directory on the walk to the marker fail the
+// trust checks the way a box agent's /opt/carlos does in production (a
+// test can't chown, so a group-writable or others-unreadable mode stands
+// in for the wrong owner: the walk refuses all three alike).
+func breakGuardChain(t *testing.T, opt, where string) {
+ t.Helper()
+ dir, mode := opt, os.FileMode(0o775)
+ switch where {
+ case "opt group-writable":
+ case "system group-writable":
+ dir = filepath.Join(opt, "system")
+ case "system unreadable by others":
+ dir, mode = filepath.Join(opt, "system"), 0o750
+ case "guard group-writable":
+ dir = filepath.Join(opt, "system", "guard")
+ default:
+ t.Fatalf("unknown chain break %q", where)
+ }
+ if err := os.MkdirAll(dir, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Chmod(dir, mode); err != nil {
+ t.Fatal(err)
+ }
+}
+
+var guardChainBreaks = []string{"opt group-writable", "system group-writable", "system unreadable by others", "guard group-writable"}
+
+// Paul's ruling of 2026-11-19: a box whose directory chain to the marker
+// is not root-trusted can't hold a guard root honours (the release path
+// reads the same chain with the same rules), so the install treats it as
+// unguarded rather than refusing every declaration.
+func TestConsoleGuardHostUntrustedChainIsUnguarded(t *testing.T) {
+ for _, where := range guardChainBreaks {
+ for _, marker := range []bool{false, true} {
+ name := where + ", no marker"
+ if marker {
+ name = where + ", marker present"
+ }
+ t.Run(name, func(t *testing.T) {
+ opt := consoleGuardAt(t)
+ if marker {
+ writeConsoleGuardMarker(t, opt, []byte(release.LiveLink(opt, "a.example.com")))
+ }
+ breakGuardChain(t, opt, where)
+ host, ok, unguarded, err := consoleGuardHost(opt)
+ if err != nil || ok || host != "" || unguarded != consoleGuardUntrustedChain {
+ t.Fatalf("untrusted chain: %q ok=%v unguarded=%q err=%v; want unguarded", host, ok, unguarded, err)
+ }
+ })
+ }
+ }
+ t.Run("trusted chain, no marker", func(t *testing.T) {
+ opt := consoleGuardAt(t)
+ if err := os.MkdirAll(filepath.Join(opt, "system", "guard"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ for _, p := range []string{filepath.Join(opt, "system"), filepath.Join(opt, "system", "guard")} {
+ if err := os.Chmod(p, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ }
+ host, ok, unguarded, err := consoleGuardHost(opt)
+ if err != nil || ok || host != "" || unguarded != "" {
+ t.Fatalf("absent marker in a trusted guard dir: %q ok=%v unguarded=%q err=%v", host, ok, unguarded, err)
+ }
+ })
+}
+
+// On a box whose chain is untrusted the install goes ahead: the empty
+// declaration dennis refused on 2026-11-19, and even a file the marker
+// would refuse, since nothing on that box can honour the marker.
+func TestInstallNamedUnitsUntrustedGuardChain(t *testing.T) {
+ for _, raw := range []string{
+ `{"schema":1,"units":[]}`,
+ `{"schema":1,"units":[{"host":"a.example.com","app":"shop","unit":"shop.service","addr":"127.0.0.1:1","health":{"path":"/"}}]}`,
+ } {
+ t.Run(raw, func(t *testing.T) {
+ opt := consoleGuardAt(t)
+ writeConsoleGuardMarker(t, opt, []byte(release.LiveLink(opt, "a.example.com")))
+ breakGuardChain(t, opt, "opt group-writable")
+ dir := t.TempDir()
+ dst := filepath.Join(dir, "named-units.json")
+ unguarded, err := InstallNamedUnits(dir, dst, []byte(raw))
+ if err != nil {
+ t.Fatalf("install on an untrusted chain: %v", err)
+ }
+ if unguarded != consoleGuardUntrustedChain {
+ t.Fatalf("unguarded = %q, want the untrusted-chain reason", unguarded)
+ }
+ if got, err := os.ReadFile(dst); err != nil || string(got) != raw {
+ t.Fatalf("installed = %q, %v", got, err)
+ }
+ })
+ }
+}
+
+// The fetch step with the production guard read on an untrusted chain:
+// the empty declaration installs, and the record says why the guard was
+// not applied.
+func TestNamedUnitsFetchUntrustedGuardChainInstalls(t *testing.T) {
+ opt := consoleGuardAt(t)
+ breakGuardChain(t, opt, "system group-writable")
+ x := newFetchFixture(t)
+ x.store.raw = declFile()
+ f := x.fetch()
+ f.guardHost = func() (string, bool, string, error) { return consoleGuardHost(opt) }
+ st := f.run(context.Background())
+ wantOutcome(t, st, "installed")
+ if st.Reason != consoleGuardUntrustedChain {
+ t.Fatalf("Reason = %q, want the untrusted-chain reason", st.Reason)
+ }
+ if line := namedUnitsLogLine(st); !strings.Contains(line, consoleGuardUntrustedChain) {
+ t.Fatalf("journal line %q does not say why the guard was not applied", line)
+ }
+ if got, err := os.ReadFile(x.dst); err != nil || string(got) != string(declFile()) {
+ t.Fatalf("file = %q, %v", got, err)
+ }
+}
diff --git a/internal/host/unitops_test.go b/internal/host/unitops_test.go
index c38c61a75..01439ed8b 100644
--- a/internal/host/unitops_test.go
+++ b/internal/host/unitops_test.go
@@ -80,7 +80,7 @@ func TestInstallNamedUnitsWaitsForTheConfigSyncLock(t *testing.T) {
dir := t.TempDir()
dst := filepath.Join(dir, "named-units.json")
body := []byte(`{"schema":1,"units":[{"host":"relay.example.com","account":"bab","app":"relay","unit":"relay.service","addr":"127.0.0.1:8451","health":{"path":"/ready"}}]}`)
- if err := InstallNamedUnits(dir, dst, []byte(`{"schema":1,"units":[]}garbage`)); err == nil {
+ if _, err := InstallNamedUnits(dir, dst, []byte(`{"schema":1,"units":[]}garbage`)); err == nil {
t.Fatal("an invalid file was installed")
}
if err := appconfig.ValidateDeclarations(body); err != nil {
@@ -91,7 +91,7 @@ func TestInstallNamedUnitsWaitsForTheConfigSyncLock(t *testing.T) {
t.Fatal(err)
}
done := make(chan error, 1)
- go func() { done <- InstallNamedUnits(dir, dst, body) }()
+ go func() { _, err := InstallNamedUnits(dir, dst, body); done <- err }()
select {
case err := <-done:
t.Fatalf("install finished while the pass held the lock: %v", err)
@@ -133,7 +133,7 @@ func TestInstallNamedUnitsRefusesWhatTheReleasePathRefuses(t *testing.T) {
noConsoleGuard(t)
dir := t.TempDir()
dst := filepath.Join(dir, "named-units.json")
- if err := InstallNamedUnits(dir, dst, []byte(body)); err == nil {
+ if _, err := InstallNamedUnits(dir, dst, []byte(body)); err == nil {
t.Fatal("installed a file the release path refuses")
}
if _, err := os.Stat(dst); !os.IsNotExist(err) {
@@ -143,14 +143,14 @@ func TestInstallNamedUnitsRefusesWhatTheReleasePathRefuses(t *testing.T) {
}
}
-// noConsoleGuard makes the box's console-guard marker absent for one test,
-// so an install never reads the machine's real /opt/carlos. The opener is
-// a package variable: tests using it must not run in parallel.
+// noConsoleGuard makes the box's console-guard directory absent for one
+// test, so an install never reads the machine's real /opt/carlos. The
+// walk is a package variable: tests using it must not run in parallel.
func noConsoleGuard(t *testing.T) {
t.Helper()
- prior := openConsoleGuardMarker
- openConsoleGuardMarker = func(string) (*os.File, error) { return nil, os.ErrNotExist }
- t.Cleanup(func() { openConsoleGuardMarker = prior })
+ prior := openConsoleGuardDir
+ openConsoleGuardDir = func(string) (*os.File, error) { return nil, os.ErrNotExist }
+ t.Cleanup(func() { openConsoleGuardDir = prior })
}
func TestCheckGuardRuleRefusesNonConsoleForGuardedHost(t *testing.T) {
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 8c754d8f7..87f1ac29c 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -256,3 +256,4 @@ plan14-root-reads-flake-lease-teardown.tsv 5d4a5eea79394145fdd59aa5eb87115cc1ee3
plan14-root-reads-ha-generations.tsv 5bf2d00767807be812b004a474352ec184788be3ce65607a45c37b04956714a2
plan14-root-reads-named-units-param-114.tsv 8daea28ba9b419e8680e8eb0d44a577c68ec01e02663a878288441dc579cc9f7
plan14-root-reads-race-activator-1249.tsv 879cc401365966a2ca23962245ce9dff4b7879fe7a27b7691c3d91a4e70ff6e8
+plan14-root-reads-named-units-guard-fix.tsv aa2c0729fe761d6438d2e8b9ef4ef2c1a20699f5e81dded1783c9a008dfafba9
diff --git a/internal/provision/testdata/plan14-root-reads-named-units-guard-fix.tsv b/internal/provision/testdata/plan14-root-reads-named-units-guard-fix.tsv
new file mode 100644
index 000000000..6992f2c09
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-named-units-guard-fix.tsv
@@ -0,0 +1,14 @@
+# Census overlay named-units-guard-fix, written by census-propose (#369). census-ruling-named-units-guard-fix, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-named-units-guard-fix.md.
+# 2 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 2 new dispositions: 0 reads re-frozen at their disposition with the claim, 2 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
+@legacy 460768a56c895733c6e75efa36f0f9c80d8edd8cd7eea6a79cd99560312e44f0 internal/host/unitops.go RunSystemNamedUnitsInstall legacy accepted-legacy accepted-legacy;rev3=census-ruling-named-units-param-114;basis=new (Task 7, renamed from RunSystemNamedUnits): carlos system named-units install <file>: refuses unless euid 0, reads the operator-given <file> by root's own choice at the command line and hands it to InstallNamedUnits, which now also runs both decoders and the console guard rule under the lock;rev3=census-ruling-named-units-guard-fix;basis=InstallNamedUnits now also returns the unguarded reason; the verb prints it beside the installed path. No new read file:ReadFile@278 03ab2984b8866a2a590a9867cf8b04fd1af853e1286b654c5f992ac46afa1c10
+@legacy 52bd09a6e1493f6816db6ca3ff4875fa7912f0f853df4253b0ae95daf70d19c6 internal/host/unitops.go consoleGuardHost legacy accepted-legacy accepted-legacy;rev3=census-ruling-named-units-param-114;basis=new (Task 2/4): root's trusted read (rootstate.OpenTrustedFile, MaxRecord cap) of <opt>/system/guard/console-ready.json, the marker root's guard-arm writes; absent is unguarded, any other failure or a marker naming no valid live host is an error that refuses the install; the host is taken only when the bytes equal release.LiveLink(opt, host);rev3=census-ruling-named-units-guard-fix;basis=the guard read now distinguishes an untrusted chain, which is treated as unguarded (Paul's ruling 2026-11-19): it walks <opt>/system/guard first with rootstate.OpenTrustedDir (same root-trusted walk as before); os.ErrPermission from that walk is ok=false, no error, with an unguarded reason; absent is ok=false as before; then it opens console-ready.json in the walked directory with rootstate.OpenTrustedFileIn (same file checks as OpenTrustedFile: no symlink, root-owned, one link, not group/other-writable) and an untrusted, oversized or hostless marker still refuses. No new read: the same marker through the same checks, split in two file:ReadAll@623 e7372aa14ec47f8b6deb88f20c8a8d15cccab06c7d6b0db7589ac85b6dfc23e6
+@legacy bb1e7584c8e088b68f36d4c71c40734308624b42a3928d09a9b65a262bfc4bb2 internal/rootstate/file_linux.go OpenTrustedDir legacy accepted-legacy accepted-legacy;rev3=census-ruling-named-units-guard-fix;basis=new: the directory half of OpenTrustedFile, the same trusted walk (root-owned, not group/other-writable, r-x for group and others) from / to dir, returning the directory descriptor; no other read file:Open@64 de0f8222d4721aa93a5588b7cdb9953700c970a9c467d74ad6bc0fb72b378d33
+@legacy 34eeabb86db74ab9a38a9c8680fd72e475d3436d2a20de032cb05cd98881e829 internal/rootstate/file_linux.go OpenTrustedFileIn legacy accepted-legacy accepted-legacy;rev3=census-ruling-named-units-guard-fix;basis=new: the file half of OpenTrustedFile: opens a name inside a trusted directory descriptor with O_NOFOLLOW and requires a root-owned regular file, one link, not group/other-writable; no other read file:Fstat@101 988166d41e2f4702db8df21a2c56dad5b8d7fd0e34dc9ee0a76f5a501a22a842
+internal/host/unitops.go RunSystemNamedUnitsInstall legacy accepted-legacy accepted-legacy;rev3=census-ruling-named-units-param-114;basis=new (Task 7, renamed from RunSystemNamedUnits): carlos system named-units install <file>: refuses unless euid 0, reads the operator-given <file> by root's own choice at the command line and hands it to InstallNamedUnits, which now also runs both decoders and the console guard rule under the lock;rev3=census-ruling-named-units-guard-fix;basis=InstallNamedUnits now also returns the unguarded reason; the verb prints it beside the installed path. No new read file:ReadFile@278 03ab2984b8866a2a590a9867cf8b04fd1af853e1286b654c5f992ac46afa1c10
+internal/host/unitops.go consoleGuardHost legacy accepted-legacy accepted-legacy;rev3=census-ruling-named-units-param-114;basis=new (Task 2/4): root's trusted read (rootstate.OpenTrustedFile, MaxRecord cap) of <opt>/system/guard/console-ready.json, the marker root's guard-arm writes; absent is unguarded, any other failure or a marker naming no valid live host is an error that refuses the install; the host is taken only when the bytes equal release.LiveLink(opt, host);rev3=census-ruling-named-units-guard-fix;basis=the guard read now distinguishes an untrusted chain, which is treated as unguarded (Paul's ruling 2026-11-19): it walks <opt>/system/guard first with rootstate.OpenTrustedDir (same root-trusted walk as before); os.ErrPermission from that walk is ok=false, no error, with an unguarded reason; absent is ok=false as before; then it opens console-ready.json in the walked directory with rootstate.OpenTrustedFileIn (same file checks as OpenTrustedFile: no symlink, root-owned, one link, not group/other-writable) and an untrusted, oversized or hostless marker still refuses. No new read: the same marker through the same checks, split in two file:ReadAll@623 e7372aa14ec47f8b6deb88f20c8a8d15cccab06c7d6b0db7589ac85b6dfc23e6
+internal/rootstate/file_linux.go OpenTrustedDir legacy accepted-legacy accepted-legacy;rev3=census-ruling-named-units-guard-fix;basis=new: the directory half of OpenTrustedFile, the same trusted walk (root-owned, not group/other-writable, r-x for group and others) from / to dir, returning the directory descriptor; no other read file:Open@64 de0f8222d4721aa93a5588b7cdb9953700c970a9c467d74ad6bc0fb72b378d33
+internal/rootstate/file_linux.go OpenTrustedFileIn legacy accepted-legacy accepted-legacy;rev3=census-ruling-named-units-guard-fix;basis=new: the file half of OpenTrustedFile: opens a name inside a trusted directory descriptor with O_NOFOLLOW and requires a root-owned regular file, one link, not group/other-writable; no other read file:Fstat@101 988166d41e2f4702db8df21a2c56dad5b8d7fd0e34dc9ee0a76f5a501a22a842
+@coverage . b26a2fbc95e2325125f3fd52a3abd1db269e562a52a0faccee76b995670b9657
+@coverage internal/host 5d386497a965577b76c5e5b6d357bad9f9c35320d455f9d6b8e8bd2b2943fe58
+@coverage internal/rootstate fa81cd055bfc3b6f0c19075b65ada2e0798cf14ca6ecb4ff8657159e915fd6d4
diff --git a/internal/rootstate/file_linux.go b/internal/rootstate/file_linux.go
index 34a2db4ac..20d9bfebc 100644
--- a/internal/rootstate/file_linux.go
+++ b/internal/rootstate/file_linux.go
@@ -30,6 +30,39 @@ func OpenTrustedFile(path string) (*os.File, error) {
return f, nil
}
+// OpenTrustedDir is OpenTrustedFile's directory walk on its own: Open's
+// public walk from / with every component root-owned, writable by neither
+// group nor others, and r-x for both. The returned descriptor is path's,
+// for OpenTrustedFileIn. A caller that must tell an untrusted chain
+// (os.ErrPermission) from an untrusted file walks first with this.
+func OpenTrustedDir(path string) (*os.File, error) {
+ s, err := Open(path, false, true)
+ if err != nil {
+ return nil, err
+ }
+ return s.(*directory).file, nil
+}
+
+// OpenTrustedFileIn opens name in dir, a descriptor OpenTrustedDir or
+// OpenTrustedDirFrom returned, with OpenTrustedFile's checks on the file:
+// no symlink, a regular file with one link owned by dir's owner (root for
+// OpenTrustedDir) and writable by neither group nor others.
+func OpenTrustedFileIn(dir *os.File, name string) (*os.File, error) {
+ var st unix.Stat_t
+ if err := unix.Fstat(int(dir.Fd()), &st); err != nil {
+ return nil, err
+ }
+ f, err := safefile.OpenFileAt(int(dir.Fd()), name, os.O_RDONLY, 0)
+ if err != nil {
+ return nil, err
+ }
+ if err := trusted(int(f.Fd()), st.Uid, unix.S_IFREG); err != nil {
+ f.Close()
+ return nil, err
+ }
+ return f, nil
+}
+
// OpenTrustedDirFrom is Open's walk from anchor to dir, trusting the
// ANCHOR's owner: every component below the anchor is opened by directory
// descriptor with O_NOFOLLOW, and each, the anchor included, must be a
diff --git a/internal/rootstate/file_linux_test.go b/internal/rootstate/file_linux_test.go
index c1e0ea532..95f39e8d2 100644
--- a/internal/rootstate/file_linux_test.go
+++ b/internal/rootstate/file_linux_test.go
@@ -40,3 +40,73 @@ func TestPlan14ProofBindingFileProvenance(t *testing.T) {
}
}
}
+
+// OpenTrustedDir and OpenTrustedFileIn split OpenTrustedFile's read so a
+// caller can tell an untrusted directory chain from an untrusted file.
+func TestOpenTrustedDirThenFileIn(t *testing.T) {
+ t.Run("root-owned chain", func(t *testing.T) {
+ for _, path := range []string{"/", "/usr", "/usr/bin", "/usr/bin/true"} {
+ var st unix.Stat_t
+ if err := unix.Lstat(path, &st); err != nil {
+ t.Fatal(err)
+ }
+ if st.Uid != 0 {
+ t.Skipf("root-owned fixture unavailable: %s uid=%d", path, st.Uid)
+ }
+ }
+ d, err := OpenTrustedDir("/usr/bin")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer d.Close()
+ f, err := OpenTrustedFileIn(d, "true")
+ if err != nil {
+ t.Fatal(err)
+ }
+ f.Close()
+ })
+ if os.Geteuid() != 0 {
+ if _, err := OpenTrustedDir(t.TempDir()); !errors.Is(err, os.ErrPermission) {
+ t.Fatalf("a non-root chain: %v, want os.ErrPermission", err)
+ }
+ }
+ anchor := t.TempDir()
+ if err := os.Chmod(anchor, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ body := filepath.Join(anchor, "body")
+ if err := os.WriteFile(body, []byte("x"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Chmod(body, 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(anchor, "loose"), []byte("x"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Chmod(filepath.Join(anchor, "loose"), 0o664); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink(body, filepath.Join(anchor, "link")); err != nil {
+ t.Fatal(err)
+ }
+ d, err := OpenTrustedDirFrom(anchor, anchor)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer d.Close()
+ f, err := OpenTrustedFileIn(d, "body")
+ if err != nil {
+ t.Fatal(err)
+ }
+ f.Close()
+ if _, err := OpenTrustedFileIn(d, "absent"); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("absent: %v, want os.ErrNotExist", err)
+ }
+ for _, name := range []string{"loose", "link", "../body", "."} {
+ if f, err := OpenTrustedFileIn(d, name); err == nil {
+ f.Close()
+ t.Fatalf("%s: opened an untrusted file", name)
+ }
+ }
+}
diff --git a/internal/rootstate/file_other.go b/internal/rootstate/file_other.go
index 326be62a1..0aea6033b 100644
--- a/internal/rootstate/file_other.go
+++ b/internal/rootstate/file_other.go
@@ -6,6 +6,10 @@ import "os"
func OpenTrustedFile(string) (*os.File, error) { return nil, os.ErrPermission }
+func OpenTrustedDir(string) (*os.File, error) { return nil, os.ErrPermission }
+
+func OpenTrustedFileIn(*os.File, string) (*os.File, error) { return nil, os.ErrPermission }
+
func OpenTrustedDirFrom(string, string) (*os.File, error) { return nil, os.ErrPermission }
func OpenTrustedFileFrom(string, string) (*os.File, error) { return nil, os.ErrPermission }
diff --git a/system_namedunits.go b/system_namedunits.go
index 8553698a8..6b027cca6 100644
--- a/system_namedunits.go
+++ b/system_namedunits.go
@@ -43,7 +43,7 @@ const namedUnitsUsage = `usage: carlos system named-units install <file>
// namedUnitsPickup is the line put prints after a write: when the box
// takes the value.
-const namedUnitsPickup = "The box installs it on its next config pass (any config write to an app on that box starts one) or within the hour."
+const namedUnitsPickup = "The box installs it on its next config pass, within the hour. A config write starts an earlier pass only when the app you write to runs as a named unit on that box."
// namedUnitsOutcomeText says what each outcome in root's record means.
var namedUnitsOutcomeText = map[string]string{
diff --git a/system_namedunits_test.go b/system_namedunits_test.go
index 6c6ea9edd..20f759e16 100644
--- a/system_namedunits_test.go
+++ b/system_namedunits_test.go
@@ -128,7 +128,7 @@ func TestNamedUnitsPutPrintsPathVersionAndPickup(t *testing.T) {
"/carlos/host/named-units/" + testIID,
"version 3",
"eu-west-1",
- "box installs it on its next config pass (any config write to an app on that box starts one) or within the hour",
+ "box installs it on its next config pass, within the hour. A config write starts an earlier pass only when the app you write to runs as a named unit on that box",
"carlos system named-units show --instance " + testIID,
} {
if !strings.Contains(s, want) {