fix: managed keep-key reasons, boot diagnostics and one-box witness
Task 6 fix round 1 (Astra R1, Fable R1). - A missing or deactivated keep key is judged before older delivered keys, so the fleet never asks the operator to delete its last working key; a deactivated keep key gets its own needs-operator reason. - Cleanup that discovers a launched instance records its ID and reads its console once before termination intent; enrolment-incomplete boxes get the read too; a failed read is shown and logged as unread. - Opted-in settings are validated whole before either provider is built: hub host as a bare hostname, the parsed release key, reserved bucket prefixes, the user path limit; the Config is checked again at start. - The production-provider guard also checks main.go's Config literal. - TestManaged2B2OneBox and TestManaged2B2KeyFailureStatus now run in internal/host through a real console, the production managed boot, prober, join, root admission code and Reconcile. - Operator docs say when the console detects a deleted or deactivated key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
21 files changed,
+1,066
−198
cmd/console/main.go+55 −10cmd/console/managedfleets_test.go+13 −1docs/site/cli.md+7 −4fleets_managed.go+3 −0fleets_managed_test.go+12 −0internal/awsmanaged/credentials.go+14 −9internal/awsmanaged/credentials_test.go+18 −9internal/awsmanaged/integration_2b2_test.go+32 −8internal/awsmanaged/storage.go+5 −0internal/console/managed2b2_linux_test.go+0 −105internal/console/managed2b2_test.go+187 −38internal/console/managed_e2e_test.go+9 −0internal/console/managedhistory.go+14 −0internal/console/managedstore.go+4 −1internal/console/managedview.go+7 −0internal/console/managedworker.go+38 −6internal/fleetstore/fake.go+24 −5internal/fleetstore/provisioner.go+8 −1internal/host/managed2b2_onebox_linux_test.go+609 −0internal/host/managedboot_linux_test.go+6 −0internal/provision/testdata/plan14-root-reads-managed-fleets-2b2.tsv+1 −1
diff --git a/cmd/console/main.go b/cmd/console/main.go| index 7abce10dd..0d1e88cbb 100644 |
| --- a/cmd/console/main.go |
| +++ b/cmd/console/main.go |
| @@ -649,6 +649,11 @@ func serve() { |
| if cfg.ManagedCompute, cfg.ManagedStorage, cfg.ManagedDeployment, err = managedProvidersFromEnv(context.Background(), os.Getenv); err != nil { |
| log.Fatalf("console: %v", err) |
| } |
| + // The parsed Config is what boxes freeze and what signs their ready |
| + // records: opted in, both must be there. |
| + if cfg.ManagedCompute != nil && (cfg.TunnelHost == "" || len(cfg.Key) != ed25519.PrivateKeySize) { |
| + log.Fatal("console: managed fleets are opted in, but the console has no fleet hub host or release signing key") // COPY |
| + } |
| cfg.HADataStores = buildHADataStores(context.Background(), cfg, rec, release.NewS3StoreIn) |
| srv, err := console.NewServer(cfg, st) |
| if err != nil { |
| @@ -1167,15 +1172,15 @@ func managedProvidersFromEnv(ctx context.Context, getenv func(string) string) (c |
| if err != nil { |
| return nil, nil, "", err |
| } |
| - if !managedPrefixRE.MatchString(prefix) { |
| - return nil, nil, "", errors.New("CARLOS_MANAGED_FLEET_BUCKET_PREFIX must be up to 24 lowercase letters, digits or hyphens, starting with a letter or digit") // COPY |
| + if !managedPrefixRE.MatchString(prefix) || strings.HasPrefix(prefix, "xn--") || strings.HasPrefix(prefix, "sthree-") || strings.HasPrefix(prefix, "amzn-s3-demo-") { |
| + return nil, nil, "", errors.New("CARLOS_MANAGED_FLEET_BUCKET_PREFIX must be up to 24 lowercase letters, digits or hyphens, starting with a letter or digit, and must not start with xn--, sthree- or amzn-s3-demo-") // COPY |
| } |
| userPath, err := need("CARLOS_MANAGED_FLEET_USER_PATH", "the IAM path fleet users are created under; the infrastructure module outputs it as managed_fleet_user_path") // COPY |
| if err != nil { |
| return nil, nil, "", err |
| } |
| - if !managedPathRE.MatchString(userPath) { |
| - return nil, nil, "", errors.New("CARLOS_MANAGED_FLEET_USER_PATH must be an IAM path below the root, such as /carlos-managed-fleet/") // COPY |
| + if len(userPath) > 512 || !managedPathRE.MatchString(userPath) { |
| + return nil, nil, "", errors.New("CARLOS_MANAGED_FLEET_USER_PATH must be an IAM path below the root, at most 512 characters, such as /carlos-managed-fleet/") // COPY |
| } |
| if strings.HasPrefix(userPath, "/carlos-store/") || strings.HasPrefix("/carlos-store/", userPath) { |
| return nil, nil, "", errors.New("CARLOS_MANAGED_FLEET_USER_PATH must not overlap the object storage user path /carlos-store/") // COPY |
| @@ -1187,23 +1192,59 @@ func managedProvidersFromEnv(ctx context.Context, getenv func(string) string) (c |
| if m := managedPolicyRE.FindStringSubmatch(boundary); m == nil || m[1] != account { |
| return nil, nil, "", errors.New("CARLOS_MANAGED_FLEET_BOUNDARY must be an IAM policy ARN in the account CARLOS_MANAGED_FLEET_ACCOUNT_ID names") // COPY |
| } |
| - if get("CARLOS_TUNNEL_HOST") == "" { |
| + // The hub host and the signing key are judged as the console parses |
| + // them for its own Config (tunnelHost, ParseSigningKey), not by raw |
| + // presence: "." or a URL is no host, and a scoped or malformed key |
| + // signs nothing a box accepts. |
| + switch host := tunnelHostFrom(getenv); { |
| + case host == "": |
| return nil, nil, "", errors.New("CARLOS_MANAGED_FLEETS_BACKEND is set. also set CARLOS_TUNNEL_HOST: managed boxes connect to the fleet hub there, and the console checks them through it") // COPY |
| + case !managedHostname(host): |
| + return nil, nil, "", errors.New("CARLOS_TUNNEL_HOST must be a bare hostname such as tunnel.example.com, with no scheme, port or path") // COPY |
| } |
| - if get("CARLOS_RELEASE_KEY") == "" { |
| + switch raw := getenv("CARLOS_RELEASE_KEY"); { |
| + case raw == "": |
| return nil, nil, "", errors.New("CARLOS_MANAGED_FLEETS_BACKEND is set. also set CARLOS_RELEASE_KEY: the console signs each managed box's ready record with it") // COPY |
| + case release.IsScopedSeed(raw): |
| + return nil, nil, "", errors.New("CARLOS_RELEASE_KEY holds a scoped key. managed boxes accept ready records signed only with the deployment's root key") // COPY |
| + default: |
| + if _, err := release.ParseSigningKey(raw, "CARLOS_RELEASE_KEY"); err != nil { |
| + return nil, nil, "", err |
| + } |
| + } |
| + // Both configurations are checked whole before either constructor runs. |
| + ccfg := awsmanaged.ComputeConfig{Deployment: deployment, AccountID: account, Regions: regions} |
| + scfg := awsmanaged.StorageConfig{Deployment: deployment, AccountID: account, IAMRegion: iamRegion, BucketPrefix: prefix, UserPath: userPath, BoundaryARN: boundary, Regions: regions} |
| + if err := awsmanaged.ValidateStorageConfig(scfg); err != nil { |
| + return nil, nil, "", fmt.Errorf("the CARLOS_MANAGED_FLEET_* settings are not usable: %w", err) // COPY |
| } |
| - c, err := awsmanaged.NewCompute(ctx, awsmanaged.ComputeConfig{Deployment: deployment, AccountID: account, Regions: regions}) |
| + c, err := awsmanaged.NewCompute(ctx, ccfg) |
| if err != nil { |
| return nil, nil, "", fmt.Errorf("managed fleets: %w", err) |
| } |
| - st, err := awsmanaged.NewStorage(ctx, awsmanaged.StorageConfig{Deployment: deployment, AccountID: account, IAMRegion: iamRegion, BucketPrefix: prefix, UserPath: userPath, BoundaryARN: boundary, Regions: regions}) |
| + st, err := awsmanaged.NewStorage(ctx, scfg) |
| if err != nil { |
| return nil, nil, "", fmt.Errorf("managed fleets: %w", err) |
| } |
| return c, st, deployment, nil |
| } |
| +var managedLabelRE = regexp.MustCompile(`^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$`) |
| + |
| +// managedHostname is a bare DNS name, as boxes freeze it |
| +// (managedboot.Frozen's tunnel host rule). |
| +func managedHostname(h string) bool { |
| + if h == "" || len(h) > 253 { |
| + return false |
| + } |
| + for _, label := range strings.Split(h, ".") { |
| + if !managedLabelRE.MatchString(label) { |
| + return false |
| + } |
| + } |
| + return true |
| +} |
| + |
| // storeOperators parses CARLOS_STORE_OPERATORS (comma-separated addresses) — |
| // who may drive the GRANT door for an app's store, and only that one door; |
| // rotate is the member's own verb and destroy is the account owner's browser |
| @@ -1650,8 +1691,12 @@ func denyDomains() []string { |
| // passing it apart from CONSOLE_DENY_DOMAINS keeps it out of reach of the |
| // operator's own --platform door (#209). Env is read at this layer only, as |
| // every other console setting is. |
| -func tunnelHost() string { |
| - return strings.TrimSuffix(strings.ToLower(strings.TrimSpace(os.Getenv("CARLOS_TUNNEL_HOST"))), ".") |
| +func tunnelHost() string { return tunnelHostFrom(os.Getenv) } |
| + |
| +// tunnelHostFrom is CARLOS_TUNNEL_HOST as the console uses it: trimmed, |
| +// lower-cased, one trailing dot removed. |
| +func tunnelHostFrom(getenv func(string) string) string { |
| + return strings.TrimSuffix(strings.ToLower(strings.TrimSpace(getenv("CARLOS_TUNNEL_HOST"))), ".") |
| } |
| // storeScannerFor builds the object-storage virus-scanning engine from the |
diff --git a/cmd/console/managedfleets_test.go b/cmd/console/managedfleets_test.go| index a7d42fc21..043b9f1e1 100644 |
| --- a/cmd/console/managedfleets_test.go |
| +++ b/cmd/console/managedfleets_test.go |
| @@ -1,7 +1,9 @@ |
| package main |
| import ( |
| + "bytes" |
| "context" |
| + "encoding/base64" |
| "path/filepath" |
| "strings" |
| "testing" |
| @@ -35,7 +37,7 @@ func TestManagedProvidersFromEnv(t *testing.T) { |
| "CARLOS_MANAGED_FLEET_USER_PATH": "/carlos-managed-fleet/", |
| "CARLOS_MANAGED_FLEET_BOUNDARY": "arn:aws:iam::123456789012:policy/carlos-managed-fleet-boundary", |
| "CARLOS_TUNNEL_HOST": "tunnel.example.com", |
| - "CARLOS_RELEASE_KEY": "set", |
| + "CARLOS_RELEASE_KEY": base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{7}, 32)), |
| } |
| env := func(edit map[string]string) func(string) string { |
| m := map[string]string{} |
| @@ -100,7 +102,17 @@ func TestManagedProvidersFromEnv(t *testing.T) { |
| {"boundary in another account", "CARLOS_MANAGED_FLEET_BOUNDARY", "arn:aws:iam::210987654321:policy/carlos-managed-fleet-boundary"}, |
| {"boundary not a policy", "CARLOS_MANAGED_FLEET_BOUNDARY", "arn:aws:iam::123456789012:role/carlos"}, |
| {"no hub host", "CARLOS_TUNNEL_HOST", ""}, |
| + {"dot hub host", "CARLOS_TUNNEL_HOST", "."}, |
| + {"URL hub host", "CARLOS_TUNNEL_HOST", "https://tunnel.example.com"}, |
| + {"hub host with port", "CARLOS_TUNNEL_HOST", "tunnel.example.com:443"}, |
| + {"hub host with path", "CARLOS_TUNNEL_HOST", "tunnel.example.com/x"}, |
| {"no release key", "CARLOS_RELEASE_KEY", ""}, |
| + {"malformed release key", "CARLOS_RELEASE_KEY", "set"}, |
| + {"scoped release key", "CARLOS_RELEASE_KEY", "scoped:" + base64.StdEncoding.EncodeToString(bytes.Repeat([]byte{7}, 32))}, |
| + {"punycode prefix", "CARLOS_MANAGED_FLEET_BUCKET_PREFIX", "xn--fleet-"}, |
| + {"sthree prefix", "CARLOS_MANAGED_FLEET_BUCKET_PREFIX", "sthree-fleet-"}, |
| + {"demo prefix", "CARLOS_MANAGED_FLEET_BUCKET_PREFIX", "amzn-s3-demo-"}, |
| + {"long user path", "CARLOS_MANAGED_FLEET_USER_PATH", "/" + strings.Repeat("a/", 256)}, |
| } { |
| t.Run(c.name, func(t *testing.T) { |
| p, s, dep, err := managedProvidersFromEnv(ctx, env(map[string]string{c.key: c.value})) |
diff --git a/docs/site/cli.md b/docs/site/cli.md| index c7a896144..4a4b78c7f 100644 |
| --- a/docs/site/cli.md |
| +++ b/docs/site/cli.md |
| @@ -2870,10 +2870,13 @@ The providers only make launches possible. `enabled` in the settings above |
| still decides whether the console accepts managed fleet requests. |
| Every access key the console delivers to a box stays recorded. Deleting an |
| -earlier box's key in IAM removes that box's bucket access. If the key the |
| -fleet's boxes use now is deleted, `carlos fleets show` reports the fleet as |
| -`needs-operator` and no boxes can be added; giving the fleet a new key is not |
| -available yet. |
| +earlier box's key in IAM removes that box's bucket access. Do not delete or |
| +deactivate the key the fleet's boxes use now. The console does not watch IAM, |
| +so it keeps giving that key to new boxes, and they fail their storage check. |
| +The console finds out only when it next has to issue a key. Then |
| +`carlos fleets show` reports the fleet as `needs-operator` and no boxes can be |
| +added. A deactivated key can be made active again; giving the fleet a new key |
| +is not available yet. |
| #### The platform's own binary |
diff --git a/fleets_managed.go b/fleets_managed.go| index 36e31491e..8a265e0eb 100644 |
| --- a/fleets_managed.go |
| +++ b/fleets_managed.go |
| @@ -41,6 +41,7 @@ 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" |
| +const msgFleetKeyInactive = "Credentials: needs-operator. the access key this fleet's boxes use is deactivated in IAM. an operator must make it active again before boxes can be added" // COPY |
| const msgFleetKeyMissing = "Credentials: needs-operator. the access key this fleet's boxes use no longer exists in IAM. boxes cannot be added until the fleet is given a new key, which the console cannot do yet" // COPY |
| func printFleetShow(w io.Writer, out apiFleetShowReply) { |
| @@ -51,6 +52,8 @@ func printFleetShow(w io.Writer, out apiFleetShowReply) { |
| fmt.Fprintln(w, msgFleetNeedsOperator) |
| case out.CredentialState == "needs-operator" && out.CredentialReason == "fleet_access_key_missing": |
| fmt.Fprintln(w, msgFleetKeyMissing) |
| + case out.CredentialState == "needs-operator" && out.CredentialReason == "fleet_access_key_inactive": |
| + fmt.Fprintln(w, msgFleetKeyInactive) |
| case out.CredentialState != "": |
| fmt.Fprintf(w, "Credentials: %s %s\n", out.CredentialState, out.CredentialReason) // COPY |
| } |
diff --git a/fleets_managed_test.go b/fleets_managed_test.go| index e75cfbb12..07080ee9a 100644 |
| --- a/fleets_managed_test.go |
| +++ b/fleets_managed_test.go |
| @@ -250,4 +250,16 @@ func TestFleetsShowBootAndKeyMissing(t *testing.T) { |
| if strings.Contains(got, msgFleetNeedsOperator) { |
| t.Fatal("the delivered-key line for a missing key") |
| } |
| + inactive := strings.Replace(reply, "fleet_access_key_missing", "fleet_access_key_inactive", 1) |
| + ts2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, inactive) })) |
| + defer ts2.Close() |
| + out, err = newTestSession(ts2.URL).showFleet(context.Background(), apiAcct{Seg: "chosen"}, "production") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + buf.Reset() |
| + printFleetShow(&buf, out) |
| + if got = buf.String(); !strings.Contains(got, "production\n"+msgFleetKeyInactive+"\n") || strings.Contains(got, msgFleetNeedsOperator) { |
| + t.Fatalf("inactive:\n%s", got) |
| + } |
| } |
diff --git a/internal/awsmanaged/credentials.go b/internal/awsmanaged/credentials.go| index e4b58e287..bcdfa247f 100644 |
| --- a/internal/awsmanaged/credentials.go |
| +++ b/internal/awsmanaged/credentials.go |
| @@ -252,7 +252,8 @@ func (s *Storage) FleetCredentials(ctx context.Context, fleet string) (fleetstor |
| // inventory first. If any delivered key other than keep still exists, in |
| // any state, it returns fleetstore.ErrDeliveredKeyStillLive and changes |
| // nothing. A nonempty keep must exist (else fleetstore.ErrKeepKeyMissing) |
| -// and be active. Deletions are |
| +// and be active (else fleetstore.ErrKeepKeyInactive); those two are judged |
| +// before the delivered keys. Deletions are |
| // confirmed by a second complete listing before the one CreateAccessKey, |
| // which is sent exactly once: a lost answer leaves an undelivered key the |
| // next rotation reaps. The secret is returned only from that mint. |
| @@ -285,13 +286,10 @@ func (s *Storage) RotateFleetCredentials(ctx context.Context, fleet, keep string |
| if err != nil { |
| return fleetstore.Credentials{}, err |
| } |
| - // The whole inventory is scanned for protected keys first, so no other |
| - // refusal can hide the one the console turns into needs-operator. |
| - for _, k := range keys { |
| - if protected[k.id] { |
| - return fleetstore.Credentials{}, fmt.Errorf("awsmanaged: %w", fleetstore.ErrDeliveredKeyStillLive) |
| - } |
| - } |
| + // The keep key is judged first (2b-2 Task 6, C2): when the key boxes use |
| + // now is absent or deactivated, deleting an older delivered key cannot |
| + // help, so that is the reason surfaced. Both refusals, like the |
| + // protected-key one after them, come before any reap or mint. |
| if keep != "" { |
| i := slices.IndexFunc(keys, func(k accessKey) bool { return k.id == keep }) |
| if i < 0 { |
| @@ -299,7 +297,14 @@ func (s *Storage) RotateFleetCredentials(ctx context.Context, fleet, keep string |
| return fleetstore.Credentials{}, fmt.Errorf("awsmanaged: %w", fleetstore.ErrKeepKeyMissing) |
| } |
| if !keys[i].active { |
| - return fleetstore.Credentials{}, drift("key to keep is not active") |
| + return fleetstore.Credentials{}, fmt.Errorf("awsmanaged: %w", fleetstore.ErrKeepKeyInactive) |
| + } |
| + } |
| + // Then the whole inventory is scanned for protected keys, so no later |
| + // refusal can hide the one the console turns into needs-operator. |
| + for _, k := range keys { |
| + if protected[k.id] { |
| + return fleetstore.Credentials{}, fmt.Errorf("awsmanaged: %w", fleetstore.ErrDeliveredKeyStillLive) |
| } |
| } |
| for _, k := range keys { |
diff --git a/internal/awsmanaged/credentials_test.go b/internal/awsmanaged/credentials_test.go| index ea1900215..347b9ba1c 100644 |
| --- a/internal/awsmanaged/credentials_test.go |
| +++ b/internal/awsmanaged/credentials_test.go |
| @@ -477,12 +477,16 @@ func TestAWSFleetCredentialsDoubleLostRotation(t *testing.T) { |
| t.Fatal("mutated keys on a partial inventory") |
| } |
| }) |
| - t.Run("inactive keep is not missing", func(t *testing.T) { |
| + t.Run("inactive keep is its own refusal", func(t *testing.T) { |
| s, user := preparedStorage(t) |
| keep := s.iam.addKey(user, iamtypes.StatusTypeInactive) |
| - if _, err := s.RotateFleetCredentials(ctx, testFleet, keep, []string{keep}); err == nil || errors.Is(err, fleetstore.ErrKeepKeyMissing) { |
| + _, err := s.RotateFleetCredentials(ctx, testFleet, keep, []string{keep}) |
| + if !errors.Is(err, fleetstore.ErrKeepKeyInactive) || errors.Is(err, fleetstore.ErrKeepKeyMissing) { |
| t.Fatalf("inactive keep: %v", err) |
| } |
| + if s.iam.keyMutations() != 0 { |
| + t.Fatal("mutated keys") |
| + } |
| }) |
| t.Run("second delivered key still live", func(t *testing.T) { |
| s, user := preparedStorage(t) |
| @@ -513,11 +517,12 @@ func TestAWSFleetCredentialsDoubleLostRotation(t *testing.T) { |
| t.Fatal("mutated keys") |
| } |
| }) |
| - // An unusable keep must not hide a live delivered key: only the |
| - // sentinel makes the console record needs-operator. Pages hold one key, |
| - // so the first order puts the delivered key on page 2. |
| + // A missing or deactivated keep key wins over a live delivered key |
| + // (2b-2 Task 6 fix round 1, Astra P1-1): deleting the older key cannot |
| + // help, so the surfaced reason names the keep key. Pages hold one key, |
| + // so the first order puts the keep key on page 2. Nothing is mutated. |
| for _, order := range []string{"inactive keep first", "delivered first"} { |
| - t.Run(order+": protected key wins over an inactive keep", func(t *testing.T) { |
| + t.Run(order+": an inactive keep wins over a live delivered key", func(t *testing.T) { |
| s, user := preparedStorage(t) |
| var keep, other string |
| if order == "inactive keep first" { |
| @@ -528,7 +533,7 @@ func TestAWSFleetCredentialsDoubleLostRotation(t *testing.T) { |
| keep = s.iam.addKey(user, iamtypes.StatusTypeInactive) |
| } |
| _, err := s.RotateFleetCredentials(ctx, testFleet, keep, []string{other, keep}) |
| - if !errors.Is(err, fleetstore.ErrDeliveredKeyStillLive) { |
| + if !errors.Is(err, fleetstore.ErrKeepKeyInactive) || errors.Is(err, fleetstore.ErrDeliveredKeyStillLive) { |
| t.Fatalf("got %v", err) |
| } |
| if s.iam.keyMutations() != 0 { |
| @@ -536,13 +541,17 @@ func TestAWSFleetCredentialsDoubleLostRotation(t *testing.T) { |
| } |
| }) |
| } |
| - t.Run("protected key wins over a missing keep", func(t *testing.T) { |
| + t.Run("a missing keep wins over a live delivered key", func(t *testing.T) { |
| s, user := preparedStorage(t) |
| s.iam.addKey(user, iamtypes.StatusTypeActive) // undelivered |
| other := s.iam.addKey(user, iamtypes.StatusTypeActive) |
| - if _, err := s.RotateFleetCredentials(ctx, testFleet, "AKIA9999999999999999", []string{other, "AKIA9999999999999999"}); !errors.Is(err, fleetstore.ErrDeliveredKeyStillLive) { |
| + _, err := s.RotateFleetCredentials(ctx, testFleet, "AKIA9999999999999999", []string{other, "AKIA9999999999999999"}) |
| + if !errors.Is(err, fleetstore.ErrKeepKeyMissing) || errors.Is(err, fleetstore.ErrDeliveredKeyStillLive) { |
| t.Fatalf("got %v", err) |
| } |
| + if s.iam.keyMutations() != 0 { |
| + t.Fatal("mutated keys") |
| + } |
| }) |
| t.Run("delivered key gone is no obstacle", func(t *testing.T) { |
| s, user := preparedStorage(t) |
diff --git a/internal/awsmanaged/integration_2b2_test.go b/internal/awsmanaged/integration_2b2_test.go| index 86a5fa07d..085443cd6 100644 |
| --- a/internal/awsmanaged/integration_2b2_test.go |
| +++ b/internal/awsmanaged/integration_2b2_test.go |
| @@ -127,25 +127,49 @@ func TestAWSManaged2B2Recovery(t *testing.T) { |
| t.Fatalf("FleetCredentials: %q %v", named.ID, err) |
| } |
| - // 2b-1 carry C2: k1 is deleted outside the console. A complete |
| - // listing proves it absent: the dedicated sentinel, nothing reaped |
| + // 2b-1 carry C2: k2 becomes the key boxes use while the earlier |
| + // delivered k1 stays live; then k2 is deleted outside the console. |
| + // A complete listing proves k2 absent and that is the surfaced |
| + // reason, not "delete k1" (fix round 1, Astra P1-1): nothing reaped |
| // or minted, and no key or secret in the error. |
| - w.deleteKey(k1.ID) |
| + k2, err := newITStorage(t, w).RotateFleetCredentials(ctx, itFleet, k1.ID, []string{k1.ID}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + w.deleteKey(k2.ID) |
| before, _ = w.snapshot() |
| - _, err = newITStorage(t, w).RotateFleetCredentials(ctx, itFleet, k1.ID, []string{k1.ID}) |
| + _, err = newITStorage(t, w).RotateFleetCredentials(ctx, itFleet, k2.ID, []string{k1.ID, k2.ID}) |
| if !errors.Is(err, fleetstore.ErrKeepKeyMissing) || errors.Is(err, fleetstore.ErrDeliveredKeyStillLive) { |
| t.Fatalf("missing keep: %v", err) |
| } |
| - if after, _ := w.snapshot(); after != before || strings.Contains(err.Error(), k1.ID) { |
| - t.Fatalf("missing keep changed IAM or named the key: %d %v", after-before, err) |
| + if after, _ := w.snapshot(); after != before || strings.Contains(err.Error(), k1.ID) || strings.Contains(err.Error(), k2.ID) { |
| + t.Fatalf("missing keep changed IAM or named a key: %d %v", after-before, err) |
| + } |
| + // k1 deactivated and kept: its own refusal, still before k-live. |
| + w.mu.Lock() |
| + for _, u := range w.users { |
| + for i := range u.keys { |
| + if u.keys[i].id == k1.ID { |
| + u.keys[i].status = "Inactive" |
| + } |
| + } |
| + } |
| + w.mu.Unlock() |
| + before, _ = w.snapshot() |
| + if _, err = newITStorage(t, w).RotateFleetCredentials(ctx, itFleet, k1.ID, []string{k1.ID, k2.ID}); !errors.Is(err, fleetstore.ErrKeepKeyInactive) { |
| + t.Fatalf("inactive keep: %v", err) |
| } |
| + if after, _ := w.snapshot(); after != before { |
| + t.Fatal("inactive keep changed IAM") |
| + } |
| + w.deleteKey(k1.ID) |
| // A listing that fails proves nothing. |
| w.fail["ListAccessKeys"] = itFault{500, "ServiceFailure"} |
| - if _, err = newITStorage(t, w).RotateFleetCredentials(ctx, itFleet, k1.ID, []string{k1.ID}); err == nil || errors.Is(err, fleetstore.ErrKeepKeyMissing) { |
| + if _, err = newITStorage(t, w).RotateFleetCredentials(ctx, itFleet, k2.ID, []string{k1.ID, k2.ID}); err == nil || errors.Is(err, fleetstore.ErrKeepKeyMissing) { |
| t.Fatalf("failed listing: %v", err) |
| } |
| delete(w.fail, "ListAccessKeys") |
| - if live := w.liveKeys(t); len(live) != 0 || slices.Contains(live, k1.ID) { |
| + if live := w.liveKeys(t); len(live) != 0 || slices.Contains(live, k2.ID) { |
| t.Fatalf("live keys: %v", live) |
| } |
| }) |
diff --git a/internal/awsmanaged/storage.go b/internal/awsmanaged/storage.go| index fee899674..abc874125 100644 |
| --- a/internal/awsmanaged/storage.go |
| +++ b/internal/awsmanaged/storage.go |
| @@ -122,6 +122,11 @@ func newStorage(cfg StorageConfig, buckets map[string]s3API, users iamAPI) (*Sto |
| return s, nil |
| } |
| +// ValidateStorageConfig reports whether cfg is a usable storage (and so |
| +// compute) configuration, exactly as NewStorage judges it, without loading |
| +// any client. The console checks it before constructing either adapter. |
| +func ValidateStorageConfig(cfg StorageConfig) error { return validateStorageConfig(cfg) } |
| + |
| func validateStorageConfig(cfg StorageConfig) error { |
| if err := validateConfig(ComputeConfig{Deployment: cfg.Deployment, AccountID: cfg.AccountID, Regions: cfg.Regions}); err != nil { |
| return err |
diff --git a/internal/console/managed2b2_linux_test.go b/internal/console/managed2b2_linux_test.go| index c9acfeed1..18082961d 100644 |
| --- a/internal/console/managed2b2_linux_test.go |
| +++ b/internal/console/managed2b2_linux_test.go |
| @@ -4,12 +4,8 @@ package console |
| import ( |
| "context" |
| - "crypto/ed25519" |
| - "encoding/base64" |
| - "errors" |
| "os" |
| "path/filepath" |
| - "strings" |
| "syscall" |
| "testing" |
| "time" |
| @@ -72,107 +68,6 @@ func (r managedFakeRoot) commit(wire []byte) error { |
| return managedboot.CommitAdmissionAs(r.root, wire, r.owner) |
| } |
| -// TestManaged2B2OneBox drives one managed box from create to root's |
| -// admission through the real console doors, worker and probe bridge, and |
| -// the box's real managedboot code: the frozen user data decodes to the |
| -// stored boot, the seed matches its frozen digest, the token trades once, |
| -// the reply passes the box's checks, the first box's key registers, a |
| -// joining heartbeat and an exactly attested probe pass all six checks, and |
| -// the signed ready object verifies with the frozen release key. Root |
| -// admits only that object; nothing counts as admitted before it. |
| -func TestManaged2B2OneBox(t *testing.T) { |
| - g := newOneBox(t) |
| - g.launch(func(script string) []byte { |
| - if req := boottest.Heredoc(script, "SEEDREQUEST"); !strings.Contains(req, `"token"`) { |
| - t.Fatalf("seed request %q", req) |
| - } |
| - return []byte(boottest.Heredoc(script, "BOOTINPUT")) |
| - }) |
| - g.seedAndTrade() |
| - id := managedboot.IdentityOf(g.in) |
| - root := newManagedFakeRoot(t, id) |
| - if !root.joining(t) { |
| - t.Fatal("admitted before anything") |
| - } |
| - g.mintKey() |
| - reg, err := openRegistry(g.s.cfg.Registry) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - fleet, err := reg.GetFleet(g.in.Fleet) |
| - if err != nil || fleet == nil || fleet.SecretsKeyFP != g.key.Fingerprint { |
| - t.Fatalf("registered key: %+v %v", fleet, err) |
| - } |
| - if b := g.box(); b.State != "enrolled" { |
| - t.Fatalf("after trade: %s", b.State) |
| - } |
| - |
| - // A minute of joining: heartbeat and probe from the box itself. |
| - at := g.now.Add(time.Minute) |
| - g.joining(at, managedboot.KeyStatusOK) |
| - // Before the ready object exists, a forged one is refused by root. |
| - _, other, _ := ed25519.GenerateKey(nil) |
| - forged, err := managedboot.SignReady(other, managedboot.ReadyRecord{Schema: 1, Kind: managedboot.ReadyKind, Fleet: id.Fleet, Label: id.Label, Op: id.Op, ReadyAt: at}) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - if err = root.commit(forged); !errors.Is(err, managedboot.ErrAdmissionRefused) || !root.joining(t) { |
| - t.Fatal("root admitted a ready object the console did not sign", err) |
| - } |
| - e2ePass(t, g.s, at) |
| - e2ePass(t, g.s, at.Add(10*time.Second)) |
| - b := g.box() |
| - if b.State != "ready" || !b.DrainClearCompleted { |
| - t.Fatalf("not ready: %s %+v", b.State, b.Checks) |
| - } |
| - for _, name := range managedReadinessChecks { |
| - if b.Checks[name].State != "pass" { |
| - t.Fatalf("%s: %+v", name, b.Checks[name]) |
| - } |
| - } |
| - if g.hub.calls.Load() == 0 || g.hub.badAuth.Load() != 0 || g.hub.last.Fleet != id.Fleet || g.hub.last.Label != id.Label || g.hub.last.Op != id.Op { |
| - t.Fatalf("probe: %d calls, %d bad, %+v", g.hub.calls.Load(), g.hub.badAuth.Load(), g.hub.last) |
| - } |
| - out := managedAPIReply(t, managedAPICall(g.s, "show", "abc", "production", "")) |
| - if out.Operation == nil || out.Operation.State != "done" || out.Operation.Outcome != "success" || out.Boxes[0].State != "ready" { |
| - t.Fatalf("show: %+v", out) |
| - } |
| - boxes, err := reg.ListFleetBoxes(g.in.Fleet) |
| - if err != nil || len(boxes) != 1 || boxes[0].DrainingSince != 0 { |
| - t.Fatalf("registry box: %+v %v", boxes, err) |
| - } |
| - |
| - // The agent relays the published object; root verifies and commits. |
| - if !root.joining(t) { |
| - t.Fatal("admitted before root's record") |
| - } |
| - raw, _, err := g.s.cfg.Releases.Get(context.Background(), managedReadyKey(b)) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - pub, err := base64.StdEncoding.DecodeString(g.in.Frozen.ReleasePubkey) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - rec, err := managedboot.VerifyReady(pub, raw, id) |
| - if err != nil || !rec.ReadyAt.Equal(b.ReadyAt) { |
| - t.Fatalf("ready object: %+v %v", rec, err) |
| - } |
| - if err = root.commit(raw); err != nil { |
| - t.Fatal("root refused the console's ready object:", err) |
| - } |
| - if root.joining(t) { |
| - t.Fatal("not admitted after root's commit") |
| - } |
| - // Admission is one-way: the object's later absence changes nothing. |
| - if err = g.s.cfg.Releases.Delete(context.Background(), managedReadyKey(b)); err != nil { |
| - t.Fatal(err) |
| - } |
| - if root.joining(t) { |
| - t.Fatal("admission depends on the published object") |
| - } |
| -} |
| - |
| // TestManaged2B2ConsumedPublicationUncertain (review focus 2, C08): the PUT |
| // succeeds and root commits admission, but the console's verifying GET is |
| // lost, then reads a mismatch. The console stays publishing and uncertain, |
diff --git a/internal/console/managed2b2_test.go b/internal/console/managed2b2_test.go| index 11aa9702f..190555d46 100644 |
| --- a/internal/console/managed2b2_test.go |
| +++ b/internal/console/managed2b2_test.go |
| @@ -406,43 +406,6 @@ func (k *keepKeyStorage) RotateFleetCredentials(ctx context.Context, fleet, keep |
| return c, err |
| } |
| -// TestManaged2B2KeyFailureStatus: the box enrols and joins, but its fleet |
| -// key object is malformed. The heartbeat's managed_key fails storage with |
| -// the key reason, show says so, no ready object is written and no workload |
| -// can be admitted; the readiness deadline cleans the box up. |
| -func TestManaged2B2KeyFailureStatus(t *testing.T) { |
| - g := newOneBox(t) |
| - g.launch(func(script string) []byte { return []byte(managedTestHeredoc(t, script, "BOOTINPUT")) }) |
| - g.seedAndTrade() |
| - at := g.now.Add(time.Minute) |
| - g.joining(at, managedboot.KeyStatusObjectInvalid) |
| - e2ePass(t, g.s, at) |
| - b := g.box() |
| - want := managedCheck{State: "fail", Reason: managedKeyReasons[managedboot.KeyStatusObjectInvalid]} |
| - if b.State != "enrolled" || b.Checks["storage"] != want { |
| - t.Fatalf("box %s %+v", b.State, b.Checks) |
| - } |
| - shown := managedAPICall(g.s, "show", "abc", "production", "") |
| - out := managedAPIReply(t, shown) |
| - if len(out.Boxes) != 1 || out.Boxes[0].State != "joining" || out.Boxes[0].Checks["storage"] != want { |
| - t.Fatalf("show: %+v", out.Boxes) |
| - } |
| - if _, _, err := g.s.cfg.Releases.Get(context.Background(), managedReadyKey(b)); err == nil { |
| - t.Fatal("ready object written for a box whose key failed") |
| - } |
| - g.cloud.console = func() (string, error) { return managedboot.CodeJoining, nil } |
| - e2ePass(t, g.s, b.LaunchStartedAt.Add(20*time.Minute)) |
| - e2ePass(t, g.s, b.LaunchStartedAt.Add(20*time.Minute+10*time.Second)) |
| - b = g.box() |
| - if b.State != "terminating" || b.LastError != "managed_readiness_timeout" || g.cloud.Calls()["Terminate"] != 1 { |
| - t.Fatalf("deadline cleanup: %s %s %v", b.State, b.LastError, g.cloud.Calls()) |
| - } |
| - out = managedAPIReply(t, managedAPICall(g.s, "show", "abc", "production", "")) |
| - if out.Boxes[0].Boot != managedBootText[managedboot.CodeJoining] { |
| - t.Fatalf("boot: %q", out.Boxes[0].Boot) |
| - } |
| -} |
| - |
| // managedTestHeredoc is the named heredoc's body in a rendered script. |
| func managedTestHeredoc(t *testing.T, script, name string) string { |
| t.Helper() |
| @@ -576,11 +539,96 @@ func TestManaged2B2Diagnostics(t *testing.T) { |
| if g2.cloud.outputs.Load() != 1 || !b2.BootDiagnosed || b2.BootBreadcrumbs != "" || b2.State != "failed" || g2.cloud.Calls()["Terminate"] != 0 { |
| t.Fatalf("failed read: %d %+v", g2.cloud.outputs.Load(), b2) |
| } |
| - if out := managedAPIReply(t, managedAPICall(g2.s, "show", "abc", "production", "")); out.Boxes[0].Boot != managedBootNoProgress { |
| + // Not shown as an empty console: the read itself failed, and is logged |
| + // by class with nothing from the box. |
| + if out := managedAPIReply(t, managedAPICall(g2.s, "show", "abc", "production", "")); out.Boxes[0].Boot != managedBootUnread { |
| + t.Fatalf("boot %q", out.Boxes[0].Boot) |
| + } |
| + if b2.BootRead || !strings.Contains(logs.String(), "boot progress could not be read (provider error)") { |
| + t.Fatalf("failed read not logged or marked read: %v %q", b2.BootRead, logs.String()) |
| + } |
| + // A successful read of an empty console is "no progress". |
| + g3 := newOneBox(t) |
| + g3.launch(func(script string) []byte { return []byte(managedTestHeredoc(t, script, "BOOTINPUT")) }) |
| + g3.cloud.console = func() (string, error) { return "", nil } |
| + b3 := g3.box() |
| + e2ePass(t, g3.s, b3.LaunchStartedAt.Add(20*time.Minute)) |
| + g3.s.wakeManagedFleets() |
| + e2ePass(t, g3.s, b3.LaunchStartedAt.Add(21*time.Minute)) |
| + if b3 = g3.box(); !b3.BootRead || g3.cloud.outputs.Load() != 1 { |
| + t.Fatalf("empty read: %d %+v", g3.cloud.outputs.Load(), b3) |
| + } |
| + if out := managedAPIReply(t, managedAPICall(g3.s, "show", "abc", "production", "")); out.Boxes[0].Boot != managedBootNoProgress { |
| t.Fatalf("boot %q", out.Boxes[0].Boot) |
| } |
| } |
| +// TestManaged2B2DiagnosticsDiscoveredAtCleanup (fix round 1, Astra P2-1): |
| +// the launch reply was lost and nothing found the instance before the |
| +// deadline. Cleanup discovers it, records its identity-checked ID, reads |
| +// its console once, and only then records termination intent. |
| +func TestManaged2B2DiagnosticsDiscoveredAtCleanup(t *testing.T) { |
| + s, p, _, now := managedWorkerFixture(t) |
| + p.LoseLaunchResponse = true |
| + findFails := true |
| + readsAtTerminate := -1 |
| + spy := &managedComputeScript{Fake: p, |
| + find: func(ctx context.Context, region string, id compute.Identity) ([]compute.Instance, error) { |
| + if findFails { |
| + return nil, errors.New("describe failed") |
| + } |
| + return p.Find(ctx, region, id) |
| + }, |
| + terminate: func(ctx context.Context, region, id string, want compute.Identity) error { |
| + readsAtTerminate = p.Calls()["ConsoleOutput"] |
| + return p.Terminate(ctx, region, id, want) |
| + }} |
| + s.cfg.ManagedCompute = spy |
| + b := workerStep(t, s, now) |
| + if b.State != "launching" || b.CloudID != "" { |
| + t.Fatalf("lost reply: %+v", b) |
| + } |
| + workerStep(t, s, now.Add(5*time.Minute)) |
| + b = workerStep(t, s, b.LaunchStartedAt.Add(20*time.Minute)) |
| + if b.State != "failed" || b.LastError != "managed_readiness_timeout" || b.CloudID != "" { |
| + t.Fatalf("deadline: %+v", b) |
| + } |
| + findFails = false |
| + b = workerStep(t, s, b.LaunchStartedAt.Add(20*time.Minute+time.Second)) |
| + if b.State != "terminating" || b.CloudID == "" || !b.BootDiagnosed || !b.BootRead { |
| + t.Fatalf("cleanup: %+v", b) |
| + } |
| + if p.Calls()["ConsoleOutput"] != 1 || readsAtTerminate != 1 || p.Calls()["Terminate"] != 1 { |
| + t.Fatalf("reads %d (at terminate %d), terminates %d", p.Calls()["ConsoleOutput"], readsAtTerminate, p.Calls()["Terminate"]) |
| + } |
| + for i := 1; i <= 3; i++ { |
| + workerStep(t, s, b.LaunchStartedAt.Add(20*time.Minute+time.Duration(i)*time.Hour)) |
| + } |
| + if p.Calls()["ConsoleOutput"] != 1 { |
| + t.Fatal("read again", p.Calls()) |
| + } |
| +} |
| + |
| +// TestManaged2B2DiagnosticsEnrolmentIncomplete (fix round 1, Fable P3-3): |
| +// a box that used its token without finishing enrolment gets the same one |
| +// read before termination. |
| +func TestManaged2B2DiagnosticsEnrolmentIncomplete(t *testing.T) { |
| + s, p, _, now := managedWorkerFixture(t) |
| + b := workerStep(t, s, now) |
| + if b.CloudID == "" { |
| + t.Fatalf("launch: %+v", b) |
| + } |
| + workerAdvance(t, s, b, func(b *managedBox) { b.EnrolUsedAt = now.Add(time.Minute) }) |
| + b = workerStep(t, s, now.Add(2*time.Minute)) |
| + if b.State != "failed" || b.LastError != "managed_enrolment_incomplete" { |
| + t.Fatalf("incomplete: %+v", b) |
| + } |
| + b = workerStep(t, s, now.Add(3*time.Minute)) |
| + if p.Calls()["ConsoleOutput"] != 1 || !b.BootDiagnosed || b.State != "terminating" { |
| + t.Fatalf("reads %d: %+v", p.Calls()["ConsoleOutput"], b) |
| + } |
| +} |
| + |
| // logOut captures the standard logger for the test. |
| func logOut(t *testing.T, w *strings.Builder) { |
| t.Helper() |
| @@ -701,3 +749,104 @@ func managedTestRoot(t *testing.T) string { |
| } |
| return dir |
| } |
| + |
| +// keepKeyFleet is a ready one-box fleet whose seal is then lost twice: the |
| +// first box got k1, a second box (after the first loss) got k2, which is |
| +// now the key boxes use; k1 stays delivered and live. It returns the |
| +// server, its storage, the compute fake, k1, k2 and an add helper. |
| +func keepKeyFleet(t *testing.T) (*Server, *keepKeyStorage, *compute.Fake, string, string, func(string) *httptest.ResponseRecorder) { |
| + t.Helper() |
| + s, p, _ := managedE2E(t, 1) |
| + storage := &keepKeyStorage{Fake: s.cfg.ManagedStorage.(*fleetstore.Fake)} |
| + s.cfg.ManagedStorage = storage |
| + clock := func() time.Time { return time.Now().UTC() } |
| + e2ePass(t, s, clock()) |
| + k1 := e2eEnrol(t, s, e2eBoxes(t, s)[0]).Credentials.ID |
| + e2eReady(t, s, clock()) |
| + loseSeal := func() { |
| + if _, err := s.store.db.Exec(`UPDATE managed_fleet_storage SET credential_sealed=X'00'`); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + add := func(id string) *httptest.ResponseRecorder { |
| + return managedAPICall(s, "add", "abc", "production", fmt.Sprintf(`{"boxes":1,"request_id":%q}`, strings.Repeat(id, 22))) |
| + } |
| + loseSeal() |
| + managedAPIReply(t, add("b")) |
| + e2ePass(t, s, clock()) |
| + var k2 string |
| + for _, b := range e2eBoxes(t, s) { |
| + if b.State != "ready" { |
| + k2 = e2eEnrol(t, s, b).Credentials.ID |
| + } |
| + } |
| + if k2 == "" || k2 == k1 || !storage.KeyLive("production", k1) { |
| + t.Fatal("fixture", k1, k2) |
| + } |
| + e2eReady(t, s, clock()) |
| + loseSeal() |
| + return s, storage, p, k1, k2, add |
| +} |
| + |
| +// TestManaged2B2KeepKeyWithOlderDelivered (fix round 1, Astra P1-1): the |
| +// key boxes use (k2) is deleted while an older delivered key (k1) is still |
| +// live. The fleet reports the missing key, never the delivered-key reason |
| +// whose remedy is deleting k1, the last working key; nothing is reaped, |
| +// minted or launched, and k1 stays. |
| +func TestManaged2B2KeepKeyWithOlderDelivered(t *testing.T) { |
| + s, storage, p, k1, k2, add := keepKeyFleet(t) |
| + storage.DeleteKey("production", k2) |
| + launches, mints := p.Calls()["Launch"], storage.mints |
| + managedAPIReply(t, add("c")) |
| + e2ePass(t, s, time.Now().UTC()) |
| + out := managedAPIReply(t, managedAPICall(s, "show", "abc", "production", "")) |
| + if out.Operation == nil || out.Operation.State != "failed" || out.Operation.Error != managedReasonKeepKeyMissing { |
| + t.Fatalf("operation: %+v", out.Operation) |
| + } |
| + w := add("e") |
| + if w.Code != 409 || !strings.Contains(w.Body.String(), msgManagedKeepKeyMissing) || strings.Contains(w.Body.String(), "delete") { |
| + t.Fatalf("add: %d %s", w.Code, w.Body) |
| + } |
| + out = managedAPIReply(t, managedAPICall(s, "show", "abc", "production", "")) |
| + if out.CredentialState != managedNeedsOperator || out.CredentialReason != managedReasonKeepKeyMissing { |
| + t.Fatalf("show: %+v", out) |
| + } |
| + if p.Calls()["Launch"] != launches || storage.mints != mints || !storage.KeyLive("production", k1) { |
| + t.Fatal("reaped, minted or launched", p.Calls(), storage.mints) |
| + } |
| +} |
| + |
| +// TestManaged2B2KeepKeyInactive (fix round 1, Fable P2-2): the key boxes |
| +// use is deactivated, not deleted. The fleet records needs-operator with |
| +// its own reason; nothing reactivates, replaces, reaps or launches. Once an |
| +// operator makes the key active again, the next add's rotation clears it. |
| +func TestManaged2B2KeepKeyInactive(t *testing.T) { |
| + s, storage, p, k1, k2, add := keepKeyFleet(t) |
| + storage.DeleteKey("production", k1) // only the inactive keep is in the way |
| + storage.DeactivateKey("production", k2) |
| + launches, mints := p.Calls()["Launch"], storage.mints |
| + managedAPIReply(t, add("c")) |
| + e2ePass(t, s, time.Now().UTC()) |
| + out := managedAPIReply(t, managedAPICall(s, "show", "abc", "production", "")) |
| + if out.Operation == nil || out.Operation.State != "failed" || out.Operation.Error != managedReasonKeepKeyInactive { |
| + t.Fatalf("operation: %+v", out.Operation) |
| + } |
| + w := add("e") |
| + if w.Code != 409 || !strings.Contains(w.Body.String(), msgManagedKeepKeyInactive) { |
| + t.Fatalf("add: %d %s", w.Code, w.Body) |
| + } |
| + out = managedAPIReply(t, managedAPICall(s, "show", "abc", "production", "")) |
| + if out.CredentialState != managedNeedsOperator || out.CredentialReason != managedReasonKeepKeyInactive { |
| + t.Fatalf("show: %+v", out) |
| + } |
| + if p.Calls()["Launch"] != launches || storage.mints != mints || !storage.KeyLive("production", k2) { |
| + t.Fatal("reaped, minted or launched", p.Calls(), storage.mints) |
| + } |
| + storage.ActivateKey("production", k2) |
| + if w = add("f"); w.Code != 202 { |
| + t.Fatalf("add after reactivation: %d %s", w.Code, w.Body) |
| + } |
| + if out = managedAPIReply(t, managedAPICall(s, "show", "abc", "production", "")); out.CredentialState != "" { |
| + t.Fatalf("not cleared: %+v", out) |
| + } |
| +} |
diff --git a/internal/console/managed_e2e_test.go b/internal/console/managed_e2e_test.go| index b449230ae..335b6cca9 100644 |
| --- a/internal/console/managed_e2e_test.go |
| +++ b/internal/console/managed_e2e_test.go |
| @@ -491,7 +491,16 @@ func TestManaged2B1Disabled(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| + if bytes.Contains(src, []byte("NewFake")) { |
| + t.Errorf("%s names a fake provider", path) |
| + } |
| ast.Inspect(f, func(n ast.Node) bool { |
| + if kv, ok := n.(*ast.KeyValueExpr); ok { |
| + if id, ok := kv.Key.(*ast.Ident); ok && (id.Name == "ManagedCompute" || id.Name == "ManagedStorage") { |
| + t.Errorf("%s sets a managed provider in a literal", path) |
| + } |
| + return true |
| + } |
| a, ok := n.(*ast.AssignStmt) |
| if !ok { |
| return true |
diff --git a/internal/console/managedhistory.go b/internal/console/managedhistory.go| index bdbf7839f..d1e8e0862 100644 |
| --- a/internal/console/managedhistory.go |
| +++ b/internal/console/managedhistory.go |
| @@ -45,6 +45,15 @@ const msgManagedKeepKeyMissing = "this fleet needs an operator (needs-operator): |
| var errManagedKeepKeyMissing = fmt.Errorf("%w: %s", errManagedNeedsOperator, managedReasonKeepKeyMissing) |
| +// COPY: the deactivated-key reason code and refusal await controller |
| +// review. A complete listing shows the key boxes use deactivated in IAM |
| +// (Fable F P2-2). Nothing reactivates or replaces it; reactivating it in |
| +// IAM lets the next add's rotation clear the state. |
| +const managedReasonKeepKeyInactive = "fleet_access_key_inactive" |
| +const msgManagedKeepKeyInactive = "this fleet needs an operator (needs-operator): the access key this fleet's boxes use is deactivated in IAM. an operator must make it active again before boxes can be added" |
| + |
| +var errManagedKeepKeyInactive = fmt.Errorf("%w: %s", errManagedNeedsOperator, managedReasonKeepKeyInactive) |
| + |
| // managedNeedsOperatorReason is the reason code and refusal for a |
| // needs-operator error; both are the delivered-key ones unless err is the |
| // missing keep key. |
| @@ -52,6 +61,9 @@ func managedNeedsOperatorReason(err error) (reason, msg string) { |
| if errors.Is(err, errManagedKeepKeyMissing) { |
| return managedReasonKeepKeyMissing, msgManagedKeepKeyMissing |
| } |
| + if errors.Is(err, errManagedKeepKeyInactive) { |
| + return managedReasonKeepKeyInactive, msgManagedKeepKeyInactive |
| + } |
| return managedReasonDeliveredKeyLive, msgManagedNeedsOperator |
| } |
| @@ -420,6 +432,8 @@ func (s *Server) rotateManagedCredentials(ctx context.Context, fleet, account, k |
| stuck = errManagedNeedsOperator |
| case keep != "" && errors.Is(e, fleetstore.ErrKeepKeyMissing): |
| stuck = errManagedKeepKeyMissing |
| + case keep != "" && errors.Is(e, fleetstore.ErrKeepKeyInactive): |
| + stuck = errManagedKeepKeyInactive |
| } |
| if stuck != nil { |
| reason, _ := managedNeedsOperatorReason(stuck) |
diff --git a/internal/console/managedstore.go b/internal/console/managedstore.go| index c6e9defa0..ece190700 100644 |
| --- a/internal/console/managedstore.go |
| +++ b/internal/console/managedstore.go |
| @@ -59,7 +59,10 @@ type managedBox struct { |
| // box that missed its readiness deadline gets; BootBreadcrumbs holds the |
| // sanitized breadcrumb codes that read returned (newline-separated, |
| // fixed codes only). Both are set once. |
| + // BootRead is set with them when the read itself succeeded, so show can |
| + // tell "no progress" from "could not be read". |
| BootDiagnosed bool `json:"boot_diagnosed,omitempty"` |
| + BootRead bool `json:"boot_read,omitempty"` |
| BootBreadcrumbs string `json:"boot_breadcrumbs,omitempty"` |
| } |
| @@ -428,7 +431,7 @@ func (s *Store) AdvanceManagedBox(ctx context.Context, before, after managedBox) |
| if before.Boot.IsZero() && !after.Boot.IsZero() && (!before.LaunchStartedAt.IsZero() || after.LaunchStartedAt.IsZero() || after.Boot.Validate() != nil) { |
| return false, errors.New("managed boot inputs are frozen only at launch") |
| } |
| - if before.BootDiagnosed && !after.BootDiagnosed || before.BootBreadcrumbs != "" && before.BootBreadcrumbs != after.BootBreadcrumbs || after.BootBreadcrumbs != "" && !after.BootDiagnosed { |
| + if before.BootDiagnosed && !after.BootDiagnosed || before.BootRead && (!after.BootRead || before.BootBreadcrumbs != after.BootBreadcrumbs) || (after.BootRead || after.BootBreadcrumbs != "") && !after.BootDiagnosed || after.BootBreadcrumbs != "" && !after.BootRead { |
| return false, errors.New("managed boot diagnostics are recorded once") |
| } |
| if before.CloudID != "" && before.CloudID != after.CloudID { |
diff --git a/internal/console/managedview.go b/internal/console/managedview.go| index a70c9ca76..6044fea83 100644 |
| --- a/internal/console/managedview.go |
| +++ b/internal/console/managedview.go |
| @@ -187,6 +187,9 @@ func managedBootShow(b managedBox) string { |
| if !b.BootDiagnosed { |
| return "" |
| } |
| + if !b.BootRead { |
| + return managedBootUnread |
| + } |
| last := b.BootBreadcrumbs |
| if i := strings.LastIndexByte(last, '\n'); i >= 0 { |
| last = last[i+1:] |
| @@ -200,6 +203,10 @@ func managedBootShow(b managedBox) string { |
| // COPY: boot progress sentences await controller copy review. |
| const managedBootNoProgress = "the box left no boot progress on its console" // COPY |
| +// managedBootUnread: the one read failed, or the console stopped before it |
| +// finished; nothing is claimed about the box's console. |
| +const managedBootUnread = "the console could not read the box's boot progress" // COPY |
| + |
| var managedBootText = map[string]string{ |
| managedboot.CodeSeedVerified: "the box verified its first binary but did not start enrolling", // COPY |
| managedboot.CodeEnrolPending: "the box was still waiting to enrol with the console", // COPY |
diff --git a/internal/console/managedworker.go b/internal/console/managedworker.go| index afefd7aa6..cde26f3f9 100644 |
| --- a/internal/console/managedworker.go |
| +++ b/internal/console/managedworker.go |
| @@ -749,6 +749,22 @@ func (s *Server) cleanupManagedBox(ctx context.Context, b managedBox, now time.T |
| if !managedInstanceMatches(b, a) || (b.CloudID != "" && b.CloudID != a.CloudID) { |
| return s.managedRetry(ctx, b, "managed_identity_mismatch", now, true) |
| } |
| + if b.CloudID == "" && a.State != compute.StateTerminated { |
| + // Discovered only now (a lost launch reply, say): the identity-checked |
| + // ID is recorded first, so the one diagnostic read happens before |
| + // any termination intent. |
| + next := b |
| + next.CloudID = a.CloudID |
| + if err = s.saveManagedBox(ctx, b, next, now); err != nil { |
| + return err |
| + } |
| + if b, err = s.loadManagedBox(ctx, b); err != nil { |
| + return err |
| + } |
| + if b, err = s.recordManagedBreadcrumbs(ctx, b, now); err != nil { |
| + return err |
| + } |
| + } |
| next := b |
| next.CloudID = a.CloudID |
| if a.State == compute.StateTerminated { |
| @@ -793,9 +809,10 @@ func (s *Server) cleanupManagedBox(ctx context.Context, b managedBox, now time.T |
| } |
| // managedBreadcrumbsWanted reports whether b is a launched box that missed |
| -// its readiness deadline and has not had its one console-output read. |
| +// its readiness deadline, or used its token without finishing enrolment, |
| +// and has not had its one console-output read. |
| func managedBreadcrumbsWanted(b managedBox) bool { |
| - return b.State == "failed" && b.LastError == "managed_readiness_timeout" && b.CloudID != "" && !b.BootDiagnosed && !b.TerminationConfirmed && b.TerminateAttemptedAt.IsZero() |
| + return b.State == "failed" && (b.LastError == "managed_readiness_timeout" || b.LastError == "managed_enrolment_incomplete") && b.CloudID != "" && !b.BootDiagnosed && !b.TerminationConfirmed && b.TerminateAttemptedAt.IsZero() |
| } |
| // recordManagedBreadcrumbs is the only ConsoleOutput call site. Inside the |
| @@ -804,7 +821,8 @@ func managedBreadcrumbsWanted(b managedBox) bool { |
| // or a failed read never leads to a second one. The call runs outside the |
| // fleet lock, and only the fixed breadcrumb codes are kept (the provider |
| // already sanitizes; this keeps the console's own copy just as narrow). |
| -// A failed read records nothing more; cleanup continues either way. |
| +// A successful read sets BootRead, even with no codes; a failed read is |
| +// logged by class and records nothing more. Cleanup continues either way. |
| func (s *Server) recordManagedBreadcrumbs(ctx context.Context, b managedBox, now time.Time) (managedBox, error) { |
| if !managedBreadcrumbsWanted(b) { |
| return b, nil |
| @@ -823,18 +841,32 @@ func (s *Server) recordManagedBreadcrumbs(ctx context.Context, b managedBox, now |
| if err = s.managedOutsideLock(ctx, b, func(c context.Context) { out, outErr = s.cfg.ManagedCompute.ConsoleOutput(c, b.Region, b.CloudID) }); err != nil { |
| return b, err |
| } |
| - codes := managedBreadcrumbCodes(out) |
| - if outErr != nil || codes == "" { |
| + if outErr != nil { |
| + // The class only: provider errors are fixed text, but no console |
| + // output ever reaches a log. |
| + log.Printf("console: managed box %s/%s: boot progress could not be read (%s)", b.Fleet, b.Label, managedOutputErrClass(outErr)) |
| return b, nil |
| } |
| next = b |
| - next.BootBreadcrumbs = codes |
| + next.BootRead = true |
| + next.BootBreadcrumbs = managedBreadcrumbCodes(out) |
| if err = s.saveManagedBox(ctx, b, next, now); err != nil { |
| return b, err |
| } |
| return s.loadManagedBox(ctx, b) |
| } |
| +// managedOutputErrClass names a console-output failure without its text. |
| +func managedOutputErrClass(err error) string { |
| + switch { |
| + case errors.Is(err, compute.ErrIdentityMismatch): |
| + return "identity mismatch" |
| + case errors.Is(err, context.DeadlineExceeded), errors.Is(err, context.Canceled): |
| + return "timed out" |
| + } |
| + return "provider error" |
| +} |
| + |
| // managedBreadcrumbLimit matches the provider sanitizer's line bound. |
| const managedBreadcrumbLimit = 32 |
diff --git a/internal/fleetstore/fake.go b/internal/fleetstore/fake.go| index 83ad9c7bb..b8414f668 100644 |
| --- a/internal/fleetstore/fake.go |
| +++ b/internal/fleetstore/fake.go |
| @@ -13,13 +13,15 @@ type Fake struct { |
| storage map[string]FleetStorage |
| keys map[string]map[string]bool |
| latest map[string]string |
| - nextKey uint64 |
| + // inactive holds "<fleet>/<id>" for keys an operator deactivated. |
| + inactive map[string]bool |
| + nextKey uint64 |
| } |
| var _ Provisioner = (*Fake)(nil) |
| func NewFake() *Fake { |
| - return &Fake{storage: make(map[string]FleetStorage), keys: make(map[string]map[string]bool), latest: make(map[string]string)} |
| + return &Fake{storage: make(map[string]FleetStorage), keys: make(map[string]map[string]bool), latest: make(map[string]string), inactive: make(map[string]bool)} |
| } |
| func (f *Fake) EnsureFleetStorage(ctx context.Context, fleet, region string) (FleetStorage, error) { |
| f.mu.Lock() |
| @@ -52,14 +54,18 @@ func (f *Fake) RotateFleetCredentials(ctx context.Context, fleet, keep string, d |
| return Credentials{}, err |
| } |
| keys := f.keys[fleet] |
| + // As the AWS adapter: the keep key first, then the delivered keys. |
| + if keep != "" && !keys[keep] { |
| + return Credentials{}, ErrKeepKeyMissing |
| + } |
| + if keep != "" && f.inactive[fleet+"/"+keep] { |
| + return Credentials{}, ErrKeepKeyInactive |
| + } |
| for _, id := range delivered { |
| if id != keep && keys[id] { |
| return Credentials{}, fmt.Errorf("%w: %s", ErrDeliveredKeyStillLive, id) |
| } |
| } |
| - if keep != "" && !keys[keep] { |
| - return Credentials{}, ErrKeepKeyMissing |
| - } |
| if keys == nil { |
| keys = make(map[string]bool) |
| f.keys[fleet] = keys |
| @@ -83,6 +89,19 @@ func (f *Fake) DeleteKey(fleet, id string) { |
| delete(f.keys[fleet], id) |
| } |
| +// DeactivateKey marks one key inactive, as an operator deactivating it in |
| +// IAM would; ActivateKey undoes that. |
| +func (f *Fake) DeactivateKey(fleet, id string) { |
| + f.mu.Lock() |
| + defer f.mu.Unlock() |
| + f.inactive[fleet+"/"+id] = true |
| +} |
| +func (f *Fake) ActivateKey(fleet, id string) { |
| + f.mu.Lock() |
| + defer f.mu.Unlock() |
| + delete(f.inactive, fleet+"/"+id) |
| +} |
| + |
| // KeyLive reports whether the fleet still holds key id. |
| func (f *Fake) KeyLive(fleet, id string) bool { |
| f.mu.Lock() |
diff --git a/internal/fleetstore/provisioner.go b/internal/fleetstore/provisioner.go| index 748635c98..5feb24786 100644 |
| --- a/internal/fleetstore/provisioner.go |
| +++ b/internal/fleetstore/provisioner.go |
| @@ -15,6 +15,11 @@ var ErrDeliveredKeyStillLive = errors.New("delivered key still live") |
| // proves absence returns it; a failed or partial listing is another error. |
| var ErrKeepKeyMissing = errors.New("key to keep does not exist") |
| +// ErrKeepKeyInactive refuses a rotation, before any key is removed or |
| +// minted, when a complete listing shows the nonempty keep key deactivated. |
| +// Nothing reactivates or replaces it automatically. |
| +var ErrKeepKeyInactive = errors.New("key to keep is not active") |
| + |
| type Credentials struct { |
| ID string `json:"id"` |
| Secret []byte `json:"secret"` |
| @@ -27,7 +32,9 @@ type Provisioner interface { |
| // one. delivered is every key ID ever handed to a box; if any of them |
| // other than keep still exists it returns ErrDeliveredKeyStillLive and |
| // changes nothing. If keep is nonempty and a complete listing proves it |
| - // absent it returns ErrKeepKeyMissing and changes nothing. |
| + // absent it returns ErrKeepKeyMissing, or deactivated ErrKeepKeyInactive, |
| + // and changes nothing; both take precedence over |
| + // ErrDeliveredKeyStillLive. |
| // Implementations check a complete key listing. |
| RotateFleetCredentials(ctx context.Context, fleet, keep string, delivered []string) (Credentials, error) |
| } |
diff --git a/internal/host/managed2b2_onebox_linux_test.go b/internal/host/managed2b2_onebox_linux_test.go| new file mode 100644 |
| index 000000000..b00df7b05 |
| --- /dev/null |
| +++ b/internal/host/managed2b2_onebox_linux_test.go |
| @@ -0,0 +1,609 @@ |
| +//go:build linux |
| + |
| +package host |
| + |
| +// Managed fleets 2b-2 Task 6: one managed box end to end. A real console |
| +// (built through its exported API, served over TLS) creates the fleet, |
| +// launches into a fake cloud and serves its real doors; the box is this |
| +// package's production managed boot over a fake root, its real prober and |
| +// managed join, a root door running root's real admission code against |
| +// that fake root, and provision.Reconcile. External dependencies are fakes: |
| +// the cloud (compute.Fake), IAM/S3 provisioning (fleetstore.Fake), the |
| +// fleet bucket (a DirStore, and a fake S3 endpoint for the probe), systemd |
| +// and exec (the boot fixture's recorder) and the fleet hub (an in-process |
| +// stand-in that checks the console's signature, as the hub does, and asks |
| +// the box's own probe handler). Steps that need real root and real systemd |
| +// are cited to their root-runner witnesses in the Task 6 report. |
| + |
| +import ( |
| + "bufio" |
| + "bytes" |
| + "context" |
| + "crypto/ed25519" |
| + "crypto/rand" |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "io" |
| + "net/http" |
| + "net/http/httptest" |
| + "os" |
| + "path/filepath" |
| + "strconv" |
| + "strings" |
| + "sync" |
| + "syscall" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/activator" |
| + "github.com/carlosframework/platform/internal/compute" |
| + "github.com/carlosframework/platform/internal/console" |
| + "github.com/carlosframework/platform/internal/edge" |
| + "github.com/carlosframework/platform/internal/edgeproof" |
| + "github.com/carlosframework/platform/internal/fleetstore" |
| + "github.com/carlosframework/platform/internal/managedboot" |
| + "github.com/carlosframework/platform/internal/managedboot/boottest" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/status" |
| + "github.com/carlosframework/platform/internal/tunnelclient" |
| +) |
| + |
| +// obCloud is the fake cloud: it records each launch's frozen request and |
| +// counts console-output reads. |
| +type obCloud struct { |
| + *compute.Fake |
| + mu sync.Mutex |
| + specs []compute.LaunchSpec |
| +} |
| + |
| +func (c *obCloud) Launch(ctx context.Context, s compute.LaunchSpec) (compute.Instance, error) { |
| + c.mu.Lock() |
| + c.specs = append(c.specs, s) |
| + c.mu.Unlock() |
| + return c.Fake.Launch(ctx, s) |
| +} |
| + |
| +// obStorage is fleetstore.Fake with AWS-shaped answers, so the box's own |
| +// reply checks accept what the console delivers. |
| +type obStorage struct { |
| + *fleetstore.Fake |
| + mu sync.Mutex |
| + n int |
| +} |
| + |
| +func (p *obStorage) EnsureFleetStorage(ctx context.Context, fleet, region string) (fleetstore.FleetStorage, error) { |
| + got, err := p.Fake.EnsureFleetStorage(ctx, fleet, region) |
| + if err != nil { |
| + return got, err |
| + } |
| + sum := sha256.Sum256([]byte(fleet)) |
| + return fleetstore.FleetStorage{Bucket: "carlos-fleet-" + hex.EncodeToString(sum[:])[:24], Region: got.Region}, nil |
| +} |
| +func (p *obStorage) RotateFleetCredentials(ctx context.Context, fleet, keep string, delivered []string) (fleetstore.Credentials, error) { |
| + if _, err := p.Fake.RotateFleetCredentials(ctx, fleet, "", nil); err != nil { |
| + return fleetstore.Credentials{}, err |
| + } |
| + p.mu.Lock() |
| + defer p.mu.Unlock() |
| + p.n++ |
| + return fleetstore.Credentials{ID: fmt.Sprintf("AKIAEXAMPLE%09d", p.n), Secret: []byte(fmt.Sprintf("examplesecret%027d", p.n))}, nil |
| +} |
| + |
| +// obRootDoor is the instance-control root door over the fake root: root's |
| +// real CommitAdmission and RootAdmission code, with the test's uid and the |
| +// admission directory's gid standing in for root. |
| +type obRootDoor struct { |
| + root string |
| + owner managedboot.RootOwner |
| +} |
| + |
| +func (d obRootDoor) ManagedAdmit(_ context.Context, wire []byte) error { |
| + return managedboot.CommitAdmissionAs(d.root, wire, d.owner) |
| +} |
| +func (d obRootDoor) ManagedAdmission(context.Context) (bool, bool, error) { |
| + return managedboot.RootAdmissionAs(d.root, d.owner) |
| +} |
| + |
| +// hubTransport routes the console's fleet-hub requests to an in-process |
| +// hub; everything else goes through the default transport. |
| +type hubTransport struct { |
| + host string |
| + hub http.Handler |
| + next http.RoundTripper |
| +} |
| + |
| +func (h hubTransport) RoundTrip(r *http.Request) (*http.Response, error) { |
| + if r.URL.Host != h.host { |
| + return h.next.RoundTrip(r) |
| + } |
| + w := httptest.NewRecorder() |
| + h.hub.ServeHTTP(w, r) |
| + return w.Result(), nil |
| +} |
| + |
| +type oneBoxWorld struct { |
| + t *testing.T |
| + ctx context.Context |
| + srv *console.Server |
| + ts *httptest.Server |
| + store *release.DirStore |
| + cloud *obCloud |
| + token string |
| + box *mbFixture |
| + bucket *release.DirStore |
| + s3 *fakeS3 |
| + reg *registry.Registry |
| + edge *edge.Edge |
| + svc *activator.Service |
| + eb *activator.ExecBackend |
| + join *managedJoin |
| + door obRootDoor |
| + now time.Time |
| + hubHits int |
| + stable string |
| +} |
| + |
| +// obAccount is account 42's sqid (domains.Sqid(42)), as the record |
| +// reconciler checks it. |
| +const obAccount = "bbw" |
| + |
| +func newOneBoxWorld(t *testing.T) *oneBoxWorld { |
| + t.Helper() |
| + ctx := context.Background() |
| + w := &oneBoxWorld{t: t, ctx: ctx, store: release.NewDirStore(t.TempDir()), now: time.Now().UTC(), stable: "v0.35.1"} |
| + pub, priv, err := ed25519.GenerateKey(rand.Reader) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + // The console, over TLS. |
| + var handler http.Handler |
| + w.ts = httptest.NewTLSServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { handler.ServeHTTP(rw, r) })) |
| + t.Cleanup(w.ts.Close) |
| + dir := t.TempDir() |
| + st, err := console.Open(filepath.Join(dir, "console.db")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { st.Close() }) |
| + w.cloud = &obCloud{Fake: compute.NewFake()} |
| + cfg := console.Config{Origin: w.ts.URL, Keymail: "https://keymail.example", Releases: w.store, Registry: filepath.Join(dir, "registry.db"), |
| + AlertSealKeyPath: filepath.Join(dir, "seal"), Key: priv, ReleasePub: pub, TunnelHost: mbtTunnelHost, |
| + ManagedCompute: w.cloud, ManagedStorage: &obStorage{Fake: fleetstore.NewFake()}, ManagedDeployment: "test"} |
| + if _, err = provision.WriteHostsState(ctx, w.store, provision.HostsState{Mode: provision.HostsModeIncomplete}, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err = edge.MintMeshKey(ctx, w.store); err != nil { |
| + t.Fatal(err) |
| + } |
| + // The stable release: its linux-arm64 artifact is both the seed the |
| + // console freezes and the binary the box installs. |
| + body := []byte("#!/bin/true stable release " + w.stable + "\n") |
| + sum := sha256.Sum256(body) |
| + art := release.SystemArtifact{Key: release.SystemArtifactKey(w.stable, managedboot.SeedArtifactPlatform), SHA256: hex.EncodeToString(sum[:])} |
| + if _, err = w.store.Put(ctx, art.Key, body, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err = release.PromoteSystem(ctx, w.store, release.RootSigner(priv), "router", "stable", release.SystemRelease{Version: w.stable, ReleaseTag: w.stable, |
| + Artifacts: map[string]release.SystemArtifact{managedboot.SeedArtifactPlatform: art}}, release.SystemPromoteOptions{}); err != nil { |
| + t.Fatal(err) |
| + } |
| + conf, _ := json.Marshal(map[string]any{"enabled": true, "ceiling": 10, "account_limit": 0, "regions": map[string]any{ |
| + "eu-west-1": map[string]any{"image": "image", "subnets": []string{"subnet-a"}, "security_groups": []string{"sg"}, "root_gb": 20, "sizes": map[string]string{"large": "m7g.large"}}}}) |
| + if _, err = w.store.Put(ctx, release.ManagedFleetsConfigKey, conf, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if w.srv, err = console.NewServer(cfg, st); err != nil { |
| + t.Fatal(err) |
| + } |
| + handler = w.srv |
| + watch := release.NewChangeWatch(w.store) |
| + if _, err = watch.Poll(ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err = w.srv.SetManagedConfigWatch(ctx, watch); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err = st.CreateAccount(42, obAccount, "shop", "owner@example.com", w.now); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err = st.AddMember(42, "member@example.com", console.RoleMember, w.now); err != nil { |
| + t.Fatal(err) |
| + } |
| + user, device, err := st.NewCLIAuth("test", "192.0.2.1", w.now) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err = st.ApproveCLIAuth(user, "member@example.com", w.now); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, w.token, _, err = st.PollCLIAuth(device, w.now); err != nil || w.token == "" { |
| + t.Fatal("cli token", err) |
| + } |
| + // The fleet hub the console probes through. |
| + prev := http.DefaultTransport |
| + http.DefaultTransport = hubTransport{host: mbtTunnelHost, hub: http.HandlerFunc(w.hub), next: prev} |
| + t.Cleanup(func() { http.DefaultTransport = prev }) |
| + // The fleet bucket's S3 endpoint, for the probe's static-key client. |
| + w.s3 = &fakeS3{objects: map[string][]byte{}, fail: map[string]int{}} |
| + s3srv := httptest.NewServer(w.s3) |
| + t.Cleanup(s3srv.Close) |
| + t.Setenv("CARLOS_S3_ENDPOINT", s3srv.URL) |
| + w.bucket = release.NewDirStore(t.TempDir()) |
| + return w |
| +} |
| + |
| +// api calls a console CLI route as the member. |
| +func (w *oneBoxWorld) api(method, path, body string) (int, []byte) { |
| + w.t.Helper() |
| + r, err := http.NewRequest(method, w.ts.URL+path, strings.NewReader(body)) |
| + if err != nil { |
| + w.t.Fatal(err) |
| + } |
| + r.Header.Set("Authorization", "Bearer "+w.token) |
| + r.Header.Set("Content-Type", "application/json") |
| + resp, err := w.ts.Client().Do(r) |
| + if err != nil { |
| + w.t.Fatal(err) |
| + } |
| + defer resp.Body.Close() |
| + b, _ := io.ReadAll(resp.Body) |
| + return resp.StatusCode, b |
| +} |
| + |
| +type obShow struct { |
| + Boxes []struct { |
| + Label, State, Boot string |
| + LastError string `json:"last_error"` |
| + Checks map[string]struct{ State, Reason string } |
| + } |
| + Operation *struct{ State, Outcome string } |
| +} |
| + |
| +func (w *oneBoxWorld) show() obShow { |
| + w.t.Helper() |
| + code, body := w.api("GET", "/api/cli/fleets/"+obAccount+"/shop", "") |
| + var out obShow |
| + if code != 200 || json.Unmarshal(body, &out) != nil { |
| + w.t.Fatalf("show: %d %s", code, body) |
| + } |
| + return out |
| +} |
| + |
| +func (w *oneBoxWorld) pass(at time.Time) { |
| + w.t.Helper() |
| + if err := w.srv.RunManagedFleetsPass(w.ctx, at); err != nil { |
| + w.t.Fatalf("worker pass: %v", err) |
| + } |
| +} |
| + |
| +// createAndLaunch creates the fleet through the CLI door and runs the |
| +// worker until the box is launched; it returns the user data. |
| +func (w *oneBoxWorld) createAndLaunch() string { |
| + w.t.Helper() |
| + body := fmt.Sprintf(`{"name":"shop","managed":true,"region":"eu-west-1","size":"large","boxes":1,"request_id":%q}`, strings.Repeat("a", 22)) |
| + if code, out := w.api("POST", "/api/cli/fleets/"+obAccount+"/new", body); code != 202 && code != 200 { |
| + w.t.Fatalf("create: %d %s", code, out) |
| + } |
| + w.pass(w.now) |
| + w.cloud.mu.Lock() |
| + defer w.cloud.mu.Unlock() |
| + if len(w.cloud.specs) != 1 { |
| + w.t.Fatalf("launches: %d", len(w.cloud.specs)) |
| + } |
| + return w.cloud.specs[0].UserData |
| +} |
| + |
| +// bootBox lays the box's disk out as cloud-init and the seed script leave |
| +// it (the seed fetched through the console's seed door and checked against |
| +// the frozen digest), then runs the production managed boot once. |
| +func (w *oneBoxWorld) bootBox(userData string) { |
| + t := w.t |
| + t.Helper() |
| + in, err := managedboot.DecodeLaunchInput([]byte(boottest.Heredoc(userData, "BOOTINPUT"))) |
| + if err != nil { |
| + t.Fatal("boot input:", err) |
| + } |
| + seedReq := strings.TrimSpace(boottest.Heredoc(userData, "SEEDREQUEST")) |
| + code, seed := w.post("/api/fleet/enrol/seed", seedReq) |
| + sum := sha256.Sum256(seed) |
| + if code != 200 || hex.EncodeToString(sum[:]) != in.Frozen.SeedSHA256 { |
| + t.Fatalf("seed door: %d", code) |
| + } |
| + f := newMBFixture(t) |
| + f.in = in |
| + input, err := json.Marshal(in) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + f.write(managedboot.BootInputPath, append(input, '\n'), 0o600) |
| + f.write(managedboot.SeedRequestPath, []byte(seedReq+"\n"), 0o600) |
| + f.write("/var/lib/carlos-managed-boot/seed", seed, 0o700) |
| + for _, p := range []string{"user-data.txt", "user-data.txt.i", "scripts/part-001", "obj.pkl"} { |
| + f.write("/var/lib/cloud/instances/i-0abc/"+p, []byte(userData), 0o600) |
| + } |
| + f.client = w.ts.Client() |
| + f.dir = w.store |
| + f.store.Store = w.store |
| + f.openStoreFn = func(env map[string]string) (release.Store, error) { |
| + if env["CARLOS_TUNNEL_URL"] != "https://"+mbtTunnelHost || len(env["CARLOS_TUNNEL_TOKEN"]) != 64 { |
| + return nil, errors.New("store door opened without the committed tunnel") |
| + } |
| + return w.store, nil |
| + } |
| + f.fleetStore = func(context.Context, map[string]string) (release.Store, error) { return w.bucket, nil } |
| + w.box = f |
| + if err = f.boot(""); err != nil { |
| + t.Fatalf("managed boot: %v (crumbs %v, logs %v)", err, f.crumbs, f.logs) |
| + } |
| +} |
| + |
| +func (w *oneBoxWorld) post(path, body string) (int, []byte) { |
| + w.t.Helper() |
| + resp, err := w.ts.Client().Post(w.ts.URL+path, "application/json", strings.NewReader(body)) |
| + if err != nil { |
| + w.t.Fatal(err) |
| + } |
| + defer resp.Body.Close() |
| + b, _ := io.ReadAll(resp.Body) |
| + return resp.StatusCode, b |
| +} |
| + |
| +// hostEnv is the box's committed host.env. |
| +func (w *oneBoxWorld) hostEnv() map[string]string { |
| + w.t.Helper() |
| + raw, err := os.ReadFile(w.box.path(managedboot.HostEnvPath)) |
| + if err != nil { |
| + w.t.Fatal(err) |
| + } |
| + env := map[string]string{} |
| + sc := bufio.NewScanner(bytes.NewReader(raw)) |
| + for sc.Scan() { |
| + if k, v, ok := strings.Cut(sc.Text(), "="); ok { |
| + env[k] = v |
| + } |
| + } |
| + return env |
| +} |
| + |
| +// agent is the box's agent after the boot queued its edge: the managed |
| +// join against the root door, the prober and the box edge with the join's |
| +// admission hooks, as runAgent wires them. |
| +func (w *oneBoxWorld) agent() { |
| + t := w.t |
| + t.Helper() |
| + st, err := os.Stat(w.box.path(managedboot.RootAdmissionDir)) |
| + if err != nil { |
| + t.Fatal("root admission directory:", err) |
| + } |
| + w.door = obRootDoor{root: w.box.root, owner: managedboot.RootOwner{UID: os.Getuid(), GID: int(st.Sys().(*syscall.Stat_t).Gid)}} |
| + w.join = newManagedJoinAt(w.box.root, w.door, func(string, ...any) {}) |
| + if w.join == nil || w.join.refused || !w.join.Joining() { |
| + t.Fatalf("join: %+v", w.join) |
| + } |
| + env := w.hostEnv() |
| + p := managedProberFor(w.join) |
| + p.getenv = func(k string) string { return env[k] } |
| + p.readCreds = func() ([]byte, error) { return os.ReadFile(w.box.path(managedboot.CredentialsPath)) } |
| + w.reg = openTestRegistry(t) |
| + w.eb = &activator.ExecBackend{} |
| + w.svc = activator.New(activator.Config{}, w.eb, w.reg) |
| + if w.edge, err = edge.New(w.reg, w.svc); err != nil { |
| + t.Fatal(err) |
| + } |
| + w.join.bind(w.svc, w.eb)(w.edge) |
| + edge.WithManagedProbe(p)(w.edge) |
| +} |
| + |
| +// heartbeat is the agent's status tick: the box's own key status file read |
| +// by managedKeyHeartbeat, published to the console's store. |
| +func (w *oneBoxWorld) heartbeat(at time.Time) string { |
| + w.t.Helper() |
| + prevRoot, prevOwner := managedKeyStatusRoot, managedKeyStatusOwner |
| + managedKeyStatusRoot, managedKeyStatusOwner = w.box.root, os.Getuid() |
| + key := managedKeyHeartbeat() |
| + managedKeyStatusRoot, managedKeyStatusOwner = prevRoot, prevOwner |
| + beat, _ := json.Marshal(status.Box{Label: "box-1", GeneratedAt: at, ManagedKey: key, Metrics: &status.BoxMetrics{Release: w.stable, RootfsReady: true, Tunnel: "connected"}}) |
| + k := "fleets/shop/status/boxes/box-1.json" |
| + _, etag, _ := w.store.Get(w.ctx, k) |
| + if _, err := w.store.Put(w.ctx, k, beat, etag); err != nil { |
| + w.t.Fatal(err) |
| + } |
| + return key |
| +} |
| + |
| +// hub checks the console's signature as the fleet hub does (the request's |
| +// own channel, the mirrored mesh key, ±30 s), delivers the probe to the box |
| +// over its tunnel marker, and attests the channel on an exact echo. |
| +func (w *oneBoxWorld) hub(rw http.ResponseWriter, r *http.Request) { |
| + w.hubHits++ |
| + body, _ := io.ReadAll(io.LimitReader(r.Body, managedboot.MaxProbeRequest+1)) |
| + req, err := managedboot.ParseProbeRequest(body) |
| + cur, _, kerr := edgeproof.LoadKeys(r.Context(), w.store) |
| + auth := r.Header.Get(edge.FleetProbeAuthHeader) |
| + ts, _, _ := strings.Cut(auth, ":") |
| + sec, _ := strconv.ParseInt(ts, 10, 64) |
| + if r.URL.Path != edge.FleetProbePath || err != nil || kerr != nil || auth != edge.SignFleetProbe(cur, nil, req.Channel(), body, time.Unix(sec, 0)) { |
| + rw.WriteHeader(http.StatusUnauthorized) |
| + return |
| + } |
| + if w.edge == nil { |
| + rw.WriteHeader(http.StatusServiceUnavailable) |
| + return |
| + } |
| + br := httptest.NewRequest(http.MethodPost, "https://"+mbtTunnelHost+"/__carlos/managed-probe", bytes.NewReader(body)) |
| + br.Header.Set(tunnelclient.ManagedProbeHeader, "1") |
| + bw := httptest.NewRecorder() |
| + tunnelclient.Mark(w.edge).ServeHTTP(bw, br) |
| + reply, err := managedboot.ParseProbeReply(bw.Body.Bytes()) |
| + if bw.Code != 200 || err != nil || !reply.Echoes(req) { |
| + rw.WriteHeader(http.StatusBadGateway) |
| + return |
| + } |
| + rw.Header().Set(edge.FleetProbeChannelHeader, req.Channel()) |
| + rw.Write(bw.Body.Bytes()) |
| +} |
| + |
| +// shopRecord is the native app placed on the fleet, in the deployment |
| +// store the box reads through its store door. |
| +func (w *oneBoxWorld) shopRecord() provision.Record { |
| + w.t.Helper() |
| + if _, _, err := w.store.Get(w.ctx, "accounts/"+obAccount+"/account.json"); errors.Is(err, os.ErrNotExist) { |
| + if _, err = w.store.Put(w.ctx, "accounts/"+obAccount+"/account.json", []byte(`{"id":42,"sqid":"`+obAccount+`","name":"shop","created_at":"2026-11-09T00:00:00Z"}`), ""); err != nil { |
| + w.t.Fatal(err) |
| + } |
| + } |
| + if err := provision.PutManifest(w.ctx, w.store, obAccount, "shop", provision.Manifest{Schema: 1, App: "shop", Domain: "example.com", Pool: "shop"}); err != nil { |
| + w.t.Fatal(err) |
| + } |
| + rec := provision.Record{Schema: 1, Host: "shop.example.com", Slug: "shop", App: "shop", Account: obAccount, Pool: "shop", Region: "fleet/shop", Channel: "stable", CreatedAt: time.Now().UTC()} |
| + if err := provision.CreateRecord(w.ctx, w.store, rec); err != nil { |
| + w.t.Fatal(err) |
| + } |
| + return rec |
| +} |
| + |
| +func (w *oneBoxWorld) reconcile() { |
| + w.t.Helper() |
| + cfg := provision.ReconcileConfig{Region: "fleet/shop", FleetBox: "box-1", Pools: []string{"shop"}, DataDir: "/data", Joining: w.join.Joining, Now: time.Now} |
| + if err := provision.Reconcile(w.ctx, w.store, w.reg, cfg); err != nil { |
| + w.t.Fatalf("reconcile: %v", err) |
| + } |
| +} |
| + |
| +// TestManaged2B2OneBox: create → frozen boot → seed → trade → staged → |
| +// key minted and registered → stable installed → edge queued → joining |
| +// heartbeat and probe → six checks → signed ready.json → agent relays → |
| +// root commits → the native shop record reconciles and may start. Nothing |
| +// is placed or allowed to start before root's record. |
| +func TestManaged2B2OneBox(t *testing.T) { |
| + w := newOneBoxWorld(t) |
| + userData := w.createAndLaunch() |
| + w.bootBox(userData) |
| + f := w.box |
| + f.assertSucceeded() |
| + // Staged and installed: credentials, host.env, identity, the stable |
| + // binary, the fleet key in host.env, its status ok; the edge queued. |
| + for _, p := range []string{managedboot.CredentialsPath, managedboot.HostEnvPath, managedboot.IdentityPath, mbStableBinary} { |
| + if !f.exists(p) { |
| + t.Fatalf("%s not installed", p) |
| + } |
| + } |
| + if bin, _ := os.ReadFile(f.path(mbStableBinary)); !strings.Contains(string(bin), "stable release "+w.stable) { |
| + t.Fatalf("stable binary %q", bin) |
| + } |
| + env := w.hostEnv() |
| + if env["CARLOS_SECRETS_KEY"] == "" { |
| + t.Fatal("no fleet key installed") |
| + } |
| + if raw, _, err := w.bucket.Get(w.ctx, managedboot.FleetKeyObject); err != nil || len(raw) == 0 { |
| + t.Fatal("fleet key object not minted", err) |
| + } |
| + if n := f.count("systemctl start --no-block carlos-edge.service"); n != 1 { |
| + t.Fatalf("edge queued %d times", n) |
| + } |
| + if out := w.show(); len(out.Boxes) != 1 || out.Boxes[0].State != "joining" { |
| + t.Fatalf("after trade: %+v", out.Boxes) |
| + } |
| + |
| + w.agent() |
| + rec := w.shopRecord() |
| + rt := registry.Route{Host: rec.Host, Kind: "instance", App: "shop", Account: obAccount, Status: "ready", Hibernate: true, Socket: "/run/carlos/" + rec.Host + ".sock"} |
| + // Joining: nothing placed, nothing may start. |
| + w.reconcile() |
| + if got, _ := w.reg.Get(rec.Host); got != nil { |
| + t.Fatal("placed before root's record") |
| + } |
| + if _, err := w.eb.Acquire(w.ctx, rt); !errors.Is(err, activator.ErrTenantAdmission) { |
| + t.Fatalf("start allowed while joining: %v", err) |
| + } |
| + |
| + // A minute of joining: heartbeat and probe from the box itself. |
| + at := w.now.Add(time.Minute) |
| + if key := w.heartbeat(at); key != managedboot.KeyStatusOK { |
| + t.Fatalf("heartbeat managed_key %q", key) |
| + } |
| + w.pass(at) |
| + w.pass(at.Add(10 * time.Second)) |
| + out := w.show() |
| + if out.Boxes[0].State != "ready" || out.Operation == nil || out.Operation.State != "done" || out.Operation.Outcome != "success" { |
| + t.Fatalf("console: %+v %+v", out.Boxes, out.Operation) |
| + } |
| + for name, c := range out.Boxes[0].Checks { |
| + if c.State != "pass" { |
| + t.Fatalf("check %s: %+v", name, c) |
| + } |
| + } |
| + if w.hubHits == 0 || len(w.s3.objects) != 0 { |
| + t.Fatalf("probe: %d hub requests, %d objects left", w.hubHits, len(w.s3.objects)) |
| + } |
| + // Still joining until the agent relays and root commits. |
| + w.reconcile() |
| + if got, _ := w.reg.Get(rec.Host); got != nil || !w.join.Joining() { |
| + t.Fatal("placed before root's record") |
| + } |
| + |
| + // The agent's ready leg: one read through the store door, relayed to |
| + // root, which verifies and commits. |
| + if !w.join.readyLeg(w.ctx, w.store, time.Now(), 1, true) { |
| + t.Fatal("ready leg did not admit") |
| + } |
| + if managed, admitted, err := w.door.ManagedAdmission(w.ctx); !managed || !admitted || err != nil { |
| + t.Fatalf("root admission: %v %v %v", managed, admitted, err) |
| + } |
| + if !f.exists(managedboot.AdmittedMarker) { |
| + t.Fatal("no admitted marker") |
| + } |
| + w.reconcile() |
| + got, err := w.reg.Get(rec.Host) |
| + if err != nil || got == nil || !got.Provisioned { |
| + t.Fatalf("shop not placed after admission: %+v %v", got, err) |
| + } |
| + if !w.svc.TenantAdmitted() || !w.eb.TenantStartAllowed(*got) { |
| + t.Fatal("start still refused after admission") |
| + } |
| +} |
| + |
| +// TestManaged2B2KeyFailureStatus: the fleet bucket already holds a malformed |
| +// key object. The box's real key step loads it, installs no key and records |
| +// object_invalid; the agent's heartbeat carries it; the console fails |
| +// storage with the key reason, writes no ready object, and the deadline |
| +// cleans the box up with its one console-output read. |
| +func TestManaged2B2KeyFailureStatus(t *testing.T) { |
| + w := newOneBoxWorld(t) |
| + userData := w.createAndLaunch() |
| + if _, err := w.bucket.Put(w.ctx, managedboot.FleetKeyObject, []byte(`{"schema":1,"fleet":"shop","public":"not a key"}`), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + w.bootBox(userData) |
| + if env := w.hostEnv(); env["CARLOS_SECRETS_KEY"] != "" { |
| + t.Fatal("a key was installed from a malformed object") |
| + } |
| + w.agent() |
| + at := w.now.Add(time.Minute) |
| + if key := w.heartbeat(at); key != managedboot.KeyStatusObjectInvalid { |
| + t.Fatalf("heartbeat managed_key %q", key) |
| + } |
| + w.pass(at) |
| + out := w.show() |
| + if out.Boxes[0].State != "joining" || out.Boxes[0].Checks["storage"].State != "fail" || !strings.Contains(out.Boxes[0].Checks["storage"].Reason, "is not valid") { |
| + t.Fatalf("show: %+v", out.Boxes) |
| + } |
| + if _, _, err := w.store.Get(w.ctx, "fleets/shop/boxes/box-1/ready.json"); err == nil { |
| + t.Fatal("ready object written for a box whose key failed") |
| + } |
| + if !w.join.Joining() { |
| + t.Fatal("admitted") |
| + } |
| + deadline := w.now.Add(20 * time.Minute) |
| + w.pass(deadline) |
| + w.pass(deadline.Add(15 * time.Second)) |
| + out = w.show() |
| + if out.Boxes[0].LastError != "managed_readiness_timeout" || w.cloud.Calls()["ConsoleOutput"] != 1 || w.cloud.Calls()["Terminate"] != 1 || out.Boxes[0].Boot == "" { |
| + t.Fatalf("deadline: %+v %v", out.Boxes, w.cloud.Calls()) |
| + } |
| +} |
diff --git a/internal/host/managedboot_linux_test.go b/internal/host/managedboot_linux_test.go| index 987371252..c13094ea3 100644 |
| --- a/internal/host/managedboot_linux_test.go |
| +++ b/internal/host/managedboot_linux_test.go |
| @@ -97,6 +97,9 @@ type mbFixture struct { |
| // the fleet bucket and the console's managed key door. nil skips it. |
| fleetStore func(ctx context.Context, env map[string]string) (release.Store, error) |
| keyDoor http.HandlerFunc |
| + // openStoreFn replaces the store door check, for a box enrolled by a |
| + // real console whose tunnel token the fixture cannot know. |
| + openStoreFn func(env map[string]string) (release.Store, error) |
| } |
| func newMBFixture(t *testing.T) *mbFixture { |
| @@ -349,6 +352,9 @@ func (f *mbFixture) boot(crashAt string) error { |
| f.mu.Unlock() |
| }, |
| openStore: func(env map[string]string) (release.Store, error) { |
| + if f.openStoreFn != nil { |
| + return f.openStoreFn(env) |
| + } |
| if env["CARLOS_TUNNEL_URL"] != "https://"+mbtTunnelHost || env["CARLOS_TUNNEL_TOKEN"] != mbtTunnelToken { |
| return nil, errors.New("store door opened without the committed tunnel") |
| } |
diff --git a/internal/provision/testdata/plan14-root-reads-managed-fleets-2b2.tsv b/internal/provision/testdata/plan14-root-reads-managed-fleets-2b2.tsv| index 9c05c56b3..2e67cef8c 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-managed-fleets-2b2.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-managed-fleets-2b2.tsv |
| @@ -110,7 +110,7 @@ internal/managedboot/cloudinit_v1.sh.tmpl external legacy accepted-legacy accept |
| internal/managedboot/identity_linux.go readRootOwned legacy accepted-legacy accepted-legacy;rev3=census-ruling-managed-fleets-2b2;basis=the O_NOFOLLOW openat walk moved out of loadIdentity unchanged (every component owned by the expected uid, not g/o writable; regular, nlink 1, size cap), parameterised by path and limit; callers: loadIdentity (/etc/carlos/managed-box.json, 4 KiB) and loadKeyStatus (/etc/carlos/managed-key-status.json, 1 KiB) file:Fstat@775,file:Open@130,file:Openat@532,file:ReadAll@1099 3f2a099882de9ffaac6189a3a844f3a3026cf02398ed7d6d247ae9461de29a09 |
| internal/managedboot/probe.go NewProbeNonce legacy accepted-legacy accepted-legacy;rev3=census-ruling-managed-fleets-2b2;basis=new: 32 bytes from crypto/rand, hex; no file read file:Read@76 9cda7dd058dd62cc5928b9c7c58f0d66a1ea59c4cd023e0fb50b63c3d0917b18 |
| internal/host/namedrecovery_pass.go namedUnitRecovery.passOption authority B3,E1 Production recovery wrapper preserves main exit status for per-host failures; only remaining named routes can probe the census for history selection. Ordinary routes make no census or binding-store reads. Fixtures: TestPlan14ERecoveryOrdinaryPass, TestPlan14Fix4AdoptPerHostFailureExitsZero, TestPlan14Fix5MainEquivalence.;rev3=census-ruling-managed-fleets-2b2;basis=asks refusedByGate before recover; on refusal recovers nothing; the whole:Route site is the route handed to refusedByGate for its log line, no new read registry:Host@333,registry:Host@557,registry:Unit@510,registry:Unit@527,whole:Route@273,whole:Route@470,whole:Route@502 3e50e426466ebfd148adea21d70fba68fa86cf5d9e4d226953f6fe4abe3a5ea5 |
| -@coverage . 98732a5cd3008a88366bff6577e3148ec514d72bf960dfa2fe5c7ed0b5369bbd |
| +@coverage . 82ccb7423ba3369c7006bf66105dda9953c70202a8048eb44657cecf82d8bbac |
| @coverage internal/appconfig 7238cd97ab717ace4651cd2fbf236b8c923e76d5bddfd5235d7ed0d11d1bf325 |
| @coverage internal/edge eae9918f14a21f508008346a242692364b29b5aeb67bb6dd64f6496034f5623b |
| @coverage internal/host 02ed999cc2400765c0820d2aa5152f13d8ef687d88f597798e5358438931eb2d |