Merge remote-tracking branch 'origin/main' into bootstrap-carlos-follows-316
# Conflicts: # internal/provision/plan14_root_reads_test.go
7 files changed,
+360
−6
internal/host/agent.go+30 −6internal/host/rootunits_test.go+88 −0internal/provision/plan14_root_reads_test.go+9 −0internal/provision/testdata/plan14-root-reads-adopt-unit-root-pass-315.tsv+7 −0internal/release/adopt.go+48 −0internal/release/rollback.go+26 −0internal/release/rootunits_test.go+152 −0
CI passed — run details
CI log
=== gate ===
go: downloading github.com/aws/aws-sdk-go-v2/service/autoscaling v1.74.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ssm v1.74.0
cd launchctx && go vet ./... && go test ./... -count=1
ok amadan.net/carlos/platform.git/launchctx 0.012s
? amadan.net/carlos/platform.git/launchctx/controlname [no test files]
? amadan.net/carlos/platform.git/launchctx/wireid [no test files]
go vet ./...
gofmt -l .: clean
go test ./... -count=1 -timeout 30m
ok github.com/carlosframework/platform 315.840s
? github.com/carlosframework/platform/cmd/changelog [no test files]
ok github.com/carlosframework/platform/cmd/console 2.743s
ok github.com/carlosframework/platform/cmd/moveprobe 93.325s
ok github.com/carlosframework/platform/cmd/zddprobe 0.710s
ok github.com/carlosframework/platform/internal/activator 250.679s
ok github.com/carlosframework/platform/internal/agentsock 0.016s
ok github.com/carlosframework/platform/internal/alerting 0.004s
ok github.com/carlosframework/platform/internal/analytics 0.019s
ok github.com/carlosframework/platform/internal/appconfig 2.471s
ok github.com/carlosframework/platform/internal/apperr 0.089s
ok github.com/carlosframework/platform/internal/applog 0.160s
ok github.com/carlosframework/platform/internal/awsinv 0.004s
ok github.com/carlosframework/platform/internal/boxchoice 0.004s
ok github.com/carlosframework/platform/internal/boxid 0.783s
? github.com/carlosframework/platform/internal/boxid/boxidtest [no test files]
? github.com/carlosframework/platform/internal/boxid/internal/signtest [no test files]
ok github.com/carlosframework/platform/internal/boxvolumes 0.011s
ok github.com/carlosframework/platform/internal/caps 0.012s
ok github.com/carlosframework/platform/internal/certwarm 0.002s
ok github.com/carlosframework/platform/internal/cgroup 0.707s
ok github.com/carlosframework/platform/internal/changelog 0.316s
ok github.com/carlosframework/platform/internal/claimactivation 0.803s
ok github.com/carlosframework/platform/internal/clamd 0.064s
? github.com/carlosframework/platform/internal/cliflag [no test files]
ok github.com/carlosframework/platform/internal/console 408.413s
? github.com/carlosframework/platform/internal/controlname [no test files]
? github.com/carlosframework/platform/internal/controlsock [no test files]
ok github.com/carlosframework/platform/internal/dbdoor 6.081s
ok github.com/carlosframework/platform/internal/dbdoor/dbdoortest 0.010s
ok github.com/carlosframework/platform/internal/dbverify 0.005s
ok github.com/carlosframework/platform/internal/dnsrec 0.003s
ok github.com/carlosframework/platform/internal/docsite 0.005s
ok github.com/carlosframework/platform/internal/domains 2.369s
ok github.com/carlosframework/platform/internal/doorkey 0.006s
ok github.com/carlosframework/platform/internal/economics 0.004s
ok github.com/carlosframework/platform/internal/edge 45.123s
? github.com/carlosframework/platform/internal/edgeproof [no test files]
ok github.com/carlosframework/platform/internal/edgesfile 0.009s
ok github.com/carlosframework/platform/internal/fleetapi 0.132s
ok github.com/carlosframework/platform/internal/gate 1.655s
ok github.com/carlosframework/platform/internal/genselect 0.016s
ok github.com/carlosframework/platform/internal/geo 0.015s
ok github.com/carlosframework/platform/internal/geoip 0.032s
ok github.com/carlosframework/platform/internal/historyreadback 0.153s
ok github.com/carlosframework/platform/internal/host 181.314s
ok github.com/carlosframework/platform/internal/hostactors 6.206s
ok github.com/carlosframework/platform/internal/hostactors/awsmembership 0.015s
ok github.com/carlosframework/platform/internal/hostbox 2.777s
ok github.com/carlosframework/platform/internal/hostclaim 0.572s
ok github.com/carlosframework/platform/internal/hostenv 0.015s
ok github.com/carlosframework/platform/internal/hostevidence 0.015s
ok github.com/carlosframework/platform/internal/hostexec 5.336s
ok github.com/carlosframework/platform/internal/hostfence 0.040s
ok github.com/carlosframework/platform/internal/hostfiles 10.653s
ok github.com/carlosframework/platform/internal/hostfloor 0.015s
ok github.com/carlosframework/platform/internal/hostguard 0.995s
ok github.com/carlosframework/platform/internal/hostops 1.604s
? github.com/carlosframework/platform/internal/hostops/fencerelease [no test files]
ok github.com/carlosframework/platform/internal/hostops/internal/fencerelease 0.020s
ok github.com/carlosframework/platform/internal/hostquarantine 0.015s
ok github.com/carlosframework/platform/internal/hostrelocate 0.427s
ok github.com/carlosframework/platform/internal/hostresolve 0.156s
ok github.com/carlosframework/platform/internal/hostwrite 0.014s
ok github.com/carlosframework/platform/internal/infraview 0.016s
ok github.com/carlosframework/platform/internal/instancectl 5.256s
ok github.com/carlosframework/platform/internal/instanceexec 2.754s
ok github.com/carlosframework/platform/internal/instancefs 0.020s
ok github.com/carlosframework/platform/internal/instancekey 0.015s
ok github.com/carlosframework/platform/internal/instanceupdates 0.022s
ok github.com/carlosframework/platform/internal/layout 1.573s
ok github.com/carlosframework/platform/internal/lbhealth 0.002s
ok github.com/carlosframework/platform/internal/lease 9.815s
ok github.com/carlosframework/platform/internal/lease/leasetest 0.006s
ok github.com/carlosframework/platform/internal/ledger 0.016s
ok github.com/carlosframework/platform/internal/mail 0.171s
ok github.com/carlosframework/platform/internal/maintenance 0.077s
ok github.com/carlosframework/platform/internal/maintenanceexec 5.540s
ok github.com/carlosframework/platform/internal/maintenanceguard 0.081s
ok github.com/carlosframework/platform/internal/metrics 0.005s
ok github.com/carlosframework/platform/internal/moves 21.165s
ok github.com/carlosframework/platform/internal/moves/archive 0.794s
ok github.com/carlosframework/platform/internal/objstore 0.186s
ok github.com/carlosframework/platform/internal/ops 0.175s
ok github.com/carlosframework/platform/internal/park 0.203s
ok github.com/carlosframework/platform/internal/privatefile 0.005s
ok github.com/carlosframework/platform/internal/provision 38.193s
ok github.com/carlosframework/platform/internal/publicrelease 0.012s
? github.com/carlosframework/platform/internal/regionname [no test files]
ok github.com/carlosframework/platform/internal/registry 5.538s
ok github.com/carlosframework/platform/internal/relay 7.254s
ok github.com/carlosframework/platform/internal/release 24.591s
ok github.com/carlosframework/platform/internal/rollout 3.961s
ok github.com/carlosframework/platform/internal/rolloutwords 0.003s
ok github.com/carlosframework/platform/internal/rootaws 0.007s
ok github.com/carlosframework/platform/internal/rootparticipation 0.058s
ok github.com/carlosframework/platform/internal/rootstate 0.026s
ok github.com/carlosframework/platform/internal/runs 0.572s
ok github.com/carlosframework/platform/internal/s3compat 0.005s
ok github.com/carlosframework/platform/internal/safefile 0.004s
ok github.com/carlosframework/platform/internal/schedule 2.543s
ok github.com/carlosframework/platform/internal/seeds 0.011s
ok github.com/carlosframework/platform/internal/sim/hostlife 10.341s
ok github.com/carlosframework/platform/internal/sim/litestreamfacts 3.558s
ok github.com/carlosframework/platform/internal/status 0.061s
ok github.com/carlosframework/platform/internal/steering 0.006s
ok github.com/carlosframework/platform/internal/stopevidence 0.221s
ok github.com/carlosframework/platform/internal/svcrole 0.002s
ok github.com/carlosframework/platform/internal/telemetry 0.004s
ok github.com/carlosframework/platform/internal/termfence 0.004s
ok github.com/carlosframework/platform/internal/tunnelclient 0.004s
ok github.com/carlosframework/platform/internal/unixdial 0.003s
ok github.com/carlosframework/platform/internal/updatewords 0.008s
ok github.com/carlosframework/platform/internal/usage 0.005s
ok github.com/carlosframework/platform/internal/version 0.002s
ok github.com/carlosframework/platform/internal/vet 1.590s
=== cross ===
--- shard 0 of 5 ---
cross-compiling darwin/arm64
--- shard 1 of 5 ---
cross-compiling darwin/amd64
--- shard 2 of 5 ---
cross-compiling linux/arm64
linux/arm64 carlos binary: 49414306 bytes (ceiling 52000000)
--- shard 3 of 5 ---
cross-compiling windows/amd64
--- shard 4 of 5 ---
cross-compiling windows/arm64
=== minio-contract ===
minio contract: arm64, minio RELEASE.2025-09-07T16-13-09Z, mc RELEASE.2025-08-13T08-35-41Z
minio: downloading https://github.com/minio/minio/releases/download/RELEASE.2025-09-07T16-13-09Z/minio.linux-arm64.RELEASE.2025-09-07T16-13-09Z
minio: downloaded, digest verified
mc: downloading https://github.com/minio/mc/releases/download/RELEASE.2025-08-13T08-35-41Z/mc.linux-arm64.RELEASE.2025-08-13T08-35-41Z
mc: downloaded, digest verified
minio healthy on 127.0.0.1:20999
Added `local` successfully.
Bucket created successfully `local/contract-bucket`.
Bucket created successfully `local/denied-bucket`.
Created policy `contract-only` successfully.
Added user `scopeduser` successfully.
Attached Policies: [contract-only]
To User: scopeduser
buckets and scoped user ready
=== RUN TestDeliveredContractMinio
=== RUN TestDeliveredContractMinio/put
=== RUN TestDeliveredContractMinio/get_round-trips_the_body
=== RUN TestDeliveredContractMinio/list_shows_the_key
=== RUN TestDeliveredContractMinio/head_and_list_agree_on_the_version
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_its_own_object
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_its_own_object/not_by_PutObjectTagging
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_its_own_object/and_not_by_x-amz-tagging_on_upload
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/not_by_CreateMultipartUpload
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/not_by_CopyObject_with_a_REPLACE_tagging_directive
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/but_multipart_itself_is_allowed
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/and_copy_itself_is_allowed
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/a_POST-policy_forged_tag_with_a_matching_version_is_still_not_a_verdict
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/and_an_ordinary_tagged-with-something-else_upload_is_allowed
=== RUN TestDeliveredContractMinio/delete_removes_it
=== RUN TestDeliveredContractMinio/cross-bucket_denial
--- PASS: TestDeliveredContractMinio (0.02s)
--- PASS: TestDeliveredContractMinio/put (0.00s)
--- PASS: TestDeliveredContractMinio/get_round-trips_the_body (0.00s)
--- PASS: TestDeliveredContractMinio/list_shows_the_key (0.00s)
--- PASS: TestDeliveredContractMinio/head_and_list_agree_on_the_version (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_its_own_object (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_its_own_object/not_by_PutObjectTagging (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_its_own_object/and_not_by_x-amz-tagging_on_upload (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route (0.01s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/not_by_CreateMultipartUpload (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/not_by_CopyObject_with_a_REPLACE_tagging_directive (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/but_multipart_itself_is_allowed (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/and_copy_itself_is_allowed (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/a_POST-policy_forged_tag_with_a_matching_version_is_still_not_a_verdict (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/and_an_ordinary_tagged-with-something-else_upload_is_allowed (0.00s)
--- PASS: TestDeliveredContractMinio/delete_removes_it (0.00s)
--- PASS: TestDeliveredContractMinio/cross-bucket_denial (0.00s)
PASS
ok github.com/carlosframework/platform/internal/objstore 0.024s
=== RUN TestT4StorageProbeMinio
2026/10/20 00:25:47 moves: T4: STORE: list: operation error S3: ListObjectsV2, https response error StatusCode: 403, RequestID: 18E0152FFDC110F0, HostID: 7c420053e0fbcd7f41653fdd92ffa2802c903d05303b1aa15adc2e8bb65d183f, api error SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
--- PASS: TestT4StorageProbeMinio (0.01s)
PASS
ok github.com/carlosframework/platform/internal/host 0.021s
minio contract: PASS
diff --git a/internal/host/agent.go b/internal/host/agent.go| index 5ccaa3955..bb9e33fea 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -1295,14 +1295,19 @@ func adoptLoop(reg *registry.Registry, svc *activator.Service, sd *scheduleDeps, |
| // DO NOT add the platform self-update here either: the system leg |
| // lives in the fast loop and re-observes hourly on its own, so an |
| // hourly call here would only double the pointer read. |
| - if err := release.Pass(ctx, reg, store, pub, optDir, restart, |
| + // |
| + // agentUnitsOption hands named units to root when this process is |
| + // not root (issue #315), which leaves WithStartUnit and |
| + // WithRollbackRestart to an agent run as root. |
| + opts := append([]release.PassOption{ |
| release.BakeDir(dataDir()), release.OnStageBlocked(stageRequester(dataDir())), |
| release.RestartHibernating(restart), |
| release.WithStartUnit(makeStartRoute(reg, systemctlStartUnit)), |
| release.WithRollbackRestart(agentRollbackUnitRestart(reg, systemdUnits{}, optDir, os.Getenv)), |
| release.WithProofGate(agentProofGate()), release.WithHostWrites(writes), |
| release.WithDigestRatchet(pointerRatchet(false, optDir, dataDir(), os.Getenv)), |
| - updatesPassOption(dataDir(), false)); err != nil { |
| + updatesPassOption(dataDir(), false)}, agentUnitsOption()...) |
| + if err := release.Pass(ctx, reg, store, pub, optDir, restart, opts...); err != nil { |
| log.Printf("agent: adopt pass: %v", err) |
| } |
| // The schedule converge's hourly floor (schedule spec §6.2), AFTER the |
| @@ -1727,9 +1732,10 @@ func stageMarkerRequester(dd string) func(host, ver string, err error) { |
| } |
| // One line for every cause the marker relays (Task 12a): a build |
| // this process cannot stage, an install request only root |
| - // resolves (ErrInstallRequestNeedsRoot), and a held wake's target |
| - // only root installs. The throttle does not carry the cause. |
| - log.Printf("agent: %s needs a root pass for %s (a build only root can stage or install, or an install request only root resolves); asked for one", host, ver) |
| + // resolves (ErrInstallRequestNeedsRoot), a named unit only root |
| + // restarts (ErrUnitRestartNeedsRoot), and a held wake's target only |
| + // root installs. The throttle does not carry the cause. |
| + log.Printf("agent: %s needs a root pass for %s (a build only root can stage or install, a unit only root can restart, or an install request only root resolves); asked for one", host, ver) |
| }) |
| } |
| @@ -2020,8 +2026,11 @@ type restartFailure struct { |
| // did not already need, and it cannot fire for a sleeper: only an |
| // ERRORED restart reaches it, and every arm that can meet a sleeping |
| // route swallows its failure. |
| +// |
| +// unitsOption hands named units to root when this process is not root |
| +// (issue #315); see agentUnitsOption. |
| func fastPassOpts(dd string, stageReq func(host, ver string, err error), restart, start func(string) error) []release.PassOption { |
| - return []release.PassOption{ |
| + return append([]release.PassOption{ |
| release.BakeDir(dd), |
| release.OnStageBlocked(stageReq), |
| release.RestartHibernating(restart), |
| @@ -2031,7 +2040,22 @@ func fastPassOpts(dd string, stageReq func(host, ver string, err error), restart |
| // resolves. The book is opened per pass, not here: these options are |
| // built once per agent run. |
| updatesPassOption(dd, false), |
| + }, agentUnitsOption()...) |
| +} |
| + |
| +// agentRunsAsRoot is the agent's euid test, a seam for tests. |
| +var agentRunsAsRoot = func() bool { return os.Geteuid() == 0 } |
| + |
| +// agentUnitsOption is release.RootRestartsUnits for an agent that is not |
| +// root (issue #315). carlos-edge.service runs as User=carlos, and systemd |
| +// refuses that user a restart of any unit a route names, so a named-unit |
| +// route goes to the root pass through the stage relay before anything moves. |
| +// An agent run as root restarts the unit itself, as before. |
| +func agentUnitsOption() []release.PassOption { |
| + if agentRunsAsRoot() { |
| + return nil |
| } |
| + return []release.PassOption{release.RootRestartsUnits()} |
| } |
| // fastMembers computes the fast set for one tick — the routes with a reason |
diff --git a/internal/host/rootunits_test.go b/internal/host/rootunits_test.go| new file mode 100644 |
| index 000000000..6c2df491a |
| --- /dev/null |
| +++ b/internal/host/rootunits_test.go |
| @@ -0,0 +1,88 @@ |
| +package host |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "runtime" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// Issue #315, through the fast loop's production options: an agent that is |
| +// not root hands a named-unit route to root's pass rather than repointing it |
| +// and failing systemd's permission check. An agent run as root keeps |
| +// restarting the unit itself. |
| +func TestFastSweepHandsANamedUnitToRoot(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + root bool |
| + }{{"agent user", false}, {"root", true}} { |
| + t.Run(tc.name, func(t *testing.T) { |
| + was := agentRunsAsRoot |
| + agentRunsAsRoot = func() bool { return tc.root } |
| + t.Cleanup(func() { agentRunsAsRoot = was }) |
| + |
| + env := newFastFixture(t) |
| + ctx := context.Background() |
| + plat := runtime.GOOS + "-" + runtime.GOARCH |
| + for _, v := range []string{"v1", "v2"} { |
| + m := release.Manifest{App: "fastapp", Version: v, Kind: "binary", |
| + Artifacts: map[string]release.Artifact{plat: {}}} |
| + if err := release.Ship(ctx, env.store, "bab", m, map[string][]byte{plat: []byte("build " + v)}); err != nil { |
| + t.Fatalf("Ship %s: %v", v, err) |
| + } |
| + } |
| + if err := release.Promote(ctx, env.store, env.priv, "bab", "fastapp", "canary/dev", "v1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := env.reg.Upsert(registry.Route{Host: "console.test", Kind: "instance", App: "fastapp", |
| + Channel: "canary/dev", Status: "ready", Addr: "127.0.0.1:8090"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := release.Pass(ctx, env.reg, env.store, env.pub, env.optDir, nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := env.reg.SetUnit("console.test", "console.service"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := release.Promote(ctx, env.store, env.priv, "bab", "fastapp", "canary/dev", "v2"); err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + var unitRestarts []string |
| + restart := makeRestartRoute(env.reg, func(string) {}, |
| + unitOnly(func(u string) error { unitRestarts = append(unitRestarts, u); return nil }), nil) |
| + var relayed []error |
| + stageReq := func(host, ver string, err error) { |
| + if host == "console.test" && ver == "v2" { |
| + relayed = append(relayed, err) |
| + } |
| + } |
| + d := env.deps(nil) |
| + d.restart = restart |
| + d.passOpts = fastPassOpts(env.dataDir, stageReq, restart, nil) |
| + |
| + fastTick(ctx, d, time.Unix(1754640000, 0)) |
| + |
| + live, err := release.LiveVersion(env.optDir, "console.test") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if tc.root { |
| + if live != "v2" || len(unitRestarts) != 1 || len(relayed) != 0 { |
| + t.Fatalf("root agent: live %q, unit restarts %v, relays %v; want v2, one restart, no relay", live, unitRestarts, relayed) |
| + } |
| + return |
| + } |
| + if live != "v1" || len(unitRestarts) != 0 { |
| + t.Fatalf("agent user: live %q, unit restarts %v; want v1 untouched and no restart", live, unitRestarts) |
| + } |
| + if len(relayed) != 1 || !errors.Is(relayed[0], release.ErrUnitRestartNeedsRoot) { |
| + t.Fatalf("relays = %v, want one ErrUnitRestartNeedsRoot", relayed) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/provision/plan14_root_reads_test.go b/internal/provision/plan14_root_reads_test.go| index c9c8e9b54..1175ecad9 100644 |
| --- a/internal/provision/plan14_root_reads_test.go |
| +++ b/internal/provision/plan14_root_reads_test.go |
| @@ -933,6 +933,15 @@ func TestPlan14RootReadCensus(t *testing.T) { |
| if err = loadRootReadInventory(filepath.Join(root, "internal/provision/testdata/plan14-root-reads-claim-guard-umask.tsv"), &inv, true); err != nil { |
| t.Fatal(err) |
| } |
| + // Census overlay adopt-unit-root-pass-315 (amadan #315: a non-root agent |
| + // hands a named unit's routes to the root pass), loaded last. PROPOSED-315, |
| + // ruling asked of the census owner on #280: adoptHost re-pinned at its |
| + // class, type passConfig gains a bool, and unitServed (new) classified |
| + // with processGroup, whose membership it inverts. Both envelopes |
| + // re-pinned. It adds no accepted-legacy row, so the seal stands. |
| + if err = loadRootReadInventory(filepath.Join(root, "internal/provision/testdata/plan14-root-reads-adopt-unit-root-pass-315.tsv"), &inv, true); err != nil { |
| + t.Fatal(err) |
| + } |
| // Census overlay bootstrap-carlos-follows-316 (amadan #316: system status |
| // compares bootstrap/carlos with stable's build), loaded last. Envelope |
| // only, proposed; ruling asked of the census owner on #280. The seal |
diff --git a/internal/provision/testdata/plan14-root-reads-adopt-unit-root-pass-315.tsv b/internal/provision/testdata/plan14-root-reads-adopt-unit-root-pass-315.tsv| new file mode 100644 |
| index 000000000..2844ab497 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-adopt-unit-root-pass-315.tsv |
| @@ -0,0 +1,7 @@ |
| +# Census overlay adopt-unit-root-pass-315 (amadan #315: a non-root agent hands named-unit routes and their process group to the root pass), loaded LAST, after claim-guard-umask. Proposed; ruling asked of the census owner on #280. |
| +# adoptHost re-pinned at its class and task: the new hand-off precedes staging and only returns. type passConfig gains a bool. unitServed (new) reads registry routes exactly as processGroup does and classifies with it. carlos adopt (root) never sets RootRestartsUnits, so root reads are unchanged. The seal stands: no accepted-legacy row. |
| +@coverage internal/release 4aafab144b1b742b27cab13ded61276b5203a64eb94f12203b6b94adddd0ae83 |
| +@coverage internal/host c589ae17ec476291bd5cd103f10909b55ddcacdc1bddff76800078133766665e |
| +internal/release/adopt.go adoptHost authority B3,E1,E2,E3,E4,J1 E16: root first-registration creation evidence under release exclusion; exact installation identity is required for first-program adoption and is consumed before an attempt. Installed-program history comes from the verified claim launch. Fixtures: TestPlan14FreshInstallRegistration, TestPlan14FreshInstallProgramGate, TestPlan14FreshInstallCanonicalIdentity, TestPlan14FreshInstallLaunchObservation, TestPlan14InstalledLaunchProgramEvidence, TestPlan14FreshInstallProcessCrash, TestPlan14FreshInstallVisibleSync, TestClaimControlUnitInstallers. E22: root generation pins guard existing-tree artifact and manifest writes in adoption and moves-held staging/publication. Held snapshot is read under release exclusion before the leaf held-stage lock; failures remain restrictive for writes. Claims-off source returns no root pins. Fresh wholly absent version trees retain signed staging. Fixtures: TestPlan14GenerationSiblingWrites, TestPlan14GenerationVerifiedSiblingWrites, TestPlan14GenerationHeldStage (production source assembly, both flag values without census, lock order, pin/error/fresh cases). Production completeness remains unavailable; no new completeness grant.;rev3=PROPOSED-p3;run=8;identity=carlos adopt uid 0; legacy agent pass uid carlos;basis=applies root settings to canonically resolved routes including named units while legacy settings eligibility remains unchanged;rev3=PROPOSED-p3;run=16;basis=P3-R11 approved punctuation edit only; authority and reads unchanged;rev3=PROPOSED-315;identity=legacy agent pass uid carlos (RootRestartsUnits; never set on carlos adopt);basis=a non-root agent pass hands a route its named unit serves (unitServed) to root through the stage relay before staging or repointing; root adopt reads unchanged registry:App@11360,registry:App@11520,registry:App@12549,registry:App@13475,registry:App@15054,registry:App@20213,registry:App@25689,registry:App@3144,registry:App@33448,registry:App@6758,registry:App@8059,registry:App@8253,registry:Hibernate@34309,registry:Host@10484,registry:Host@11240,registry:Host@11273,registry:Host@11373,registry:Host@11533,registry:Host@11635,registry:Host@11667,registry:Host@11732,registry:Host@12182,registry:Host@12315,registry:Host@12762,registry:Host@12871,registry:Host@13073,registry:Host@13565,registry:Host@14351,registry:Host@14826,registry:Host@15040,registry:Host@15382,registry:Host@15972,registry:Host@19703,registry:Host@19811,registry:Host@20181,registry:Host@21001,registry:Host@2105,registry:Host@21159,registry:Host@21621,registry:Host@21673,registry:Host@21820,registry:Host@21907,registry:Host@2294,registry:Host@23013,registry:Host@23257,registry:Host@2375,registry:Host@23917,registry:Host@24302,registry:Host@24443,registry:Host@25657,registry:Host@25784,registry:Host@27126,registry:Host@27776,registry:Host@31009,registry:Host@3157,registry:Host@31627,registry:Host@31952,registry:Host@32026,registry:Host@32273,registry:Host@32424,registry:Host@33620,registry:Host@33787,registry:Host@33894,registry:Host@34122,registry:Host@34265,registry:Host@35010,registry:Host@35136,registry:Host@35224,registry:Host@4469,registry:Host@4583,registry:Host@5546,registry:Host@5651,registry:Host@6870,registry:Host@6918,registry:Host@7035,registry:Host@7067,registry:Host@7945,registry:Host@8113,registry:Host@8239,registry:Host@8358,registry:Host@8836,registry:Host@9223,registry:Host@9449,registry:Host@9545,registry:Host@9636,registry:Kind@554,registry:Unit@32172,registry:Unit@579,whole:Route@10073,whole:Route@10427,whole:Route@11355,whole:Route@11515,whole:Route@12539,whole:Route@13465,whole:Route@15022,whole:Route@15587,whole:Route@15948,whole:Route@17171,whole:Route@17474,whole:Route@17630,whole:Route@19960,whole:Route@20104,whole:Route@20203,whole:Route@2206,whole:Route@22742,whole:Route@23141,whole:Route@25679,whole:Route@30580,whole:Route@3139,whole:Route@33596,whole:Route@3595,whole:Route@4347,whole:Route@6753 219694d85c22b7886a4ebc62be97888bf993af79d5c0df134b95e0480b2db992 |
| +internal/release/adopt.go type passConfig authority E2,E3 E19: both destructive readers use the root reservation snapshot under existing release exclusion. Exact artifact and containing-tree identities are retained; missing completeness refuses destruction. Production installation/launch/kernel completeness and verified retirement remain unfinished. Fixtures: TestPlan14GenerationDeletionCannotUnpin, TestPlan14GenerationSnapshotCompleteness, TestPlan14GenerationSnapshotPermitsUnreservedRestage, TestPlan14GenerationSnapshotPinsContainingTree, TestPlan14GenerationSnapshotEmptyIsUnknown, TestPlan14GenerationConsumerMode, TestPlan14GenerationProductionModeGate, TestPlan14GenerationSnapshotPermitsFreshTree.;rev3=PROPOSED-p3;run=8;identity=carlos adopt uid 0; legacy agent pass uid carlos;basis=stores the typed census-only root update provider and per-pass resolved input authority;rev3=PROPOSED-315;identity=legacy agent pass uid carlos (RootRestartsUnits; never set on carlos adopt);basis=adds the unitsToRoot bool set by RootRestartsUnits; reads nothing 60131fde0633bcee3db957f9f898b6e9eef96f1a84f2f2f03a7ab0d9b05db6ad |
| +internal/release/rollback.go unitServed authority B3,E1,E3,J1 root-route;kept=B3,E1,E3;scope=protected-decision-only;rev3=PROPOSED-315;identity=legacy agent pass uid carlos (RootRestartsUnits; never set on carlos adopt);basis=processGroup membership inverted (same account, app, channel and non-empty upstream as a route naming a unit); only ever narrows the agent pass to a hand-off; a registry list failure hands off; no file read registry:App@281,registry:App@290,registry:Host@244,registry:Host@254,registry:Unit@265,registry:Unit@70,whole:Route@119,whole:Route@233,whole:Route@316,whole:Route@335,whole:Route@351,whole:Route@379,whole:Route@398 fef7b67b13241535f225f634f776d2822837a734ca6a25ea732ef37d9b7909e9 |
diff --git a/internal/release/adopt.go b/internal/release/adopt.go| index da914a81c..2867b8797 100644 |
| --- a/internal/release/adopt.go |
| +++ b/internal/release/adopt.go |
| @@ -86,6 +86,11 @@ type passConfig struct { |
| // is consulted for them at all. |
| restartHibernating func(host string) error |
| + // unitsToRoot hands every route that names its own unit to the root pass |
| + // before anything is staged or repointed (RootRestartsUnits). false, the |
| + // default and RunAdopt's, restarts the named unit in this pass. |
| + unitsToRoot bool |
| + |
| // startUnit is consulted ONLY on adoptHost's restart-failure rollback |
| // path, after the symlink has gone back (WithStartUnit). nil — every |
| // call site that does not pass the option, and every existing test — |
| @@ -154,6 +159,40 @@ type FailedBuild func(acct, app, build, host string, served bool) bool |
| // this pass sees it. Never shown to members. |
| var ErrInstallRequestNeedsRoot = errors.New("release: an install request waits for root's pass to resolve it") |
| +// ErrUnitRestartNeedsRoot is what a RootRestartsUnits pass hands |
| +// OnStageBlocked's callback for a route that names its own unit: nothing |
| +// failed, and the version is the build root's pass should install. Never |
| +// shown to members. |
| +var ErrUnitRestartNeedsRoot = errors.New("release: a route's named unit is restarted by root's pass") |
| + |
| +// RootRestartsUnits is for a pass whose process cannot restart a unit an |
| +// operator named (issue #315): the agent's in-process loops when they do not |
| +// run as root. carlos-edge.service is User=carlos, and systemd refuses it |
| +// ("Interactive authentication required") for console.service and every |
| +// other route.Unit. Before this option such a pass repointed the live link, |
| +// failed the restart, read the refusal as a broken build, rolled back, |
| +// poisoned the version and tried to start the old build over a process that |
| +// had never stopped. |
| +// |
| +// With it, a route that names its unit, and every route in that unit's |
| +// process group (processGroup: same account, app, channel and upstream), is |
| +// handed to root before anything is staged or repointed, through |
| +// OnStageBlocked with ErrUnitRestartNeedsRoot, the way a build this process |
| +// cannot stage is. The live links keep naming the running build, so no |
| +// sibling is stamped with a build the unit does not run. Nothing is poisoned |
| +// and no refusal is recorded; root's |
| +// pass stages, repoints, restarts and stamps. Every hold, refusal and proof |
| +// check before the hand-off still applies, so root is only asked for a build |
| +// this pass would have installed. |
| +// |
| +// Lifecycle host writes (WithHostWrites) restart through the selected |
| +// receiver instead, so the option does nothing under them. Nor for a route |
| +// this pass would not restart (restart nil: a sleeper on a pass without |
| +// RestartHibernating, a sidecar). |
| +func RootRestartsUnits() PassOption { |
| + return func(c *passConfig) { c.unitsToRoot = true } |
| +} |
| + |
| // NagExpiredCanaries opts a Pass/PassFilter call into spec §5's nag: one |
| // line per expired canary/* route the call sees, written to w. |
| // |
| @@ -1483,6 +1522,15 @@ func adoptHost(ctx context.Context, work hostwrite.Work, reg *registry.Registry, |
| if !admitted { |
| return |
| } |
| + // A named unit this process cannot restart is root's (RootRestartsUnits), |
| + // and so is every route its process serves: ask for root's pass and touch |
| + // nothing. Silent on the tick; the requester logs each request it writes. |
| + if cfg.unitsToRoot && restart != nil && !cfg.hostWrites.Enabled && unitServed(reg, rt) { |
| + if cfg.stageBlocked != nil { |
| + cfg.stageBlocked(rt.Host, ver, ErrUnitRestartNeedsRoot) |
| + } |
| + return |
| + } |
| // The evidence that authorizes ver (settings spec §4.1). Only today's |
| // adoption of the head, and a request whose T is still the head, rest on |
| // the signed pointer and its digest; everything else needs a promotion |
diff --git a/internal/release/rollback.go b/internal/release/rollback.go| index dcdbe3831..830a0f6cf 100644 |
| --- a/internal/release/rollback.go |
| +++ b/internal/release/rollback.go |
| @@ -66,6 +66,32 @@ func processGroup(reg *registry.Registry, bound registry.Route) []registry.Route |
| return out |
| } |
| +// unitServed reports whether rt's process is a unit an operator named: rt |
| +// names one itself, or rt is in the processGroup of a route that does. A |
| +// registry that cannot be listed answers true, so a RootRestartsUnits pass |
| +// hands the route to root rather than stamp a build the unit may not run. |
| +func unitServed(reg *registry.Registry, rt registry.Route) bool { |
| + if rt.Unit != "" { |
| + return true |
| + } |
| + up := upstream(rt) |
| + if up == "" { |
| + return false |
| + } |
| + all, err := reg.List() |
| + if err != nil { |
| + return true |
| + } |
| + for _, r := range all { |
| + if r.Host != rt.Host && r.Unit != "" && r.App == rt.App && |
| + RouteAccount(r) == RouteAccount(rt) && upstream(r) == up && |
| + routeChannel(r) == routeChannel(rt) { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| // rollbackGroup puts every group route whose link names the rejected version |
| // onto restored (what bound now runs), stamps it to match, and returns bound |
| // and every group host: the hosts writeGroupRefusals refuses. restored "" |
diff --git a/internal/release/rootunits_test.go b/internal/release/rootunits_test.go| new file mode 100644 |
| index 000000000..497e81219 |
| --- /dev/null |
| +++ b/internal/release/rootunits_test.go |
| @@ -0,0 +1,152 @@ |
| +package release |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "testing" |
| +) |
| + |
| +// Issue #315: a pass that cannot restart a named unit (the agent, User=carlos) |
| +// hands that route to root before it stages or repoints anything. The live |
| +// link keeps naming the running build, the version is not poisoned for the |
| +// other hosts in the pass, and root's pass then installs it normally. |
| +func TestRootRestartsUnitsHandsNamedUnitsToRoot(t *testing.T) { |
| + ctx := context.Background() |
| + s := NewDirStore(t.TempDir()) |
| + priv, pub := testKeys(t) |
| + opt := t.TempDir() |
| + reg := testRegistry(t) |
| + t.Cleanup(func() { reg.Close() }) |
| + const consoleHost, appHost = "console.example.com", "shop.example.com" |
| + for _, ver := range []string{"v1", "v2"} { |
| + shipRelease(t, s, "bab", "myapp", ver, adoptPlatform, []byte(ver)) |
| + } |
| + if err := Promote(ctx, s, priv, "bab", "myapp", "canary/x", "v1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + addRoute(t, reg, consoleHost, "myapp", "canary/x", false) |
| + addRoute(t, reg, appHost, "myapp", "canary/x", false) |
| + if err := Pass(ctx, reg, s, pub, opt, nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.SetUnit(consoleHost, "console.service"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := Promote(ctx, s, priv, "bab", "myapp", "canary/x", "v2"); err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + var restarted []string |
| + restart := func(host string) error { |
| + restarted = append(restarted, host) |
| + if host == consoleHost { |
| + return errors.New("try-restart console.service: Interactive authentication required") |
| + } |
| + return nil |
| + } |
| + type req struct { |
| + host, ver string |
| + err error |
| + } |
| + var reqs []req |
| + relay := func(host, ver string, err error) { reqs = append(reqs, req{host, ver, err}) } |
| + |
| + if err := Pass(ctx, reg, s, pub, opt, restart, OnStageBlocked(relay), RootRestartsUnits()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(reqs) != 1 || reqs[0].host != consoleHost || reqs[0].ver != "v2" || !errors.Is(reqs[0].err, ErrUnitRestartNeedsRoot) { |
| + t.Fatalf("relays = %+v, want one for %s v2 with ErrUnitRestartNeedsRoot", reqs, consoleHost) |
| + } |
| + if len(restarted) != 1 || restarted[0] != appHost { |
| + t.Fatalf("restarted = %v, want only %s", restarted, appHost) |
| + } |
| + if ver, err := LiveVersion(opt, consoleHost); err != nil || ver != "v1" { |
| + t.Fatalf("%s live = %q, %v; want v1 (untouched)", consoleHost, ver, err) |
| + } |
| + if rt, err := reg.Get(consoleHost); err != nil || rt == nil || rt.Version != "v1" { |
| + t.Fatalf("%s route = %+v, %v; want stamped v1", consoleHost, rt, err) |
| + } |
| + if ver, err := LiveVersion(opt, appHost); err != nil || ver != "v2" { |
| + t.Fatalf("%s live = %q, %v; want v2 (not poisoned by the hand-off)", appHost, ver, err) |
| + } |
| + if r, err := ReadRefusal(opt, consoleHost); err != nil || r != nil { |
| + t.Fatalf("refusal for %s = %+v, %v; want none", consoleHost, r, err) |
| + } |
| + |
| + // Root's pass, without the option, installs it. |
| + restarted = nil |
| + rootRestart := func(host string) error { restarted = append(restarted, host); return nil } |
| + if err := Pass(ctx, reg, s, pub, opt, rootRestart); err != nil { |
| + t.Fatal(err) |
| + } |
| + if ver, err := LiveVersion(opt, consoleHost); err != nil || ver != "v2" || len(restarted) != 1 || restarted[0] != consoleHost { |
| + t.Fatalf("root pass: %s live = %q, %v, restarted %v; want v2 and one restart", consoleHost, ver, err, restarted) |
| + } |
| +} |
| + |
| +// The option hands nothing over for a route this pass would not restart, and |
| +// leaves routes with no unit to the pass. |
| +func TestRootRestartsUnitsNeedsANamedUnitAndARestart(t *testing.T) { |
| + ctx := context.Background() |
| + s := NewDirStore(t.TempDir()) |
| + priv, pub := testKeys(t) |
| + opt := t.TempDir() |
| + reg := testRegistry(t) |
| + t.Cleanup(func() { reg.Close() }) |
| + const host = "console.example.com" |
| + shipRelease(t, s, "bab", "myapp", "v1", adoptPlatform, []byte("v1")) |
| + if err := Promote(ctx, s, priv, "bab", "myapp", "canary/x", "v1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + addRoute(t, reg, host, "myapp", "canary/x", false) |
| + if err := reg.SetUnit(host, "console.service"); err != nil { |
| + t.Fatal(err) |
| + } |
| + relays := 0 |
| + relay := func(string, string, error) { relays++ } |
| + // restart nil: a pure repoint, which needs no unit restart. |
| + if err := Pass(ctx, reg, s, pub, opt, nil, OnStageBlocked(relay), RootRestartsUnits()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if ver, err := LiveVersion(opt, host); err != nil || ver != "v1" || relays != 0 { |
| + t.Fatalf("live = %q, %v, relays %d; want v1 and no relay", ver, err, relays) |
| + } |
| +} |
| + |
| +// Astra review of #315: a route with no unit of its own whose process is a |
| +// named unit (same account, app, channel and upstream) is root's too. Stamped |
| +// by the agent it would claim a build console.service does not run. |
| +func TestRootRestartsUnitsHandsTheProcessGroupToRoot(t *testing.T) { |
| + ctx, reg, s, pub, opt := startUnitFixture(t, "console.example.com") |
| + if err := reg.SetUnit("console.example.com", ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + groupFixtureRoute(t, reg, "platform.example.com", "", "127.0.0.1:8090", "console.service") |
| + if err := reg.SetUpstreams("console.example.com", "127.0.0.1:8090", "", ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := PointLive(opt, "platform.example.com", "bab", "old", "console"); err != nil { |
| + t.Fatal(err) |
| + } |
| + var relayed []string |
| + relay := func(host, ver string, err error) { |
| + if errors.Is(err, ErrUnitRestartNeedsRoot) { |
| + relayed = append(relayed, host) |
| + } |
| + } |
| + restart := func(host string) error { |
| + t.Errorf("restart(%s): every host here is the unit's", host) |
| + return nil |
| + } |
| + if err := Pass(ctx, reg, s, pub, opt, restart, OnStageBlocked(relay), RootRestartsUnits()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(relayed) != 2 { |
| + t.Fatalf("relayed = %v, want both hosts", relayed) |
| + } |
| + for _, h := range []string{"console.example.com", "platform.example.com"} { |
| + if ver, err := LiveVersion(opt, h); err != nil || ver != "old" { |
| + t.Fatalf("%s live = %q, %v; want old", h, ver, err) |
| + } |
| + } |
| +} |