activator: the claim launch source names the host once around a key refusal, and the tests pin host-once on every path (task 6 fix round 1)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+63
−2
internal/activator/claim_instancekey_test.go+45 −0internal/activator/claim_snapshot.go+8 −2internal/activator/instancekey_test.go+10 −0
CI passed — run details
CI log
=== gate ===
cd launchctx && go vet ./... && go test ./... -count=1
ok amadan.net/carlos/platform.git/launchctx 0.011s
? 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 311.638s
? github.com/carlosframework/platform/cmd/changelog [no test files]
ok github.com/carlosframework/platform/cmd/console 3.040s
ok github.com/carlosframework/platform/internal/activator 202.497s
ok github.com/carlosframework/platform/internal/agentsock 0.028s
ok github.com/carlosframework/platform/internal/alerting 0.003s
ok github.com/carlosframework/platform/internal/analytics 0.020s
ok github.com/carlosframework/platform/internal/appconfig 2.181s
ok github.com/carlosframework/platform/internal/apperr 0.099s
ok github.com/carlosframework/platform/internal/applog 0.149s
ok github.com/carlosframework/platform/internal/awsinv 0.005s
ok github.com/carlosframework/platform/internal/boxchoice 0.004s
ok github.com/carlosframework/platform/internal/boxid 0.620s
? 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.009s
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.192s
ok github.com/carlosframework/platform/internal/changelog 0.260s
ok github.com/carlosframework/platform/internal/clamd 0.059s
? github.com/carlosframework/platform/internal/cliflag [no test files]
ok github.com/carlosframework/platform/internal/console 318.661s
? 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.111s
ok github.com/carlosframework/platform/internal/dbdoor/dbdoortest 0.009s
ok github.com/carlosframework/platform/internal/dbverify 0.004s
ok github.com/carlosframework/platform/internal/dnsrec 0.002s
ok github.com/carlosframework/platform/internal/docsite 0.005s
ok github.com/carlosframework/platform/internal/domains 1.939s
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 25.763s
? github.com/carlosframework/platform/internal/edgeproof [no test files]
ok github.com/carlosframework/platform/internal/edgesfile 0.006s
ok github.com/carlosframework/platform/internal/fleetapi 0.120s
ok github.com/carlosframework/platform/internal/gate 1.655s
ok github.com/carlosframework/platform/internal/genselect 0.014s
ok github.com/carlosframework/platform/internal/geo 0.016s
ok github.com/carlosframework/platform/internal/geoip 0.030s
ok github.com/carlosframework/platform/internal/host 44.432s
ok github.com/carlosframework/platform/internal/hostactors 0.323s
ok github.com/carlosframework/platform/internal/hostbox 1.235s
ok github.com/carlosframework/platform/internal/hostclaim 0.224s
ok github.com/carlosframework/platform/internal/hostevidence 0.006s
ok github.com/carlosframework/platform/internal/hostexec 0.297s
ok github.com/carlosframework/platform/internal/hostfence 0.030s
ok github.com/carlosframework/platform/internal/hostfiles 4.134s
ok github.com/carlosframework/platform/internal/hostfloor 0.008s
ok github.com/carlosframework/platform/internal/hostguard 0.130s
ok github.com/carlosframework/platform/internal/hostops 1.248s
ok github.com/carlosframework/platform/internal/hostquarantine 0.002s
ok github.com/carlosframework/platform/internal/hostresolve 0.137s
ok github.com/carlosframework/platform/internal/hostwrite 0.002s
ok github.com/carlosframework/platform/internal/infraview 0.002s
ok github.com/carlosframework/platform/internal/instancectl 1.701s
ok github.com/carlosframework/platform/internal/instanceexec 2.687s
ok github.com/carlosframework/platform/internal/instancefs 0.003s
ok github.com/carlosframework/platform/internal/instancekey 0.016s
ok github.com/carlosframework/platform/internal/layout 1.304s
ok github.com/carlosframework/platform/internal/lease 9.456s
ok github.com/carlosframework/platform/internal/lease/leasetest 0.020s
ok github.com/carlosframework/platform/internal/ledger 0.028s
ok github.com/carlosframework/platform/internal/mail 0.161s
ok github.com/carlosframework/platform/internal/maintenance 0.075s
ok github.com/carlosframework/platform/internal/maintenanceexec 5.523s
ok github.com/carlosframework/platform/internal/maintenanceguard 0.072s
ok github.com/carlosframework/platform/internal/metrics 0.005s
ok github.com/carlosframework/platform/internal/moves 20.964s
ok github.com/carlosframework/platform/internal/moves/archive 0.762s
ok github.com/carlosframework/platform/internal/objstore 0.159s
ok github.com/carlosframework/platform/internal/ops 0.152s
ok github.com/carlosframework/platform/internal/park 0.193s
ok github.com/carlosframework/platform/internal/privatefile 0.003s
ok github.com/carlosframework/platform/internal/provision 3.010s
ok github.com/carlosframework/platform/internal/publicrelease 0.007s
ok github.com/carlosframework/platform/internal/registry 3.527s
ok github.com/carlosframework/platform/internal/relay 7.225s
ok github.com/carlosframework/platform/internal/release 18.444s
ok github.com/carlosframework/platform/internal/rollout 1.465s
ok github.com/carlosframework/platform/internal/rootaws 0.007s
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.190s
ok github.com/carlosframework/platform/internal/sim/hostlife 2.348s
ok github.com/carlosframework/platform/internal/sim/litestreamfacts 3.903s
ok github.com/carlosframework/platform/internal/status 0.036s
ok github.com/carlosframework/platform/internal/steering 0.005s
ok github.com/carlosframework/platform/internal/stopevidence 0.156s
ok github.com/carlosframework/platform/internal/svcrole 0.002s
ok github.com/carlosframework/platform/internal/telemetry 0.003s
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.002s
ok github.com/carlosframework/platform/internal/updatewords 0.002s
ok github.com/carlosframework/platform/internal/usage 0.004s
ok github.com/carlosframework/platform/internal/version 0.002s
ok github.com/carlosframework/platform/internal/vet 1.546s
=== cross ===
--- shard 0 of 5 ---
cross-compiling darwin/arm64
go: downloading github.com/ncruces/go-strftime v1.0.0
--- shard 1 of 5 ---
cross-compiling darwin/amd64
go: downloading github.com/ncruces/go-strftime v1.0.0
--- shard 2 of 5 ---
cross-compiling linux/arm64
--- shard 3 of 5 ---
cross-compiling windows/amd64
go: downloading github.com/ncruces/go-strftime v1.0.0
--- shard 4 of 5 ---
cross-compiling windows/arm64
go: downloading github.com/ncruces/go-strftime v1.0.0
=== 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.023s
=== RUN TestT4StorageProbeMinio
2026/10/11 17:32:15 moves: T4: STORE: list: operation error S3: ListObjectsV2, https response error StatusCode: 403, RequestID: 18DD89FA84A5D929, 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.015s
minio contract: PASS
diff --git a/internal/activator/claim_instancekey_test.go b/internal/activator/claim_instancekey_test.go| index c3323232d..4d983f8c8 100644 |
| --- a/internal/activator/claim_instancekey_test.go |
| +++ b/internal/activator/claim_instancekey_test.go |
| @@ -8,6 +8,7 @@ import ( |
| "strings" |
| "testing" |
| + "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| ) |
| @@ -110,3 +111,47 @@ func TestEnsureClaimAdminTokenMintsOnlyTheKeyWhenConfigSuppliesTheToken(t *testi |
| t.Fatalf("the launch's token changed: %q, %v", vars["CARLOS_ADMIN_TOKEN"], err) |
| } |
| } |
| + |
| +// Task 6 ruling (K2): the claim launch source is the one launch path that |
| +// returns the key's refusal without a wrapper of its own, so it names the |
| +// host there, once. A fenced or conflicting row is refused under the guard, |
| +// the error carries "instance key for <host>", and the file is untouched. |
| +func TestEnsureClaimAdminTokenNamesTheHostOnceInAKeyRefusal(t *testing.T) { |
| + for _, layout := range []Layout{LayoutFenced, LayoutConflict} { |
| + t.Run(string(layout), func(t *testing.T) { |
| + b := testExecBackend(t) |
| + const host = "shop.example.com" |
| + rt := registry.Route{Host: host, Kind: "instance", Hibernate: true, |
| + DBPath: provision.DefaultDBPath(b.DataDir, host), Socket: filepath.Join(provision.SocketDir, host+".sock")} |
| + own := filepath.Join(b.DataDir, host+".env") |
| + tok := "CARLOS_ADMIN_TOKEN=" + strings.Repeat("d", 64) + "\n" |
| + if err := os.WriteFile(own, []byte(tok), 0o600); err != nil { |
| + t.Fatal(err) |
| + } |
| + switch layout { |
| + case LayoutFenced: |
| + b.LayoutFacts.Journal = func(string) bool { return true } |
| + case LayoutConflict: |
| + b.LayoutFacts.SameID = func(a, b string) bool { return true } |
| + b.LayoutFacts.Peers = func() ([]registry.Route, error) { |
| + return []registry.Route{{Host: "other.example.com", Kind: "instance", Hibernate: true, Socket: "/nonexistent/other.sock"}}, nil |
| + } |
| + } |
| + authorized := 0 |
| + authorize := func(_ context.Context, write func() error) error { authorized++; return write() } |
| + err := b.EnsureClaimAdminToken(context.Background(), rt, authorize) |
| + if err == nil || !strings.Contains(err.Error(), "instance key for "+host) || !strings.Contains(err.Error(), "not minted") { |
| + t.Fatalf("a %s row: err = %v, want the key's refusal naming the host", layout, err) |
| + } |
| + if n := strings.Count(err.Error(), host+": "); n != 1 { |
| + t.Fatalf("a %s row: the refusal names the host %d times: %v", layout, n, err) |
| + } |
| + if authorized != 1 { |
| + t.Fatalf("authorized %d times, want the one guarded write the refusal came from", authorized) |
| + } |
| + if raw, _ := os.ReadFile(own); string(raw) != tok { |
| + t.Fatalf("a refused %s row's env file was changed", layout) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/activator/claim_snapshot.go b/internal/activator/claim_snapshot.go| index 7ef54377c..8aa7d43df 100644 |
| --- a/internal/activator/claim_snapshot.go |
| +++ b/internal/activator/claim_snapshot.go |
| @@ -6,6 +6,7 @@ import ( |
| "encoding/hex" |
| "encoding/json" |
| "errors" |
| + "fmt" |
| "io" |
| "os" |
| "path/filepath" |
| @@ -100,8 +101,13 @@ func (b *ExecBackend) EnsureClaimAdminToken(ctx context.Context, rt registry.Rou |
| return err |
| } |
| } |
| - _, err := b.ensureInstanceKeyFor(rt, paths) |
| - return err |
| + // The one place the claim launch source names the host around the |
| + // key's error: the refusal itself does not, and every other launch |
| + // path wraps it the same way. |
| + if _, err := b.ensureInstanceKeyFor(rt, paths); err != nil { |
| + return fmt.Errorf("instance key for %s: %w", rt.Host, err) |
| + } |
| + return nil |
| }) |
| } |
diff --git a/internal/activator/instancekey_test.go b/internal/activator/instancekey_test.go| index bf85473f7..649c13c23 100644 |
| --- a/internal/activator/instancekey_test.go |
| +++ b/internal/activator/instancekey_test.go |
| @@ -879,6 +879,12 @@ func TestLaunchBodiesMintNoKeyForARowRefusedSinceTheDispatch(t *testing.T) { |
| if err == nil || !strings.Contains(err.Error(), "instance key for "+host) || !strings.Contains(err.Error(), "not minted") { |
| t.Fatalf("%s of a row %s since the dispatch: err = %v, want the key's refusal", launch, layout, err) |
| } |
| + // The host is named once, by the wrapper. (A fenced reason |
| + // also names it inside the journal path, so the count is |
| + // of the "<host>: " prefix.) |
| + if n := strings.Count(err.Error(), host+": "); n != 1 { |
| + t.Fatalf("the refusal names the host %d times: %v", n, err) |
| + } |
| raw, _ := os.ReadFile(filepath.Join(b.DataDir, host+".env")) |
| if n := len(keyLines(raw)); n != 0 { |
| t.Fatalf("a %s row was minted %d key(s)", layout, n) |
| @@ -925,6 +931,8 @@ func TestEnsureInstanceKeyForRefusesFencedAndConflictRows(t *testing.T) { |
| } |
| if _, err := b.ensureInstanceKeyFor(rt, p); err == nil || !strings.Contains(err.Error(), "not minted") { |
| t.Fatalf("ensure for a %s row: err = %v, want a refusal", layout, err) |
| + } else if strings.HasPrefix(err.Error(), rt.Host) { |
| + t.Fatalf("the refusal names the host itself (%v); its callers do", err) |
| } |
| for _, f := range []string{ |
| filepath.Join(b.DataDir, rt.Host+".env"), |
| @@ -957,6 +965,8 @@ func TestBackfillInstanceKeyRefusesFencedAndConflictRows(t *testing.T) { |
| _, _ = b.Layout(rt) |
| if _, err := b.BackfillInstanceKey(rt); err == nil || !strings.Contains(err.Error(), "not backfilled") { |
| t.Fatalf("backfill of a %s row: err = %v, want a refusal", layout, err) |
| + } else if strings.HasPrefix(err.Error(), host) { |
| + t.Fatalf("the refusal names the host itself (%v); the agent's backfill does", err) |
| } |
| if raw, _ := os.ReadFile(own); string(raw) != tok { |
| t.Fatalf("the backfill changed a %s row's env file", layout) |