fix: show a fleet's needs-operator credential state in fleets show
Branch review BR1-P2-01. The console's fleet show reply carries credential_state and credential_reason since Task 2, but the CLI type dropped them, so a fleet waiting for an operator looked normal. - apiFleetShowReply gains both fields (omitempty, additive). - printFleetShow prints the state on its own line after the fleet name, whether or not an operation is open: the needs-operator explanation in the 409's words, or the raw state and reason code otherwise. Codes only; the reply never carries key IDs or secrets. - TestFleetsShowCredentialState decodes the console's wire shape (pinned on the server side in TestManagedDeliveredKeySet) for a closed operation, and without one, and checks that a fleet with no credential state renders byte for byte as before. - Census: root envelope re-pinned via census-propose; no new units.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+55
−3
apimode_managedfleets.go+4 −0docs/superpowers/notes/census-proposal-managed-fleets-2b1.md+1 −1fleets_managed.go+10 −0fleets_managed_test.go+32 −0internal/console/managedrecovery_test.go+6 −1internal/provision/testdata/plan14-root-reads-managed-fleets-2b1.tsv+2 −1
diff --git a/apimode_managedfleets.go b/apimode_managedfleets.go| index db067f57e..f698747d4 100644 |
| --- a/apimode_managedfleets.go |
| +++ b/apimode_managedfleets.go |
| @@ -45,6 +45,10 @@ type apiFleetShowReply struct { |
| Managed bool `json:"managed"` |
| Boxes []apiFleetShowBox `json:"boxes"` |
| Operation *apiFleetShowOperation `json:"operation,omitempty"` |
| + // The fleet credential's state, such as needs-operator: codes only, |
| + // never a key or secret. Absent on a fleet that needs nothing. |
| + CredentialState string `json:"credential_state,omitempty"` |
| + CredentialReason string `json:"credential_reason,omitempty"` |
| } |
| func (s *apiSession) showFleet(ctx context.Context, a apiAcct, name string) (apiFleetShowReply, error) { |
diff --git a/docs/superpowers/notes/census-proposal-managed-fleets-2b1.md b/docs/superpowers/notes/census-proposal-managed-fleets-2b1.md| index c9cc7d47c..de2407738 100644 |
| --- a/docs/superpowers/notes/census-proposal-managed-fleets-2b1.md |
| +++ b/docs/superpowers/notes/census-proposal-managed-fleets-2b1.md |
| @@ -12,7 +12,7 @@ Ruling `census-ruling-managed-fleets-2b1`. The independent reviewer approves or |
| | `internal/registry/remote_dispatch.go` `Registry.dispatchRemote` | body | unchanged (454) | managed fleets 2b-1 Task 1: the registry child (carlos __registry-child, the service user a root pass forks) answers GetFleet and ListFleetBoxes with GetFleetContext(ctx, q.Name) and ListFleetBoxesContext(ctx, q.Fleet), passing its existing request context so a cancelled caller ends the child's SQL read; same request fields (Name, Fleet) and same local queries; no method, field or read operation added; read-only method gate unchanged | |
| | `internal/registry/remote.go` `remoteClient.call` | sites | -registry:mu ×2 | managed fleets 2b-1 Task 1 fix: takes the request slot through acquire(ctx) instead of c.mu.Lock (the -registry:mu sites), returning ctx.Err() without sending anything if the caller's context ends while another request holds the pipe; release on return; one request on the pipe at a time as before; the request, closed check, encode/decode and reconnect logic are unchanged; no read added | |
| -Envelopes re-pinned: `infra/modules/region-host`, `infra/modules/region-host/tests/managed_fleets`, `internal/edge`, `internal/registry`. |
| +Envelopes re-pinned: `.`, `infra/modules/region-host`, `infra/modules/region-host/tests/managed_fleets`, `internal/edge`, `internal/registry`. |
| 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. |
diff --git a/fleets_managed.go b/fleets_managed.go| index abdac5d47..8bb18f04e 100644 |
| --- a/fleets_managed.go |
| +++ b/fleets_managed.go |
| @@ -39,8 +39,18 @@ func runFleetsShow(args []string) { |
| } |
| } |
| +// COPY: the credential state lines await controller copy review. |
| +const msgFleetNeedsOperator = "Credentials: needs-operator. an access key delivered to an earlier box, other than the key boxes use now, is still live. an operator must delete that key in IAM before boxes can be added" |
| + |
| func printFleetShow(w io.Writer, out apiFleetShowReply) { |
| fmt.Fprintln(w, out.Name) |
| + // Shown whether or not an operation is open: it blocks every later add. |
| + switch { |
| + case out.CredentialState == "needs-operator" && out.CredentialReason == "delivered_key_other_than_keep_still_live": |
| + fmt.Fprintln(w, msgFleetNeedsOperator) |
| + case out.CredentialState != "": |
| + fmt.Fprintf(w, "Credentials: %s %s\n", out.CredentialState, out.CredentialReason) // COPY |
| + } |
| if op := out.Operation; op != nil { |
| fmt.Fprintf(w, "Operation %s: %s %s %s\n", op.ID, op.State, op.Outcome, op.Error) // COPY |
| printManagedPlan(w, op.Plan) |
diff --git a/fleets_managed_test.go b/fleets_managed_test.go| index 1953c1b1e..49f0f72e0 100644 |
| --- a/fleets_managed_test.go |
| +++ b/fleets_managed_test.go |
| @@ -195,3 +195,35 @@ func TestManagedCLIFollowSuccessfulPreparationRetry(t *testing.T) { |
| t.Fatal(err) |
| } |
| } |
| + |
| +// TestFleetsShowCredentialState decodes the console's show reply for a fleet |
| +// waiting for an operator, with its operation closed, and renders the state. |
| +// A fleet with no credential state renders exactly as before. |
| +func TestFleetsShowCredentialState(t *testing.T) { |
| + // The console's wire shape, pinned on the server side by |
| + // TestManagedDeliveredKeySet. |
| + needs := `{"name":"production","managed":true,"boxes":[{"label":"box-1","state":"ready","version":"v0.34.0","last_error":"","checks":{"owner_record":{"state":"pass","reason":""},"version":{"state":"pass","reason":""}}},{"label":"box-3","state":"terminated","version":"","last_error":"delivered_key_other_than_keep_still_live","checks":{}}],"operation":{"plan":{"region":"eu-west-1","size":"large","instance_type":"m7g.large","boxes":1},"id":"3b23fa442c2eb348f8df1d60ac1b07e9","kind":"add","state":"failed","outcome":"failed","error":"delivered_key_other_than_keep_still_live","requested":1},"credential_state":"needs-operator","credential_reason":"delivered_key_other_than_keep_still_live"}` |
| + normal := `{"name":"production","managed":true,"boxes":[{"label":"box-1","state":"ready","version":"v0.34.0","last_error":"","checks":{"owner_record":{"state":"pass","reason":""},"version":{"state":"pass","reason":""}}},{"label":"box-3","state":"terminated","version":"","last_error":"managed_launch_rejected","checks":{}}],"operation":{"plan":{"region":"eu-west-1","size":"large","instance_type":"m7g.large","boxes":1},"id":"3b23fa442c2eb348f8df1d60ac1b07e9","kind":"add","state":"done","outcome":"failed","error":"managed_partial_failure","requested":2}}` |
| + render := func(reply string) string { |
| + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, reply) })) |
| + defer ts.Close() |
| + out, err := newTestSession(ts.URL).showFleet(context.Background(), apiAcct{Seg: "chosen"}, "production") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var buf bytes.Buffer |
| + printFleetShow(&buf, out) |
| + return buf.String() |
| + } |
| + got := render(needs) |
| + if !strings.Contains(got, "production\n"+msgFleetNeedsOperator+"\n") || strings.Contains(got, "key-") { |
| + t.Fatalf("needs-operator not shown: %s", got) |
| + } |
| + if got = render(strings.Replace(needs, `"operation":{"plan":{"region":"eu-west-1","size":"large","instance_type":"m7g.large","boxes":1},"id":"3b23fa442c2eb348f8df1d60ac1b07e9","kind":"add","state":"failed","outcome":"failed","error":"delivered_key_other_than_keep_still_live","requested":1},`, "", 1)); !strings.Contains(got, msgFleetNeedsOperator) { |
| + t.Fatalf("needs-operator hidden without an operation: %s", got) |
| + } |
| + const want = "production\nOperation 3b23fa442c2eb348f8df1d60ac1b07e9: done failed managed_partial_failure\nPlan: 1 boxes, region eu-west-1, size large, instance type m7g.large\nBOX STATE VERSION LAST ERROR\nbox-1 ready v0.34.0 \nbox-3 terminated unknown managed_launch_rejected\n box-1 owner_record: pass \n box-1 version: pass \n" |
| + if got = render(normal); got != want { |
| + t.Fatalf("normal fleet render changed:\n%q\nwant\n%q", got, want) |
| + } |
| +} |
diff --git a/internal/console/managedrecovery_test.go b/internal/console/managedrecovery_test.go| index b270025de..05a563c05 100644 |
| --- a/internal/console/managedrecovery_test.go |
| +++ b/internal/console/managedrecovery_test.go |
| @@ -468,7 +468,12 @@ func TestManagedDeliveredKeySet(t *testing.T) { |
| if spy.rotations != rotations+1 || !spy.KeyLive("production", k1) || !spy.KeyLive("production", k2) || p.Calls()["Launch"] != launches { |
| t.Fatal("refused rotation reaped, minted or launched", spy.rotations, p.Calls()) |
| } |
| - out := managedAPIReply(t, managedAPICall(s, "show", "abc", "production", "")) |
| + shown := managedAPICall(s, "show", "abc", "production", "") |
| + // The CLI decodes this wire shape (TestFleetsShowCredentialState). |
| + if !strings.Contains(shown.Body.String(), `,"credential_state":"needs-operator","credential_reason":"delivered_key_other_than_keep_still_live"}`) { |
| + t.Fatalf("show wire: %s", shown.Body) |
| + } |
| + out := managedAPIReply(t, shown) |
| if out.CredentialState != "needs-operator" || out.CredentialReason != "delivered_key_other_than_keep_still_live" { |
| t.Fatalf("show: %+v", out) |
| } |
diff --git a/internal/provision/testdata/plan14-root-reads-managed-fleets-2b1.tsv b/internal/provision/testdata/plan14-root-reads-managed-fleets-2b1.tsv| index 8fb71c66d..d3c8b7f6d 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-managed-fleets-2b1.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-managed-fleets-2b1.tsv |
| @@ -1,5 +1,5 @@ |
| # Census overlay managed-fleets-2b1, written by census-propose (#369). census-ruling-managed-fleets-2b1, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-managed-fleets-2b1.md. |
| -# 6 body, 1 sites, 4 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 6 body, 1 sites, 5 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| # 11 new dispositions: 0 reads re-frozen at their disposition with the claim, 7 new units frozen accepted-legacy, 3 quiet units retired while they read nothing, 1 other. |
| @legacy a44b63fa895260919d9fa4d0a5fedc3785664fcf082870df35a2de82c2bf400c infra/modules/region-host/main.tf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-console-invite-delivery;basis=tofu on an operator's machine with the operator's AWS credentials (no box unit; no binary embeds the file): main's module with one optional aws_iam_role_policy, host_console_mail, count 0 unless console_mail_from is set; it grants the host role ses:SendEmail on the one sending identity, the carlos-bab configuration set and its tenants, conditioned on ses:FromAddress equal to console_mail_from; no read is added and nothing on a box reads the file;rev3=census-ruling-sec-host-imdsv2-module;basis=aws_instance.host gains metadata_options (IMDSv2 required, hop limit 1, endpoint enabled), matching scanner-host; tofu configuration only, run on an operator's machine; no read, file or record write is added; applies in place on a running instance with no restart;rev3=census-ruling-hunt-account-root-hardening;basis=adds aws_iam_role_policy host_release_key_deny (count from deny_release_key_reads, default true): an explicit Deny on ssm:GetParameter, GetParameters and GetParameterHistory for parameter/carlos/release-key, and on GetParametersByPath for its ancestor paths; tofu only, run on an operator's machine; no read is added and nothing on a box reads the file;rev3=census-ruling-region-host-store-deny;basis=host_store policy: the explicit Deny on the deployment's own buckets drops s3:DeleteObject and keeps s3:DeleteBucket and s3:CreateBucket (lease release, retention and prune are DeleteObject); tofu only, run on an operator machine; no read is added and nothing on a box reads the file;rev3=census-ruling-region-ha-p3b;basis=Select default fixed resources through counted addresses and explicit moves; group mode selects scoped bucket/SSM policy, partition-aware ARNs and refuses fixed-only settings. Operator Terraform controls the instance role that can read boot parameters and write runtime bucket objects; release-key Deny and fixed-mode policy remain.;rev3=census-ruling-region-ha-g3-fixes;basis=Enable the fixed-host memory alarm with either alert input and use the selected topic for alarm and recovery notifications. Preserve module topic/subscription creation for alerts_email only. No new root runtime read or box authority.;rev3=census-ruling-managed-fleets-2b1;basis=managed fleets 2b-1 Task 5: aws_iam_policy.store_user_boundary is now counted when store_bucket_prefix is set or managed_fleets_enabled is true; its statements are concat of the unchanged object-storage pair (only with a store prefix, moved into local.store_boundary_statements byte for byte) and local.managed_boundary_statements (only with managed fleets: the fleet-data Allows on <managed_fleet_bucket_prefix>* buckets); name unchanged, description conditional on store prefix with lifecycle ignore_changes on description so a later feature switch never replaces the policy; tofu only, run on an operator's machine with the operator's AWS credentials; no box unit, user_data or binary reads the file; no read is added; default (both features off) plans no change file:external@0 b0ca0e42d5d9d904132621d174948fb725909b13d030348fda2a57ef75815d38 |
| @legacy 95c0a6fd6ba66588712a911a72117f15acf21513993d05f7fd074f1b11426dc2 infra/modules/region-host/outputs.tf external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-region-ha-p3b;basis=Keep fixed outputs through indexed resources, return null for group instance/EIP, and expose group, pinned template, ingress and boot-parameter names. Operator Terraform outputs only; no new box read.;rev3=census-ruling-region-ha-g2-fixes;basis=Expose the module alert topic ARN, null without an alerts topic; no new box runtime read.;rev3=census-ruling-region-ha-g3-fixes;basis=Return the selected existing or module-created alert topic ARN, null when neither input is set. Terraform output only; no new root runtime read.;rev3=census-ruling-managed-fleets-2b1;basis=managed fleets 2b-1 Task 5: three outputs, managed_fleet_user_boundary_arn, managed_fleet_user_path and managed_fleet_bucket_prefix, each null unless managed_fleets_enabled; Terraform outputs for the operator only; no box runtime read is added file:external@0 c5428698ba862dfe598504959913af95fb1268962cb06907cd7a4a38da0a8c42 |
| @@ -34,6 +34,7 @@ internal/registry/remote.go remoteClient.call legacy accepted-legacy accepted-le |
| @removed internal/registry/fleets.go Registry.ListFleetBoxes H3 census-ruling-managed-fleets-2b1;basis=managed fleets 2b-1 Task 1: now only returns ListFleetBoxesContext(context.Background(), fleet); the same reads moved there unchanged; reads nothing itself |
| @remove internal/registry/remote.go remoteClient.close |
| @removed internal/registry/remote.go remoteClient.close H3 census-ruling-managed-fleets-2b1;basis=managed fleets 2b-1 Task 1 fix: takes the slot with acquire(nil) and frees it with release instead of c.mu; stop() unchanged; reads nothing now |
| +@coverage . 3f8ad88eaabc142a21eaf36b6685c3d58a3a4ed26c84bcbab3821aa045ee726d |
| @coverage infra/modules/region-host b55cce3beafa7b7a026fe4b6c68d8d6d307266099708e7e47c54b5b2a28c7c81 |
| @coverage infra/modules/region-host/tests/managed_fleets 53601a40bb20e428bbd2ce48788bf6c1c23095a9d8a4a4cccaf39ba2219ffaca |
| @coverage internal/edge 762e92a1009c962c7df52c01a4bdf050eae8bb19a98467d1e685d1e23b89ef0f |