Rootfs processes get HOME=/tmp when nothing sets one
Rootfs Plan 6's dev checklist (Task 15 Step 3) found that carlos console on the Rails sample exits 1 at start. Nothing gave a rootfs process a HOME, which Docker and the OCI runtimes always do, so Ruby's Dir.home fell back to getlogin_r. That answers ENODEV on a session's terminal because every instance template hides /dev/pts. Every Rails boot also logged "`/` is not writable. Bundler will use /tmp...". The trampoline's rootfs launch now passes the merged environment through withDefaultHome. It appends HOME=/tmp (DefaultRootfsHome, the one writable place besides the database's directory) only when no entry names HOME. A HOME the image's config, the processes file or the instance sets, even an empty one, is kept. It is box-side, so releases already shipped get it without a reship. Binary instances are unchanged. Test: TestRootfsLaunchGivesAProcessAHome covers no HOME, the manifest's, the instance's and an empty one, with no duplicate keys. Census: root-read overlay rootfs-default-home (execRootfsLaunch body, the same two read sites). The record-write inventory entry is re-digested with a note.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+91
−2
docs/superpowers/notes/census-proposal-rootfs-default-home.md+19 −0internal/instanceexec/exec_rootfs.go+21 −1internal/instanceexec/exec_rootfs_test.go+43 −0internal/provision/rootfs_apps_2_census_test.go+2 −1internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-rootfs-default-home.tsv+5 −0
Intent
Attributed to this commit: 73.5 g CO₂e (9,212,031 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on rootfs-default-home, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/notes/census-proposal-rootfs-default-home.md b/docs/superpowers/notes/census-proposal-rootfs-default-home.md| new file mode 100644 |
| index 000000000..3693e523b |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-rootfs-default-home.md |
| @@ -0,0 +1,19 @@ |
| +# Census approval: rootfs-default-home |
| + |
| +Ruling `census-ruling-rootfs-default-home`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/instanceexec/exec_rootfs.go` `execRootfsLaunch` | body | unchanged (2) | rootfs HOME default: the merged environment passes through withDefaultHome, which appends HOME=/tmp (DefaultRootfsHome) only when no entry names HOME; a HOME the manifest or the tenant launch sets, even empty, is kept. Environment only: argv, argv0 resolution (still the manifest PATH, never the tenant PATH), working dir, both launch-file checks and every refusal are unchanged; reads nothing new, the same two sites | |
| + |
| +Envelopes re-pinned: `internal/instanceexec`. |
| + |
| +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/instanceexec/exec_rootfs.go` `execRootfsLaunch`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-2;identity=the trampoline (/opt/carlos/carlos instance-exec --rootfs <role> <iid>, the ExecStart= of a rootfs unit, run by PID 1 as user carlos inside the unit's namespace, whose root is the instance's own image mounted read-only, nosuid, nodev; no root process runs it);basis=root-input (J4, as execLaunch): new (rootfs Plan 2 Task 6): reads the tenant half (launch.<role>.json in the instance's own directory, instancefs.ReadBeneath, refusing a symlink or an escape) for the environment only, refusing a file that names a command, another host or a bad env entry; then root's half at /opt/carlos/launch.json, a read-only bind of root's file, after realRootLaunchOwned; the argv, working dir and PATH are root's alone; the Stat is ResolveRootfsCommand's os.Stat of a candidate inside the image; it execs as carlos and decides nothing for root |
| + |
| +Seal: `f9d3016cc6803338f9db19311f3f598e20c37c8a19e111a3dabf4741dabe1b19` → `3c5808bf02dd469289332e305d8471eeb961e3de371881440fc6e9f12ee2ce96`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-rootfs-default-home.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/instanceexec/exec_rootfs.go b/internal/instanceexec/exec_rootfs.go| index f998be63d..97c4aec5a 100644 |
| --- a/internal/instanceexec/exec_rootfs.go |
| +++ b/internal/instanceexec/exec_rootfs.go |
| @@ -123,7 +123,27 @@ func execRootfsLaunch(dataDir, rootLaunch string, role instancectl.Role, inst st |
| if err != nil { |
| return refused("%v", err) |
| } |
| - return execFn(argv0, root.Argv, MergeRootfsEnv(root.Env, tenant.Env)) |
| + return execFn(argv0, root.Argv, withDefaultHome(MergeRootfsEnv(root.Env, tenant.Env))) |
| +} |
| + |
| +// DefaultRootfsHome is the HOME a rootfs process gets when neither the |
| +// image's config, the app nor the instance sets one. Docker and the OCI |
| +// runtimes always give a process a HOME. Without one, Ruby's Dir.home asks |
| +// getlogin_r, which answers ENODEV on a session's terminal because every |
| +// instance template hides /dev/pts, so `carlos console` on a Rails app |
| +// stopped at start (rootfs Plan 6 Task 15, dev). /tmp is writable by every |
| +// process of the instance; the image itself is read-only. |
| +const DefaultRootfsHome = "/tmp" |
| + |
| +// withDefaultHome is env with HOME=DefaultRootfsHome appended when no |
| +// entry names HOME. A HOME that is set, even to "", is kept. |
| +func withDefaultHome(env []string) []string { |
| + for _, kv := range env { |
| + if strings.HasPrefix(kv, "HOME=") { |
| + return env |
| + } |
| + } |
| + return append(env, "HOME="+DefaultRootfsHome) |
| } |
| // ResolveRootfsCommand resolves argv0 inside the image by Plan 1's rule |
diff --git a/internal/instanceexec/exec_rootfs_test.go b/internal/instanceexec/exec_rootfs_test.go| index d2680f08e..0fc5a3dc5 100644 |
| --- a/internal/instanceexec/exec_rootfs_test.go |
| +++ b/internal/instanceexec/exec_rootfs_test.go |
| @@ -627,3 +627,46 @@ func TestBinaryTrampolineRefusesARootfsLaunchFileAndTheReverse(t *testing.T) { |
| t.Fatalf("the rootfs shape ran a schema-1 launch file: %v", err) |
| } |
| } |
| + |
| +// A rootfs process always has a HOME, as under Docker and the OCI |
| +// runtimes. Without one Ruby's Dir.home asks getlogin_r, which answers |
| +// ENODEV on a session's terminal because /dev/pts is hidden, and |
| +// `carlos console` on a Rails app stopped at start (Plan 6 Task 15, dev). |
| +// A HOME the image's config, the app or the instance sets is kept. |
| +func TestRootfsLaunchGivesAProcessAHome(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + manifest map[string]string |
| + tenantHome string |
| + want string |
| + }{ |
| + {"none set", nil, "", DefaultRootfsHome}, |
| + {"the manifest's", map[string]string{"HOME": "/rails"}, "", "/rails"}, |
| + {"the instance's", nil, "/srv/home", "/srv/home"}, |
| + {"set empty", map[string]string{"HOME": ""}, "", ""}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + f := newRootfsExecFixture(t) |
| + if tc.tenantHome != "" { |
| + f.tenant.Env = append(f.tenant.Env, "HOME="+tc.tenantHome) |
| + f.writeTenant(t) |
| + } |
| + env := map[string]string{"PATH": f.imagePath("app") + ":" + f.imagePath("usr/bin")} |
| + for k, v := range tc.manifest { |
| + env[k] = v |
| + } |
| + f.writeRoot(t, instancectl.RootfsLaunch{Schema: 1, Host: f.host, Process: "web", Argv: []string{"serve"}, Env: env, Version: "v1", Digest: f.digest}) |
| + var c captured |
| + if err := execRootfsLaunch(f.dataDir, f.rootLaunch, instancectl.RoleRun, f.iid, c.exec); err != nil { |
| + t.Fatal(err) |
| + } |
| + got, ok := envMap(c.env)["HOME"] |
| + if !ok || got != tc.want { |
| + t.Errorf("HOME = %q (set %v), want %q", got, ok, tc.want) |
| + } |
| + if dups := duplicateKeys(c.env); len(dups) > 0 { |
| + t.Errorf("duplicate env keys %v", dups) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/provision/rootfs_apps_2_census_test.go b/internal/provision/rootfs_apps_2_census_test.go| index 988bd0365..8c41ec25d 100644 |
| --- a/internal/provision/rootfs_apps_2_census_test.go |
| +++ b/internal/provision/rootfs_apps_2_census_test.go |
| @@ -53,7 +53,8 @@ func rootfsApps2WriteCensusInventory() []censusEntry { |
| censusEntry{"internal/instanceexec/exit.go", "parseExitArgs", "key-site", "lit:instances", "fa4b37d7203a51f29f7783aa741cfee2210c42a32c2a664b1bb8a23afeda958e"}, |
| censusEntry{"internal/instanceexec/probe.go", "ownTreesCheck", "key-site", "lit:instances", "b185ad889c0b7661b1dac7c85c7d5ff7fb5bd2596c4a44d67867c9aa64ea8b8a"}, |
| censusEntry{"internal/instanceexec/probe.go", "symlinkChecks", "key-site", "lit:instances", "ae6456ea50d360fc3c6967d8e9b7bcb0523e93365674e3c4c292ff2698110ced"}, |
| - censusEntry{"internal/instanceexec/exec_rootfs.go", "execRootfsLaunch", "key-site", "lit:instances", "047b129f61f6e9ebd737754ace0d0d58873c66845473af13402afbd725cfb630"}, |
| + // Re-digested for rootfs-default-home (census-ruling-rootfs-default-home, 2026-11-01): the merged env passes through withDefaultHome (HOME=/tmp when no entry names HOME). Same single ReadBeneath of the tenant launch file under instances/<iid>; no write. |
| + censusEntry{"internal/instanceexec/exec_rootfs.go", "execRootfsLaunch", "key-site", "lit:instances", "6c16958b78174f2c5f58a6ce7b3d8edbe77df4d2cdef0f7505a66546d2f414b9"}, |
| censusEntry{"internal/instanceexec/probe_rootfs.go", "foreignInstance", "key-site", "lit:instances", "c4d5b15bdef79937583a9b149d8dc971af6be15b8b161c5083719c9ce6825568"}, |
| ) |
| } |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index ed697dc84..19df7d0ac 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -53,3 +53,4 @@ plan14-root-reads-sponsor-existing-accounts.tsv 7570ca617863882780c1c5a7d04430b5 |
| plan14-root-reads-rootfs-apps-6.tsv c86929d08b9b2038fa103d1c7311ab2958e7100e92dc550d36daeb364affd029 |
| plan14-root-reads-devbox-macos.tsv 67b54b219f990c3dcfe32c6ffb11a80a4ca3898aec060fe9f4450e21098af714 |
| plan14-root-reads-fix-set-aside-exdev.tsv f9d3016cc6803338f9db19311f3f598e20c37c8a19e111a3dabf4741dabe1b19 |
| +plan14-root-reads-rootfs-default-home.tsv 3c5808bf02dd469289332e305d8471eeb961e3de371881440fc6e9f12ee2ce96 |
diff --git a/internal/provision/testdata/plan14-root-reads-rootfs-default-home.tsv b/internal/provision/testdata/plan14-root-reads-rootfs-default-home.tsv| new file mode 100644 |
| index 000000000..3d1cd95b3 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-rootfs-default-home.tsv |
| @@ -0,0 +1,5 @@ |
| +# Census overlay rootfs-default-home, written by census-propose (#369). census-ruling-rootfs-default-home, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-rootfs-default-home.md. |
| +# 1 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@legacy 8536f278ff7ce94db58628970287992caf5a500edd37e25dc432b8146f2c0132 internal/instanceexec/exec_rootfs.go execRootfsLaunch legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-2;identity=the trampoline (/opt/carlos/carlos instance-exec --rootfs <role> <iid>, the ExecStart= of a rootfs unit, run by PID 1 as user carlos inside the unit's namespace, whose root is the instance's own image mounted read-only, nosuid, nodev; no root process runs it);basis=root-input (J4, as execLaunch): new (rootfs Plan 2 Task 6): reads the tenant half (launch.<role>.json in the instance's own directory, instancefs.ReadBeneath, refusing a symlink or an escape) for the environment only, refusing a file that names a command, another host or a bad env entry; then root's half at /opt/carlos/launch.json, a read-only bind of root's file, after realRootLaunchOwned; the argv, working dir and PATH are root's alone; the Stat is ResolveRootfsCommand's os.Stat of a candidate inside the image; it execs as carlos and decides nothing for root;rev3=census-ruling-rootfs-default-home;basis=rootfs HOME default: the merged environment passes through withDefaultHome, which appends HOME=/tmp (DefaultRootfsHome) only when no entry names HOME; a HOME the manifest or the tenant launch sets, even empty, is kept. Environment only: argv, argv0 resolution (still the manifest PATH, never the tenant PATH), working dir, both launch-file checks and every refusal are unchanged; reads nothing new, the same two sites file:ReadFile@1654,file:Stat@3002 6c16958b78174f2c5f58a6ce7b3d8edbe77df4d2cdef0f7505a66546d2f414b9 |
| +internal/instanceexec/exec_rootfs.go execRootfsLaunch legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-2;identity=the trampoline (/opt/carlos/carlos instance-exec --rootfs <role> <iid>, the ExecStart= of a rootfs unit, run by PID 1 as user carlos inside the unit's namespace, whose root is the instance's own image mounted read-only, nosuid, nodev; no root process runs it);basis=root-input (J4, as execLaunch): new (rootfs Plan 2 Task 6): reads the tenant half (launch.<role>.json in the instance's own directory, instancefs.ReadBeneath, refusing a symlink or an escape) for the environment only, refusing a file that names a command, another host or a bad env entry; then root's half at /opt/carlos/launch.json, a read-only bind of root's file, after realRootLaunchOwned; the argv, working dir and PATH are root's alone; the Stat is ResolveRootfsCommand's os.Stat of a candidate inside the image; it execs as carlos and decides nothing for root;rev3=census-ruling-rootfs-default-home;basis=rootfs HOME default: the merged environment passes through withDefaultHome, which appends HOME=/tmp (DefaultRootfsHome) only when no entry names HOME; a HOME the manifest or the tenant launch sets, even empty, is kept. Environment only: argv, argv0 resolution (still the manifest PATH, never the tenant PATH), working dir, both launch-file checks and every refusal are unchanged; reads nothing new, the same two sites file:ReadFile@1654,file:Stat@3002 6c16958b78174f2c5f58a6ce7b3d8edbe77df4d2cdef0f7505a66546d2f414b9 |
| +@coverage internal/instanceexec 5d763fa91affc67202892a101b99cf6e9e0f8f7b8129cffffa83cfe73f3ccf41 |