instancectl: accept hashed instance IDs in the start identity check (#854)
A host over 40 bytes is keyed by a hashed instance ID that starts with "_" (provision.InstanceID). Since v0.34.34, UnitFamily checked that ID with execsandbox.ValidID, the OCI container-ID rule, which refuses a leading "_". So ValidateStartIdentity refused every unit of a long host, and the activator SIGKILLed the unit it had just started without logging why. This hit Tito staging's rootfs apps and 36 flagship hostnames. UnitFamily now checks the ID as an instance ID (validInstanceIDPart) and holds only a gVisor unit's container ID, "run-"+iid, to ValidID. New tests cover every role with a hashed host. Astra R1 READY; census re-pin of the instancectl envelope approved by Astra on #280. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from fix-rootfs-jit-kill-854 into main.
5 files changed,
+100
−1
docs/superpowers/notes/census-proposal-fix-rootfs-jit-kill-854.md+11 −0internal/instancectl/identity.go+12 −1internal/instancectl/identity_test.go+73 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-fix-rootfs-jit-kill-854.tsv+3 −0
CI passed — run details
diff --git a/docs/superpowers/notes/census-proposal-fix-rootfs-jit-kill-854.md b/docs/superpowers/notes/census-proposal-fix-rootfs-jit-kill-854.md| new file mode 100644 |
| index 000000000..a0626fa7f |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-fix-rootfs-jit-kill-854.md |
| @@ -0,0 +1,11 @@ |
| +# Census approval: fix-rootfs-jit-kill-854 |
| + |
| +Ruling `census-ruling-fix-rootfs-jit-kill-854`. 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). |
| + |
| +Envelopes re-pinned: `internal/instancectl`. |
| + |
| +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. |
| + |
| +Seal: `eea13e9a0b04164ea3fc7f8258bd1ab0a613d1e23ffe0cd028bc85058576c248` → `eea13e9a0b04164ea3fc7f8258bd1ab0a613d1e23ffe0cd028bc85058576c248`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-fix-rootfs-jit-kill-854.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/instancectl/identity.go b/internal/instancectl/identity.go| index 88ae1a189..1cdb620f6 100644 |
| --- a/internal/instancectl/identity.go |
| +++ b/internal/instancectl/identity.go |
| @@ -6,15 +6,26 @@ import ( |
| "github.com/carlosframework/platform/internal/execsandbox" |
| ) |
| +// UnitFamily reports which sandbox family runs unit, and whether unit is a |
| +// well-formed instance unit at all. The name's instance ID is checked as an |
| +// instance ID (validInstanceIDPart), not as an OCI container ID: a host |
| +// over provision.MaxInstanceID bytes is keyed by a hashed ID that starts |
| +// with "_", which execsandbox.ValidID refuses (#854). Only a gVisor unit's |
| +// ID becomes a container ID, as "run-"+iid (GVisorID), so only that is |
| +// held to execsandbox.ValidID. |
| func UnitFamily(unit string) (execsandbox.Family, bool) { |
| _, esc, ok := ParseUnitName(unit) |
| if !ok { |
| return "", false |
| } |
| - if id, ok := Unescape(esc); !ok || !execsandbox.ValidID(id) { |
| + id, ok := Unescape(esc) |
| + if !ok || !validInstanceIDPart(id) { |
| return "", false |
| } |
| if strings.HasPrefix(unit, UnitPrefixGVisor) { |
| + if !execsandbox.ValidID("run-" + id) { |
| + return "", false |
| + } |
| return execsandbox.FamilyGVisor, true |
| } |
| return execsandbox.FamilySystemd, true |
diff --git a/internal/instancectl/identity_test.go b/internal/instancectl/identity_test.go| new file mode 100644 |
| index 000000000..18d7c12da |
| --- /dev/null |
| +++ b/internal/instancectl/identity_test.go |
| @@ -0,0 +1,73 @@ |
| +package instancectl |
| + |
| +import ( |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/execsandbox" |
| + "github.com/carlosframework/platform/internal/provision" |
| +) |
| + |
| +// A host over provision.MaxInstanceID bytes is keyed by a hashed instance |
| +// ID that starts with "_" (provision.InstanceID). Every unit root starts |
| +// for it carries that ID, so the agent's check of root's answer must |
| +// accept it (#854: v0.34.34..v0.34.42 refused it and SIGKILLed the unit |
| +// it had just started). |
| +func TestValidateStartIdentityAcceptsHashedInstanceIDs(t *testing.T) { |
| + const long = "imageproxy.shop.staging.platform.example.com" |
| + if id := provision.InstanceID(long); !strings.HasPrefix(id, "_") { |
| + t.Fatalf("test host %q is not hashed (InstanceID %q); make it longer", long, id) |
| + } |
| + sys := execsandbox.EffectiveSystemd |
| + for _, tc := range []struct { |
| + name string |
| + unit string |
| + mode execsandbox.Effective |
| + role Role |
| + gen uint64 |
| + rootfs bool |
| + worker string |
| + }{ |
| + {"run", UnitName(RoleRun, long), sys, RoleRun, 0, false, ""}, |
| + {"seed", UnitName(RoleSeed, long), sys, RoleSeed, 0, false, ""}, |
| + {"cmd", UnitName(RoleCmd, long), sys, RoleCmd, 0, false, ""}, |
| + {"generation", GenUnitName(long, 7), sys, RoleRun, 7, false, ""}, |
| + {"rootfs run", RootfsUnitName(RoleRun, long), sys, RoleRun, 0, true, ""}, |
| + {"rootfs generation", RootfsGenUnitName(long, 7), sys, RoleRun, 7, true, ""}, |
| + {"rootfs worker", WorkerUnitName(long, "sidekiq"), sys, RoleWorker, 0, true, "sidekiq"}, |
| + {"gvisor run", GVisorUnitName(long), execsandbox.EffectiveGVisor, RoleRun, 0, false, ""}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + if tc.unit == "" { |
| + t.Fatal("no unit name for the long host") |
| + } |
| + if _, ok := UnitFamily(tc.unit); !ok { |
| + t.Errorf("UnitFamily(%q) refused a hashed instance ID", tc.unit) |
| + } |
| + got := StartResponse{Unit: tc.unit, Sandbox: tc.mode, InvocationID: "inv"} |
| + if err := ValidateStartIdentity(got, tc.mode, long, tc.role, tc.gen, tc.rootfs, tc.worker); err != nil { |
| + t.Errorf("ValidateStartIdentity(%q) = %v, want nil", tc.unit, err) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// The check still refuses what it exists to refuse: another host's unit, |
| +// and an instance ID no host could have. |
| +func TestValidateStartIdentityStillRefusesMismatches(t *testing.T) { |
| + const long = "imageproxy.shop.staging.platform.example.com" |
| + sys := execsandbox.EffectiveSystemd |
| + other := RootfsGenUnitName("billing.shop.staging.platform.example.com", 7) |
| + if err := ValidateStartIdentity(StartResponse{Unit: other, Sandbox: sys, InvocationID: "inv"}, sys, long, RoleRun, 7, true, ""); err == nil { |
| + t.Error("another host's generation unit was accepted") |
| + } |
| + for _, unit := range []string{ |
| + UnitPrefixRun + Escape("a/b") + ".service", |
| + UnitPrefixRun + Escape("..") + ".service", |
| + UnitPrefixGVisor + Escape("x\x00y") + ".service", |
| + } { |
| + if _, ok := UnitFamily(unit); ok { |
| + t.Errorf("UnitFamily(%q) accepted an invalid instance ID", unit) |
| + } |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 58c6ca4d9..80ba47226 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -160,3 +160,4 @@ plan14-root-reads-held-floor-capability.tsv b60c83f8ba4311222174284420b5327e9200 |
| plan14-root-reads-litestream-unit-restart.tsv e650a3ceb286df4457850d74ded9229d94ed9932057ae5b45b1d6c3d0d843ce2 |
| plan14-root-reads-health-check-no-redirects-845.tsv e650a3ceb286df4457850d74ded9229d94ed9932057ae5b45b1d6c3d0d843ce2 |
| plan14-root-reads-retry-after-503.tsv eea13e9a0b04164ea3fc7f8258bd1ab0a613d1e23ffe0cd028bc85058576c248 |
| +plan14-root-reads-fix-rootfs-jit-kill-854.tsv eea13e9a0b04164ea3fc7f8258bd1ab0a613d1e23ffe0cd028bc85058576c248 |
diff --git a/internal/provision/testdata/plan14-root-reads-fix-rootfs-jit-kill-854.tsv b/internal/provision/testdata/plan14-root-reads-fix-rootfs-jit-kill-854.tsv| new file mode 100644 |
| index 000000000..42843dac0 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-fix-rootfs-jit-kill-854.tsv |
| @@ -0,0 +1,3 @@ |
| +# Census overlay fix-rootfs-jit-kill-854, written by census-propose (#369). census-ruling-fix-rootfs-jit-kill-854, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-fix-rootfs-jit-kill-854.md. |
| +# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@coverage internal/instancectl 1362028fdff5a57bee9eb95862e2911fda0df0fd69e784fa3a751151ec536a7f |