Fleet set-aside moves through the raw instance dir (EXDEV fix)
Managed fleets 1b's start rule (v0.33.0) sets an unmarked or reassigned local copy aside by renaming it from the instance directory into <DataDir>/.superseded. On the nested layout /data/instances is a nosymfollow bind mount of /data/.instances, and rename(2) refuses to cross mount points even within one filesystem, so every move failed with EXDEV and every wake was refused. Found on dev fleet box box-1 after the v0.33.1 roll: shop and railsdemo answered 503 from their first restart since the drill labelled them. ExecBackend gains RawInstanceDir, set to layout.RawInstanceDir by the agent and the claim backend (activator cannot import layout). The set-aside moves through the raw directory only when it is the same directory as the instance directory (same device and inode); anything else moves as before. The location, the durability order and the no-symlink opens are unchanged. Tests: TestSetAsideCrossesTheNestedBindMount runs the real Restore in an unprivileged user and mount namespace with the box's bind, checks a plain rename across it is EXDEV, and fails without the fix with the box's error (skips where no unprivileged mount namespace exists). TestExecBackendsCarryTheRawInstanceDir (go/ast) requires the field on every wake-capable ExecBackend in internal/host. Reviews: Opus READY (two P3s, one fixed, one declined: editing the mount unit's comment would rewrite it on every box). Census census-ruling-fix-set-aside-exdev approved by Astra on #280; Astra correctness READY. Follow-up (not here): movesoffline_land.go's parkInto may rename a nested warm copy across the same bind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from fix-set-aside-exdev into main.
9 files changed,
+290
−4
docs/superpowers/notes/census-proposal-fix-set-aside-exdev.md+23 −0internal/activator/backend_exec.go+7 −0internal/activator/startrule.go+33 −3internal/activator/startrule_bind_linux_test.go+137 −0internal/host/agent.go+3 −0internal/host/claimproduction.go+2 −1internal/host/rawinstancedir_wiring_test.go+76 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-fix-set-aside-exdev.tsv+8 −0
CI failed — run details
diff --git a/docs/superpowers/notes/census-proposal-fix-set-aside-exdev.md b/docs/superpowers/notes/census-proposal-fix-set-aside-exdev.md| new file mode 100644 |
| index 000000000..11a6bbd33 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-fix-set-aside-exdev.md |
| @@ -0,0 +1,23 @@ |
| +# Census approval: fix-set-aside-exdev |
| + |
| +Ruling `census-ruling-fix-set-aside-exdev`. The independent reviewer approves or rejects every change below, 1 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/host/agent.go` `runAgent` | body | unchanged (6) | set-aside EXDEV fix: one field more on the agent ExecBackend literal, RawInstanceDir: layout.RawInstanceDir (a pure path join: <dataDir>/.instances/<InstanceID(host)>), so the start rule set-aside moves a copy out through the raw directory instead of through the nosymfollow bind; this body reads nothing new, the same six sites | |
| + |
| +Envelopes re-pinned: `internal/activator`, `internal/host`. |
| + |
| +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/agent.go` `runAgent`: authority, task B,C,D,F. Basis: rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): builds the box's lifetime judge once (newBoxJudge, nil with host claims on) and hands it to the seed placement, the moves and runs workers and every loop it starts; read sites unchanged, offsets moved; B,C,D,F authority retained; self-serve moves 1 Task 8: derives the box's lifetimes switch from the judge once (lifetimes := boxJudge != nil) and hands it to the edges file loop; read sites unchanged, offsets moved;rev3=census-ruling-plans-4d-lapse;basis=arms two more plans hooks from the same snapshot: e.SetPlanDisabledFor(planDisabledFor) beside SetPlanGovernedFor, and svc.SetDisabledFor(planDisabledRoute) beside SetMaxRunFor (plans 4d); the reads live in those units (plans-4d-units decision); read sites unchanged, offsets moved;rev3=census-ruling-rootfs-apps-2;basis=main's body as of the merge of origin/main 9b81d97b (with main's plan rate ceiling, edge request records, regional box names, self-serve moves plan 1, plans 4d-1 lapse and its other later changes under main's own census rulings) plus the rootfs placement wiring in the activator start: an agentRootfs built from eb.NestedOK, CARLOS_DEPLOYMENT_SINGLE_TENANT, CARLOS_POOLS, the claim flag, swapArming's answer, the control client's /ready/rootfs and, on a fleet box whose identity resolved, fleetOwnerCheck over the deploy store main already opens for the fleet label (fleetStore), then arm and armedRootfs.Store; this body reads nothing new itself; the closures it wires read later, at a rootfs wake and each status tick: GET /ready/rootfs over the control socket, NestedOK's checks, and release.FleetOwnerKey for the judged row's own account and this box's fleet from the deploy store;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Tasks 7 and 11, #329 plan 3 Task 7 and plan 1 Task 7's policy cache: the control client is built once and handed to eb.Control, to the status tick (egressStatus) and to a new egressNudgeLoop goroutine; armSizeSource(svc, "/sys/fs/cgroup") after the activator Service; armPolicyCache() after armChangeIndex; statusLoop takes egressStatus. The reads are those units' own (decision rows); this body reads nothing new: the same five sites, offsets moved, in the agent; B,C,D,F authority retained.;rev3=census-ruling-remote-instance-metrics;basis=builds the metrics loop's owners closure (metricsOwners over the agent's registry, the activator and cgm.Leftover) when an activator exists and hands it to metricsLoop; reads nothing new itself;rev3=census-ruling-edge-asset-cache-3;basis=adds file:Statfs. runAgent keeps its authority (B,C,D,F). The new site is assetcache.Statfs, an exported assetcache.FS interface value (var Statfs FS = statfsFS{}), not a function value and not a call in runAgent: the ready hook passes it to armEdgeAssetCache as the store's filesystem, and armEdgeAssetCache calls its Space method on the configured data directory (dataDir(): $CARLOS_DATA_DIR, else /data), which calls unix.Statfs there (statfsFS.Space, accepted legacy at census-ruling-edge-asset-cache-2). No request-supplied pathname reaches it.;rev3=census-ruling-remote-metrics-nested;basis=main's body (merged origin/main acfa4f80, under main's own census rulings) plus: snapshots the nested layout (snapshotNestedUnits over /sys/fs/cgroup/carlos.slice/carlos-instances.slice) once at start, before the activator, and hands the metrics loop a unitSources struct (stamped units, routeHostNames, that root and the snapshot); reads nothing new itself;rev3=census-ruling-region-ha-p1a;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): wires region HA P1a into the activator: cfg.Record = haRecordFacts(openDeployStore, boxJudge) (the box's lifetime judge this body already builds with newBoxJudge, nil with host claims on; CI fix) and cfg.Self = lease.CurrentSelf; eb.Lifetimes (the process's lifetime index), eb.Registry, eb.StartupSwept (seedSweptAtStart.Load), eb.FilesStore from newProductionFilesStore (now lease.NewFilesStore, rootaws-loaded, a log line on failure) and lease.SetObligationDir(<data>/.ha-owed) (logged on failure; HA acquires then refuse); this body reads nothing new itself, the same five sites; the reads are those units' own (haRecordFacts and lease's SetObligationDir are new rows on this card); merge of origin/main d7ae1d76: main's own later changes to this body are kept as main has them, under main's rulings (census-ruling-remote-instance-metrics: the metricsOwners closure for metricsLoop; census-ruling-edge-asset-cache-3: the +file:Statfs site, assetcache.Statfs handed to the asset ready hook); this branch's change is the same as above;rev3=census-ruling-region-ha-p1b1;basis=region HA P1b-1: builds one termfence.Confirmer (Self from lease.CurrentSelf at each call, EC2 DescribeInstances method only, client from rootaws.LoadDefaultConfig with retries off, built lazily on first use) and sets eb.OwnerTerminated; this body reads nothing new itself, the same six sites;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 7: the startup Sweep literal hands its answer to startupSwept, which logs as before and, only on a clean sweep, marks rootfs admission swept (MarkRootfsSwept); same Sweep call, no read added;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (controller ruling after branch review R1, and Paul's R2 ruling): sets svc.Fleet = fleetWakeFor(os.Getenv, identity, identErr, fleetStore) from the identity it already resolves once and the deployment store the fleet loops already opened, and logs an ERROR naming the identity error when the box is on a fleet with an invalid identity. fleetWakeFor reads CARLOS_REGION and CARLOS_FLEET from the same environment. Read sites unchanged (6). Agent, not root; a platform box is unchanged.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 12: one call more beside armRunsPass, armInteractivePass(svc, reg, rolloutSink, boxJudge), in the same activator Configure hook, handing it the same box judge; fix round 1 (Astra P2, shutdown): after svc.Shutdown(ctx), shutdownInteractive(ctx) ends and joins every interactive session under the same shutdown budget; the worker's own reads are its units' (interactive.go); this body reads nothing new, the same six sites; merge of origin/main 6f1f6ca6: main's svc.Fleet = fleetWakeFor(...) and its invalid-identity ERROR line are kept as main has them (census-ruling-managed-fleets-1b); this branch's change is the same as above; read sites unchanged (6) |
| + |
| +New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff: |
| + |
| +- new `internal/activator/startrule.go:ExecBackend.setAsideSource`: reads +file:Lstat ×2; written legacy, accepted-legacy, frozen |
| + |
| +Seal: `67b54b219f990c3dcfe32c6ffb11a80a4ca3898aec060fe9f4450e21098af714` → `f9d3016cc6803338f9db19311f3f598e20c37c8a19e111a3dabf4741dabe1b19`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-fix-set-aside-exdev.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/activator/backend_exec.go b/internal/activator/backend_exec.go| index 212525d36..21b0ef30b 100644 |
| --- a/internal/activator/backend_exec.go |
| +++ b/internal/activator/backend_exec.go |
| @@ -92,6 +92,13 @@ type ExecBackend struct { |
| // DataDir holds each instance's DB and env files (<host>.db, <host>.env, |
| // <host>-sidecar.env) — /data in production. |
| DataDir string |
| + // RawInstanceDir, when set, names a host's raw instance directory |
| + // (layout.RawInstanceDir, which this package cannot import), the one |
| + // that /data/instances/<id> is a bind mount of on the nested layout. |
| + // The start rule's set-aside moves a copy out through it, because a |
| + // rename through the bind answers EXDEV (setAsideSource). Nil keeps |
| + // every move on the instance directory itself. |
| + RawInstanceDir func(dataDir, host string) string |
| // Materialize, when non-nil, stages a binary and points the host's live |
| // symlink at it via an external mechanism instead of the backend doing |
| // filesystem work itself — Eleven needed this because its router ran |
diff --git a/internal/activator/startrule.go b/internal/activator/startrule.go| index 3090e793f..3f746ead5 100644 |
| --- a/internal/activator/startrule.go |
| +++ b/internal/activator/startrule.go |
| @@ -15,7 +15,9 @@ package activator |
| // |
| // A local copy under any other assignment, or under none, is SET ASIDE, |
| // NEVER DELETED: moved whole into <DataDir>/.superseded/<host>/<unix |
| -// nanos>/ (built as <unix nanos>.partial and renamed when complete). A |
| +// nanos>/ (built as <unix nanos>.partial and renamed when complete; on the |
| +// nested layout the move goes through the raw instance directory, see |
| +// setAsideSource). A |
| // set-aside copy, complete or partial, stays on disk as the standing |
| // reason to refuse an empty start, so a second wake and an agent restart |
| // refuse again. Nothing in this package deletes from .superseded: that is |
| @@ -217,6 +219,33 @@ func (b *ExecBackend) reconcileAssignment(rt registry.Route, dbPath string) erro |
| return nil |
| } |
| +// setAsideSource is the directory the set-aside moves a local copy out |
| +// of. On the nested layout the instance directory is reached through a |
| +// nosymfollow bind mount of the raw instance directory, and rename(2) |
| +// refuses to cross mount points even within one filesystem (EXDEV), so a |
| +// move from it into <DataDir>/.superseded can never succeed (found on a |
| +// dev fleet box, v0.33.0: every wake of an unmarked copy was refused). |
| +// When b.RawInstanceDir names a raw directory that is the same directory |
| +// as dir, the copy moves out through it, which shares .superseded's |
| +// mount. Anything else (the flat layout, no raw directory, a test's plain |
| +// directory) moves from dir as before. The renames open both paths with |
| +// no symlink resolution, as before. |
| +func (b *ExecBackend) setAsideSource(host, dir string) string { |
| + if b.RawInstanceDir == nil { |
| + return dir |
| + } |
| + raw := b.RawInstanceDir(b.DataDir, host) |
| + if raw == "" || raw == dir { |
| + return dir |
| + } |
| + viaBind, errB := os.Lstat(dir) |
| + viaRaw, errR := os.Lstat(raw) |
| + if errB != nil || errR != nil || !viaBind.IsDir() || !viaRaw.IsDir() || !os.SameFile(viaBind, viaRaw) { |
| + return dir |
| + } |
| + return raw |
| +} |
| + |
| // supersede moves names from dir into a new set-aside entry for host and |
| // returns the entry's final path. On a failure part way, what has moved |
| // stays in the .partial directory, whose path the error names. |
| @@ -239,6 +268,7 @@ func (b *ExecBackend) supersede(host, dir string, names []string) (string, error |
| } |
| root := filepath.Dir(hostDir) |
| dataRoot := filepath.Dir(root) |
| + src := b.setAsideSource(host, dir) |
| if _, err := instancefs.EnsureDirBeneath(dataRoot, supersededDirName, 0o700); err != nil { |
| return "", err |
| } |
| @@ -271,10 +301,10 @@ func (b *ExecBackend) supersede(host, dir string, names []string) (string, error |
| return partial, fmt.Errorf("sync %s: %w", hostDir, err) |
| } |
| for _, n := range names { |
| - if err := setAsideRename(dir, n, partial, n); err != nil { |
| + if err := setAsideRename(src, n, partial, n); err != nil { |
| return partial, fmt.Errorf("interrupted with part of it at %s: %w", partial, err) |
| } |
| - for _, d := range []string{dir, partial} { |
| + for _, d := range []string{src, partial} { |
| if err := durableSync(d); err != nil { |
| return partial, fmt.Errorf("interrupted with part of it at %s: sync %s: %w", partial, d, err) |
| } |
diff --git a/internal/activator/startrule_bind_linux_test.go b/internal/activator/startrule_bind_linux_test.go| new file mode 100644 |
| index 000000000..587ae4900 |
| --- /dev/null |
| +++ b/internal/activator/startrule_bind_linux_test.go |
| @@ -0,0 +1,137 @@ |
| +//go:build linux |
| + |
| +package activator |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "os" |
| + "os/exec" |
| + "path/filepath" |
| + "strings" |
| + "syscall" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// bindChildEnv marks the re-executed test binary that runs inside its own |
| +// user and mount namespace, where it may bind-mount without privilege. |
| +const bindChildEnv = "CARLOS_TEST_SETASIDE_BIND_CHILD" |
| + |
| +// bindSkipPrefix is what the child prints when this kernel will not let |
| +// it build the bind mount, so the parent skips rather than fails. |
| +const bindSkipPrefix = "SKIP-BIND: " |
| + |
| +// TestSetAsideCrossesTheNestedBindMount sets aside an unmarked copy on the |
| +// nested layout as a box has it: <DataDir>/instances is a bind mount of |
| +// <DataDir>/.instances, so rename(2) from an instance directory into |
| +// <DataDir>/.superseded fails with EXDEV. v0.33.0 moved through the bind |
| +// and refused every wake of shop and railsdemo on a dev fleet box. The |
| +// test runs the real Restore in a user and mount namespace holding that |
| +// bind, checks first that a plain rename across it does fail with EXDEV, |
| +// and then that the copy is set aside whole and a replica restored. |
| +func TestSetAsideCrossesTheNestedBindMount(t *testing.T) { |
| + if os.Getenv(bindChildEnv) == "1" { |
| + setAsideUnderBind(t) |
| + return |
| + } |
| + self, err := os.Executable() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + // The child dies with the parent's deadline, so a hang in it can never |
| + // outlive the test run on a CI worker. |
| + ctx := context.Background() |
| + if dl, ok := t.Deadline(); ok { |
| + var cancel context.CancelFunc |
| + ctx, cancel = context.WithDeadline(ctx, dl) |
| + defer cancel() |
| + } |
| + cmd := exec.CommandContext(ctx, self, "-test.run=^TestSetAsideCrossesTheNestedBindMount$", "-test.count=1", "-test.v") |
| + cmd.Env = append(os.Environ(), bindChildEnv+"=1") |
| + cmd.SysProcAttr = &syscall.SysProcAttr{ |
| + Cloneflags: syscall.CLONE_NEWUSER | syscall.CLONE_NEWNS, |
| + UidMappings: []syscall.SysProcIDMap{{ContainerID: 0, HostID: os.Getuid(), Size: 1}}, |
| + GidMappings: []syscall.SysProcIDMap{{ContainerID: 0, HostID: os.Getgid(), Size: 1}}, |
| + Pdeathsig: syscall.SIGKILL, |
| + } |
| + out, err := cmd.CombinedOutput() |
| + if i := strings.Index(string(out), bindSkipPrefix); i >= 0 { |
| + t.Skipf("no bind mount in an unprivileged namespace here: %s", strings.TrimSpace(string(out[i+len(bindSkipPrefix):]))) |
| + } |
| + if err != nil { |
| + var ee *exec.ExitError |
| + if !errors.As(err, &ee) { |
| + t.Skipf("no unprivileged user and mount namespace here: %v", err) |
| + } |
| + t.Fatalf("set-aside under the bind failed: %v\n%s", err, out) |
| + } |
| + if !strings.Contains(string(out), "--- PASS: TestSetAsideCrossesTheNestedBindMount") { |
| + t.Fatalf("the child did not run the test:\n%s", out) |
| + } |
| +} |
| + |
| +// setAsideUnderBind is the child's half: it builds the box's bind, then |
| +// drives Restore on a labelled row whose copy has no marker. |
| +func setAsideUnderBind(t *testing.T) { |
| + skip := func(format string, args ...any) { |
| + t.Logf(bindSkipPrefix+format, args...) |
| + t.SkipNow() |
| + } |
| + // A mount made here must not propagate anywhere. |
| + if err := syscall.Mount("", "/", "", syscall.MS_REC|syscall.MS_PRIVATE, ""); err != nil { |
| + skip("make / private: %v", err) |
| + } |
| + b := testExecBackend(t) |
| + // What the agent wires in production (layout.RawInstanceDir). |
| + b.RawInstanceDir = func(dataDir, host string) string { |
| + return filepath.Join(dataDir, ".instances", provision.InstanceID(host)) |
| + } |
| + raw := filepath.Join(b.DataDir, ".instances") |
| + bind := filepath.Join(b.DataDir, "instances") |
| + for _, d := range []string{raw, bind} { |
| + if err := os.Mkdir(d, 0o700); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if err := syscall.Mount(raw, bind, "", syscall.MS_BIND, ""); err != nil { |
| + skip("bind %s on %s: %v", raw, bind, err) |
| + } |
| + t.Cleanup(func() { _ = syscall.Unmount(bind, syscall.MNT_DETACH) }) |
| + |
| + instDir := provision.InstanceDir(b.DataDir, ruleHost) |
| + if err := os.Mkdir(instDir, 0o700); err != nil { |
| + t.Fatal(err) |
| + } |
| + // The condition the box had: a rename out through the bind is EXDEV. |
| + probe := filepath.Join(instDir, "probe") |
| + if err := os.WriteFile(probe, nil, 0o600); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.Rename(probe, filepath.Join(b.DataDir, "probe")); !errors.Is(err, syscall.EXDEV) { |
| + t.Fatalf("rename across the bind = %v; want EXDEV, or this test reproduces nothing", err) |
| + } |
| + if err := os.Remove(probe); err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + rt := registry.Route{Host: ruleHost, Kind: "instance", Hibernate: true, |
| + Socket: "/tmp/nope.sock", DBPath: filepath.Join(instDir, ruleHost+".db"), |
| + Assigned: assignA} |
| + want := localCopy(t, rt.DBPath, "") |
| + restores := replicaCalls(t, true) |
| + |
| + fresh, err := b.Restore(context.Background(), rt) |
| + if err != nil || fresh { |
| + t.Fatalf("fresh %v err %v; want the copy set aside and a replica restored", fresh, err) |
| + } |
| + if *restores != 1 { |
| + t.Fatalf("restores = %d; want 1", *restores) |
| + } |
| + assertSetAside(t, b, rt.Host, want) |
| + if got, ok := markerAt(t, rt.DBPath); !ok || got != assignA { |
| + t.Fatalf("marker = %q (present %v); want %q after the restore", got, ok, assignA) |
| + } |
| +} |
diff --git a/internal/host/agent.go b/internal/host/agent.go| index 21d84cbd6..89f90eacc 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -439,6 +439,9 @@ func runAgent(args []string, buildClaims ClaimFactory) { |
| Cache: cache, |
| Materialize: materializeHook(reg, dd), |
| Cgroups: cgm, |
| + // The start rule's set-aside moves a copy out through the raw |
| + // directory: a rename through the nested bind answers EXDEV. |
| + RawInstanceDir: layout.RawInstanceDir, |
| // The memory tier for each spawned child's cgroup, read off the |
| // staged manifest of the route's live version (memory-pressure |
| // spec §2.3): 512M, or 1G for a family that declares children. |
diff --git a/internal/host/claimproduction.go b/internal/host/claimproduction.go| index 1569d66b7..03a0ab129 100644 |
| --- a/internal/host/claimproduction.go |
| +++ b/internal/host/claimproduction.go |
| @@ -25,6 +25,7 @@ import ( |
| "github.com/carlosframework/platform/internal/hostguard" |
| "github.com/carlosframework/platform/internal/hostops" |
| "github.com/carlosframework/platform/internal/hostwrite" |
| + "github.com/carlosframework/platform/internal/layout" |
| "github.com/carlosframework/platform/internal/lease" |
| "github.com/carlosframework/platform/internal/moves" |
| "github.com/carlosframework/platform/internal/park" |
| @@ -245,7 +246,7 @@ func (ProductionClaimOwnerProvider) OpenClaimOwners(ctx context.Context, store r |
| // could mint before the configuration was delivered; the agent's backend |
| // is wired from the same pair. |
| func claimExecBackend(r ClaimRuntimeResources, keys instanceKeyReaders) *activator.ExecBackend { |
| - eb := &activator.ExecBackend{DataDir: r.DataDir, OptDir: r.OptDir, Cgroups: r.Manager} |
| + eb := &activator.ExecBackend{DataDir: r.DataDir, OptDir: r.OptDir, Cgroups: r.Manager, RawInstanceDir: layout.RawInstanceDir} |
| keys.wire(eb) |
| return eb |
| } |
diff --git a/internal/host/rawinstancedir_wiring_test.go b/internal/host/rawinstancedir_wiring_test.go| new file mode 100644 |
| index 000000000..3305df288 |
| --- /dev/null |
| +++ b/internal/host/rawinstancedir_wiring_test.go |
| @@ -0,0 +1,76 @@ |
| +package host |
| + |
| +import ( |
| + "go/ast" |
| + "go/parser" |
| + "go/token" |
| + "os" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +// Every activator.ExecBackend this package builds to wake instances must |
| +// carry RawInstanceDir, or the start rule's set-aside renames through the |
| +// nested bind mount and every wake of an unmarked fleet copy is refused |
| +// with EXDEV (v0.33.0 on a dev fleet box). rawDirExempt lists the |
| +// literals that never wake anything, with the reason. |
| +var rawDirExempt = map[string]string{ |
| + "movesheldenv.go": "renders a held instance's env into a temporary directory; never restores or starts", |
| +} |
| + |
| +func TestExecBackendsCarryTheRawInstanceDir(t *testing.T) { |
| + files, err := filepath.Glob("*.go") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + found := 0 |
| + for _, path := range files { |
| + if strings.HasSuffix(path, "_test.go") { |
| + continue |
| + } |
| + src, err := os.ReadFile(path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + f, err := parser.ParseFile(token.NewFileSet(), path, src, 0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + ast.Inspect(f, func(n ast.Node) bool { |
| + lit, ok := n.(*ast.CompositeLit) |
| + if !ok { |
| + return true |
| + } |
| + sel, ok := lit.Type.(*ast.SelectorExpr) |
| + if !ok || sel.Sel.Name != "ExecBackend" { |
| + return true |
| + } |
| + if x, ok := sel.X.(*ast.Ident); !ok || x.Name != "activator" { |
| + return true |
| + } |
| + found++ |
| + if _, ok := rawDirExempt[path]; ok { |
| + return true |
| + } |
| + for _, el := range lit.Elts { |
| + kv, ok := el.(*ast.KeyValueExpr) |
| + if !ok { |
| + continue |
| + } |
| + if k, ok := kv.Key.(*ast.Ident); ok && k.Name == "RawInstanceDir" { |
| + if v, ok := kv.Value.(*ast.SelectorExpr); ok && v.Sel.Name == "RawInstanceDir" { |
| + if x, ok := v.X.(*ast.Ident); ok && x.Name == "layout" { |
| + return true |
| + } |
| + } |
| + } |
| + } |
| + t.Errorf("%s: an activator.ExecBackend without RawInstanceDir: layout.RawInstanceDir", path) |
| + return true |
| + }) |
| + } |
| + if found < 2 { |
| + t.Fatalf("found %d ExecBackend literals; the scan is looking in the wrong place", found) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 2960b5a41..ed697dc84 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -52,3 +52,4 @@ plan14-root-reads-managed-fleets-1b.tsv 7570ca617863882780c1c5a7d04430b578a297ee |
| plan14-root-reads-sponsor-existing-accounts.tsv 7570ca617863882780c1c5a7d04430b578a297ee4d72ca25acc1cdc5288ca283 |
| plan14-root-reads-rootfs-apps-6.tsv c86929d08b9b2038fa103d1c7311ab2958e7100e92dc550d36daeb364affd029 |
| plan14-root-reads-devbox-macos.tsv 67b54b219f990c3dcfe32c6ffb11a80a4ca3898aec060fe9f4450e21098af714 |
| +plan14-root-reads-fix-set-aside-exdev.tsv f9d3016cc6803338f9db19311f3f598e20c37c8a19e111a3dabf4741dabe1b19 |
diff --git a/internal/provision/testdata/plan14-root-reads-fix-set-aside-exdev.tsv b/internal/provision/testdata/plan14-root-reads-fix-set-aside-exdev.tsv| new file mode 100644 |
| index 000000000..0c4b0c828 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-fix-set-aside-exdev.tsv |
| @@ -0,0 +1,8 @@ |
| +# Census overlay fix-set-aside-exdev, written by census-propose (#369). census-ruling-fix-set-aside-exdev, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-fix-set-aside-exdev.md. |
| +# 1 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 1 new dispositions: 0 reads re-frozen at their disposition with the claim, 1 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| +@legacy 1d4ec6ca60a9a0d2f69c88f09eabc213cfc38315ea2871fd29ef82551f013c19 internal/activator/startrule.go ExecBackend.setAsideSource legacy accepted-legacy accepted-legacy;rev3=census-ruling-fix-set-aside-exdev;basis=new: picks the directory supersede renames from. With b.RawInstanceDir set, Lstats the instance directory (from the route DBPath, as reconcileAssignment already reads it) and the raw path layout.RawInstanceDir names for the host (agent-owned /data/.instances/<id>, 0700 carlos; the id comes from the host name, not tenant input); only when both are directories and os.SameFile returns the raw path, otherwise the instance directory as before. Lstat follows no final symlink; the renames still open both directories with openat2 RESOLVE_NO_SYMLINKS. Adds two root reads (file:Lstat) of paths a tenant cannot name file:Lstat@216,file:Lstat@247 45ee09c91b7f682d49b38f430c7ae194363c547f2a1314e9a735fa41f37a3d8f |
| +internal/host/agent.go runAgent authority B,C,D,F rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): builds the box's lifetime judge once (newBoxJudge, nil with host claims on) and hands it to the seed placement, the moves and runs workers and every loop it starts; read sites unchanged, offsets moved; B,C,D,F authority retained; self-serve moves 1 Task 8: derives the box's lifetimes switch from the judge once (lifetimes := boxJudge != nil) and hands it to the edges file loop; read sites unchanged, offsets moved;rev3=census-ruling-plans-4d-lapse;basis=arms two more plans hooks from the same snapshot: e.SetPlanDisabledFor(planDisabledFor) beside SetPlanGovernedFor, and svc.SetDisabledFor(planDisabledRoute) beside SetMaxRunFor (plans 4d); the reads live in those units (plans-4d-units decision); read sites unchanged, offsets moved;rev3=census-ruling-rootfs-apps-2;basis=main's body as of the merge of origin/main 9b81d97b (with main's plan rate ceiling, edge request records, regional box names, self-serve moves plan 1, plans 4d-1 lapse and its other later changes under main's own census rulings) plus the rootfs placement wiring in the activator start: an agentRootfs built from eb.NestedOK, CARLOS_DEPLOYMENT_SINGLE_TENANT, CARLOS_POOLS, the claim flag, swapArming's answer, the control client's /ready/rootfs and, on a fleet box whose identity resolved, fleetOwnerCheck over the deploy store main already opens for the fleet label (fleetStore), then arm and armedRootfs.Store; this body reads nothing new itself; the closures it wires read later, at a rootfs wake and each status tick: GET /ready/rootfs over the control socket, NestedOK's checks, and release.FleetOwnerKey for the judged row's own account and this box's fleet from the deploy store;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Tasks 7 and 11, #329 plan 3 Task 7 and plan 1 Task 7's policy cache: the control client is built once and handed to eb.Control, to the status tick (egressStatus) and to a new egressNudgeLoop goroutine; armSizeSource(svc, "/sys/fs/cgroup") after the activator Service; armPolicyCache() after armChangeIndex; statusLoop takes egressStatus. The reads are those units' own (decision rows); this body reads nothing new: the same five sites, offsets moved, in the agent; B,C,D,F authority retained.;rev3=census-ruling-remote-instance-metrics;basis=builds the metrics loop's owners closure (metricsOwners over the agent's registry, the activator and cgm.Leftover) when an activator exists and hands it to metricsLoop; reads nothing new itself;rev3=census-ruling-edge-asset-cache-3;basis=adds file:Statfs. runAgent keeps its authority (B,C,D,F). The new site is assetcache.Statfs, an exported assetcache.FS interface value (var Statfs FS = statfsFS{}), not a function value and not a call in runAgent: the ready hook passes it to armEdgeAssetCache as the store's filesystem, and armEdgeAssetCache calls its Space method on the configured data directory (dataDir(): $CARLOS_DATA_DIR, else /data), which calls unix.Statfs there (statfsFS.Space, accepted legacy at census-ruling-edge-asset-cache-2). No request-supplied pathname reaches it.;rev3=census-ruling-remote-metrics-nested;basis=main's body (merged origin/main acfa4f80, under main's own census rulings) plus: snapshots the nested layout (snapshotNestedUnits over /sys/fs/cgroup/carlos.slice/carlos-instances.slice) once at start, before the activator, and hands the metrics loop a unitSources struct (stamped units, routeHostNames, that root and the snapshot); reads nothing new itself;rev3=census-ruling-region-ha-p1a;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): wires region HA P1a into the activator: cfg.Record = haRecordFacts(openDeployStore, boxJudge) (the box's lifetime judge this body already builds with newBoxJudge, nil with host claims on; CI fix) and cfg.Self = lease.CurrentSelf; eb.Lifetimes (the process's lifetime index), eb.Registry, eb.StartupSwept (seedSweptAtStart.Load), eb.FilesStore from newProductionFilesStore (now lease.NewFilesStore, rootaws-loaded, a log line on failure) and lease.SetObligationDir(<data>/.ha-owed) (logged on failure; HA acquires then refuse); this body reads nothing new itself, the same five sites; the reads are those units' own (haRecordFacts and lease's SetObligationDir are new rows on this card); merge of origin/main d7ae1d76: main's own later changes to this body are kept as main has them, under main's rulings (census-ruling-remote-instance-metrics: the metricsOwners closure for metricsLoop; census-ruling-edge-asset-cache-3: the +file:Statfs site, assetcache.Statfs handed to the asset ready hook); this branch's change is the same as above;rev3=census-ruling-region-ha-p1b1;basis=region HA P1b-1: builds one termfence.Confirmer (Self from lease.CurrentSelf at each call, EC2 DescribeInstances method only, client from rootaws.LoadDefaultConfig with retries off, built lazily on first use) and sets eb.OwnerTerminated; this body reads nothing new itself, the same six sites;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 7: the startup Sweep literal hands its answer to startupSwept, which logs as before and, only on a clean sweep, marks rootfs admission swept (MarkRootfsSwept); same Sweep call, no read added;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (controller ruling after branch review R1, and Paul's R2 ruling): sets svc.Fleet = fleetWakeFor(os.Getenv, identity, identErr, fleetStore) from the identity it already resolves once and the deployment store the fleet loops already opened, and logs an ERROR naming the identity error when the box is on a fleet with an invalid identity. fleetWakeFor reads CARLOS_REGION and CARLOS_FLEET from the same environment. Read sites unchanged (6). Agent, not root; a platform box is unchanged.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 12: one call more beside armRunsPass, armInteractivePass(svc, reg, rolloutSink, boxJudge), in the same activator Configure hook, handing it the same box judge; fix round 1 (Astra P2, shutdown): after svc.Shutdown(ctx), shutdownInteractive(ctx) ends and joins every interactive session under the same shutdown budget; the worker's own reads are its units' (interactive.go); this body reads nothing new, the same six sites; merge of origin/main 6f1f6ca6: main's svc.Fleet = fleetWakeFor(...) and its invalid-identity ERROR line are kept as main has them (census-ruling-managed-fleets-1b); this branch's change is the same as above; read sites unchanged (6);rev3=census-ruling-fix-set-aside-exdev;basis=set-aside EXDEV fix: one field more on the agent ExecBackend literal, RawInstanceDir: layout.RawInstanceDir (a pure path join: <dataDir>/.instances/<InstanceID(host)>), so the start rule set-aside moves a copy out through the raw directory instead of through the nosymfollow bind; this body reads nothing new, the same six sites file:Exec@17216,file:Open@1150,file:Statfs@43749,registry:App@11372,whole:Route@11364,whole:Route@28004 764fa9bb232c1da7a130c86a09ff89172ef5e9f79dcf5e590ffda3d58bd88dcb |
| +internal/activator/startrule.go ExecBackend.setAsideSource legacy accepted-legacy accepted-legacy;rev3=census-ruling-fix-set-aside-exdev;basis=new: picks the directory supersede renames from. With b.RawInstanceDir set, Lstats the instance directory (from the route DBPath, as reconcileAssignment already reads it) and the raw path layout.RawInstanceDir names for the host (agent-owned /data/.instances/<id>, 0700 carlos; the id comes from the host name, not tenant input); only when both are directories and os.SameFile returns the raw path, otherwise the instance directory as before. Lstat follows no final symlink; the renames still open both directories with openat2 RESOLVE_NO_SYMLINKS. Adds two root reads (file:Lstat) of paths a tenant cannot name file:Lstat@216,file:Lstat@247 45ee09c91b7f682d49b38f430c7ae194363c547f2a1314e9a735fa41f37a3d8f |
| +@coverage internal/activator b442a017a8026920c5a033b12e027410abb3eefb3e5af3d1b2ca5248949b6120 |
| +@coverage internal/host 18d2b979d7ee74abc2a2e03fa027e93c9cb8c4d13a5fac1c0c1d99223885f076 |