Console-minted credentials seal to the app's own key (Task 6a): the store, mail, scan callback, webhook rotation, instance store and team environment mail seal sites take an appconfig.Sealer from sealKeyFor, so a fleet app's credential is sealed to its fleet's key (SealedTo set, v2) and an app on a keyless fleet is refused before any backend call (FSK-C44, FSK-C45)
objstore (writeEnv, Grant, GrantIn, GrantInFor, Rotate, RotateIn and their claimRaw twins) and mail (writeSMTPEnv/In, Enable, Rotate, EnableEnvironment and their claimUnserialized twins) take seal appconfig.Sealer instead of *ecdh.PublicKey and store the Var Seal returns. storeSealKey and mailSealKey take (w, ctx, acct, app) and map sealKeyFor's errors: keyless fleet 409 with the approved row, no or unreadable deployment key the existing 503s, an app gone since the gate 404, anything else logged and 502. instanceStorePreflight returns (Sealer, bool). convergeCallbackKey and rotateWebhookBudget take no key; each app's comes from sealKeyFor, and the rotation skips (and leaves in remaining) an app whose key cannot be chosen. Plan storage gets the minimal wiring (log and skip); 6b settles its semantics and lock. Relay is untouched (6b). Account lock (lockAccount), by entry point: - takes it (before the store walk lock and any app lock): handleAPIStoreGrant, handleAPIStoreRotate, handleAPIStoreProvision, handleAPIEmailEnable, handleAPIEmailRotate (seal path, not -finish), handleAPIScanGrant (when a callback signer is set), handleAPIScanRevoke, handleAPIScanEnforce, handleAPIScanCallbackRotate, handleAPISystemWebhookRotate (per app inside rotateWebhookBudget), runFrom (the detached seed copy, around instanceStoreProvisionFor), handleAPIEnvironmentAdopt (around mintOwnedEnvironment, after its app lock is released), handleAPIConfigPut (now also for any team write into an environment, not only one carrying a sealed value, so a new team environment's mail mint runs under it). - already holds it, takes nothing more: instance create, seeded and imported creates (apiinstances.go planLock, plans on; with plans off the private store seal runs unlocked, an accepted I2 gap noted in instanceStoreProvisionFor); mintOwnedEnvironmentMail under the config PUT and email enable; app create (apicli.go planLock) seals nothing here. - unlocked, owned elsewhere: handleAPIEnvironmentFork's mint (Task 7 takes the lock before its app lock); plan storage's convergeStoreDeny (6b). The store provision queueing probe now watches the account lock, where a second provision waits. The two callback convergence races run their concurrent writer behind the door: the in-process door now waits on the lock the pass holds. Tests: TestStoreGrantOnKeylessFleetRefusesBeforeBackend, TestStoreGrantOnFleetSealsToTheFleetKey, TestMailEnableOnFleetSealsToTheFleetKey, TestMailEnableOnKeylessFleetRefusesBeforeBackend, TestWebhookRotateUsesEachAppsKey, TestAppCreateAdoptingFleetAppDoesNotDeadlock, TestInstanceCreatePrivateStoreOnFleetDoesNotDeadlock, TestTeamEnvironmentCreateOnFleetDoesNotDeadlock (plans on and off, 5 s).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
approved_fleet_secrets_copy_test.go+4 −2internal/console/apiconfig.go+7 −2internal/console/apienv.go+5 −0internal/console/apiinstanceseed.go+10 −1internal/console/apimail.go+22 −20internal/console/apiscan.go+28 −16internal/console/apiscan_keys_test.go+4 −11internal/console/apiscan_rotation_race_test.go+4 −6internal/console/apistore.go+57 −20internal/console/apistore_provision.go+6 −2internal/console/apistore_provision_test.go+8 −3internal/console/apisystem.go+19 −8internal/console/fleetsecrets_mint_test.go+383 −0internal/console/instanceprivatestore.go+16 −8internal/console/planstorage.go+7 −5internal/console/scan_review_regression_test.go+6 −18internal/console/scankeysync.go+28 −6internal/console/scankeysync_test.go+29 −14internal/console/teamcreds.go+9 −7internal/console/teamcreds_test.go+3 −3internal/mail/claim_gate_closure_test.go+1 −1internal/mail/sealer_helper_test.go+14 −0internal/mail/walk.go+16 −17internal/mail/walk_domainremove_test.go+1 −1internal/mail/walk_enable_test.go+20 −20internal/mail/walk_environment.go+5 −6internal/mail/walk_environment_test.go+10 −10internal/mail/walk_lifecycle_test.go+21 −21internal/mail/walk_verify_test.go+1 −1internal/objstore/enforce_test.go+3 −3internal/objstore/nameclaim_test.go+1 −1internal/objstore/walk.go+21 −22internal/objstore/walk_env_test.go+9 −9internal/objstore/walk_seed_test.go+4 −4internal/objstore/walk_test.go+47 −40internal/objstore/writesdenied_test.go+2 −2
Intent
<task-notification> <task-id>a769dfc11bbfdf41e</task-id> <tool-use-id>toolu_01Xfk8WNx9H8owPaqXp1sGR7</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2d812478-ae68-44f2-8075-b2330abd5939/tasks/a769dfc11bbfdf41e.output</output-file> <status>completed</status> <summary>Agent "Implement Task 5: sealKeyFor and config" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Status: DONE (fix round 1). The backfill no longer overwrites a place or an unplace that commits while it runs. Commit: 174a3972 on `design-fleet-secrets-key`. The commit printed the known `packed-refs.lock` hook error; `git log` shows it landed. Fix: `backfillAppPlacements` still lists routes once, but now only to pick candidates. For each candidate, `backfillApp` takes the account lock and then the app lock, which is the lock `placeAppTarget` writes under. It re-reads the column and the routes under those locks, and writes only if the column is still empty and the fresh routes still say `fleet/<f>`. Tests: - **New race test:** a place, an unplace, or a column written without its routes lands between the listing and the write. It failed on the reviewed code with `"fleet/home", want "fleet/away"` and `want ""`, and passes now. - **New lock test:** a place arrives while the backfill holds its locks, after its reads and before its write. It has to wait for the lock, land afterwards and win. - **Mutations:** each of three fails a test: no app lock, no column re-read, the listing's stale routes. - **Covering run:** `-run 'TestBackfillAppPlacements|TestSealKeyFor|TestConfigPut'` over `./internal/console/` passes; vet, build, gofmt and the cross-builds pass. Concerns: none new. - My first lock test passed even with the app lock removed, because the fresh route read hid it. I moved the hook to just before the write, and that mutation now fails. - The backfill now lists routes once per candidate. Only legacy apps are candidates, and the pass runs once per start. - The earlier concerns still stand; they are in the report. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/.superpowers/sdd/2026-10-29-fleet-secrets-key/task-5-report.md (fix round 1 is appended at the end)</result> <usage><subagent_tokens>269672</subagent_tokens><tool_uses>12</tool_uses><duration_ms>342759</duration_ms></usage> </task-notification>
<task-notification> <task-id>aca6272042a264c10</task-id> <tool-use-id>toolu_01Xs4r1bbS66Q7yJJWCUfbpm</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2d812478-ae68-44f2-8075-b2330abd5939/tasks/aca6272042a264c10.output</output-file> <status>completed</status> <summary>Agent "Re-review Task 5 fix round 1" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Finding (backfillAppPlacements writing placement without the app lock): ADDRESSED. No new Critical or Important breakage in the fix diff. The lock order is account then app, matching applocks.go. The only non-test caller is the startup goroutine in cmd/console/main.go, which holds neither lock. I did not re-run the tests. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/.superpowers/sdd/2026-10-29-fleet-secrets-key/task-5-rereview-1.md</result> <usage><subagent_tokens>56218</subagent_tokens><tool_uses>8</tool_uses><duration_ms>52717</duration_ms></usage> </task-notification>
Attributed to this commit: 62.0 g CO₂e (3,163,693 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-fleet-secrets-key, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/approved_fleet_secrets_copy_test.go b/approved_fleet_secrets_copy_test.go| index ad01eadb5..6003679a7 100644 |
| --- a/approved_fleet_secrets_copy_test.go |
| +++ b/approved_fleet_secrets_copy_test.go |
| @@ -55,7 +55,8 @@ var fleetSecretsCopyStatuses = []string{"pending", "approved", "struck"} |
| // fleetSecretsCopyBuilt is every id whose text the code or docs carry. The |
| // task that writes a row's text adds its id here in the same commit, once the |
| // row is approved. Task 3 built the door, BYO page and fleet page rows; Task 4 the CLI rows; |
| -// Task 5 sealKeyFor's refusals and the config door's. |
| +// Task 5 sealKeyFor's refusals and the config door's; Task 6a the store and |
| +// email doors' keyless-fleet refusals. |
| var fleetSecretsCopyBuilt = []string{ |
| "FSK-C01", "FSK-C02", "FSK-C03", "FSK-C04", |
| "FSK-C05", "FSK-C06", "FSK-C07", "FSK-C08", |
| @@ -67,7 +68,8 @@ var fleetSecretsCopyBuilt = []string{ |
| "FSK-C29", "FSK-C30", "FSK-C31", "FSK-C32", |
| "FSK-C33", "FSK-C34", "FSK-C35", "FSK-C36", |
| "FSK-C37", "FSK-C38", "FSK-C39", "FSK-C40", |
| - "FSK-C41", "FSK-C42", "FSK-C43", |
| + "FSK-C41", "FSK-C42", "FSK-C43", "FSK-C44", |
| + "FSK-C45", |
| } |
| func mustParseFleetSecretsRecord(t *testing.T) []copyRow { |
diff --git a/internal/console/apiconfig.go b/internal/console/apiconfig.go| index 612fd58b1..0e8f1e857 100644 |
| --- a/internal/console/apiconfig.go |
| +++ b/internal/console/apiconfig.go |
| @@ -507,9 +507,12 @@ func (s *Server) handleAPIConfigPut(w http.ResponseWriter, r *http.Request) { |
| // lock and then sees this value. Taken here, at the door, before any |
| // app lock (teamApplyEnvironment's comes after: account, then app). |
| // Nothing below takes the account lock again: planLock is only on the |
| - // create doors. A plain env write takes no lock. |
| + // create doors. A team write into an environment holds it too, sealed |
| + // value or not: one that brings the environment into being mints its |
| + // platform credentials (mintOwnedEnvironment) under it, sealed to the |
| + // key chosen there (Task 6). Any other plain env write takes no lock. |
| unlockAcct := func() {} |
| - if configSetsSecret(sets) { |
| + if configSetsSecret(sets) || (team && envName != "") { |
| unlock := s.lockAccount(acct.Sqid) |
| held := true |
| unlockAcct = func() { |
| @@ -519,6 +522,8 @@ func (s *Server) handleAPIConfigPut(w http.ResponseWriter, r *http.Request) { |
| } |
| } |
| defer unlockAcct() |
| + } |
| + if configSetsSecret(sets) { |
| if !s.configCheckSealedTo(w, r, ctx, acct, app, keys, sets) { |
| return |
| } |
diff --git a/internal/console/apienv.go b/internal/console/apienv.go| index 3145c3901..5bee22c6f 100644 |
| --- a/internal/console/apienv.go |
| +++ b/internal/console/apienv.go |
| @@ -178,7 +178,12 @@ func (s *Server) handleAPIEnvironmentAdopt(w http.ResponseWriter, r *http.Reques |
| Detail: fmt.Sprintf("adopted environment %s into team scope %s, platform-managed keys left out: %s (cli)", env, req.Scope, noneOr(stripped)), |
| }) |
| s.bumpSerial(ctx) |
| + // The mint seals to the key sealKeyFor chooses, under the account lock |
| + // (fleet secrets key spec §5.2.1). Taken here, after the app lock above |
| + // was released, so the lock order holds. |
| + unlockAcct := s.lockAccount(acct.Sqid) |
| s.mintOwnedEnvironment(ctx, acct, app, env) |
| + unlockAcct() |
| writeJSON(w, http.StatusOK, map[string]any{"environment": env, "scope": req.Scope, "stripped": stripped}) |
| } |
diff --git a/internal/console/apiinstanceseed.go b/internal/console/apiinstanceseed.go| index 1126eed88..279f708ca 100644 |
| --- a/internal/console/apiinstanceseed.go |
| +++ b/internal/console/apiinstanceseed.go |
| @@ -441,9 +441,18 @@ func (s *Server) runFrom(j *fromCopy) { |
| if c.m.PrivateStorage { |
| // Its refusals are written to a held answer nobody reads but this: |
| - // the sentence becomes the seed's reason. |
| + // the sentence becomes the seed's reason. A seal key sealKeyFor |
| + // cannot give (a keyless fleet, no deployment key) is one of them, |
| + // refused before the backend is touched, its sentence the store |
| + // door's. |
| held := &heldResponse{header: http.Header{}} |
| + // The account lock from the seal key's choice through the grant |
| + // (fleet secrets key spec §5.2.1). This goroutine is an entry point: |
| + // the door that started it, which may hold the lock through |
| + // planLock, answered before it ran and holds nothing it waits on. |
| + unlockAcct := s.lockAccount(acct.Sqid) |
| storeRec, ok, err := s.instanceStoreProvisionFor(ctx, held, acct, app, c.rec.Environment, c.principal, j.id) |
| + unlockAcct() |
| if !ok { |
| reason := held.message(failed) |
| switch { |
diff --git a/internal/console/apimail.go b/internal/console/apimail.go| index d42deb970..c0f585f7a 100644 |
| --- a/internal/console/apimail.go |
| +++ b/internal/console/apimail.go |
| @@ -49,7 +49,6 @@ package console |
| import ( |
| "context" |
| - "crypto/ecdh" |
| "errors" |
| "fmt" |
| "log" |
| @@ -147,21 +146,18 @@ func (s *Server) mailWriteGates(w http.ResponseWriter, addr string) bool { |
| // the system (see storeSealKey's own doc comment for why). Enable and |
| // Rotate need it; CreateStandalone does not, because a standalone |
| // credential is displayed, never sealed into config (mail.StandaloneCreds' |
| -// doc comment). |
| -func (s *Server) mailSealKey(w http.ResponseWriter) (*ecdh.PublicKey, bool) { |
| - if s.cfg.SecretsPub == "" { |
| - jsonError(w, http.StatusServiceUnavailable, |
| - "this console has no secrets key (CARLOS_SECRETS_PUBKEY) — it cannot deliver an email credential, so it will not enable sending") |
| - return nil, false |
| - } |
| - pub, err := appconfig.ParsePublicKey(s.cfg.SecretsPub, "CARLOS_SECRETS_PUBKEY") |
| - if err != nil { |
| - log.Printf("console: api email seal key: %v", err) |
| - jsonError(w, http.StatusServiceUnavailable, |
| - "this console's secrets key (CARLOS_SECRETS_PUBKEY) cannot be read — it cannot deliver an email credential, so it will not enable sending") |
| - return nil, false |
| - } |
| - return pub, true |
| +// doc comment). The key is the app's own (sealKeyFor); an app on a keyless |
| +// fleet is refused, never sealed to the deployment key. |
| +func (s *Server) mailSealKey(w http.ResponseWriter, ctx context.Context, acct *Account, app string) (appconfig.Sealer, bool) { |
| + sealer, err := s.sealKeyFor(ctx, acct.Sqid, app) |
| + var keyless errFleetNoSecretsKey |
| + if errors.As(err, &keyless) { |
| + jsonError(w, http.StatusConflict, fmt.Sprintf("%s has no secrets key, so the console cannot deliver an email credential to %s and will not enable sending. run carlos fleets secrets-key %s <pubkey>", keyless.Fleet, app, keyless.Fleet)) |
| + return appconfig.Sealer{}, false |
| + } |
| + return sealer, sealKeyAnswered(w, "email", acct, app, err, |
| + "this console has no secrets key (CARLOS_SECRETS_PUBKEY) — it cannot deliver an email credential, so it will not enable sending", |
| + "this console's secrets key (CARLOS_SECRETS_PUBKEY) cannot be read — it cannot deliver an email credential, so it will not enable sending") |
| } |
| // mailOperator reports whether addr may drive the pause/cap door — a |
| @@ -1275,7 +1271,10 @@ func (s *Server) handleAPIEmailEnable(w http.ResponseWriter, r *http.Request) { |
| if !s.mailWriteGates(w, addr) { |
| return |
| } |
| - pub, ok := s.mailSealKey(w) |
| + // The account lock from the key choice through the delivery (fleet |
| + // secrets key spec §5.2.1), before any app lock. |
| + defer s.lockAccount(acct.Sqid)() |
| + sealer, ok := s.mailSealKey(w, r.Context(), acct, app) |
| if !ok { |
| return |
| } |
| @@ -1304,7 +1303,7 @@ func (s *Server) handleAPIEmailEnable(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| - rec, err := mail.Enable(ctx, s.claimMailStore(), s.cfg.MailProvisioner, pub, s.cfg.MailDeployment, acct.Sqid, app, time.Now()) |
| + rec, err := mail.Enable(ctx, s.claimMailStore(), s.cfg.MailProvisioner, sealer, s.cfg.MailDeployment, acct.Sqid, app, time.Now()) |
| switch { |
| case errors.Is(err, mail.ErrNotDeclared): |
| jsonError(w, http.StatusConflict, "no email is declared for this app — declare it first") |
| @@ -1376,13 +1375,16 @@ func (s *Server) handleAPIEmailRotate(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| - pub, ok := s.mailSealKey(w) |
| + // The account lock from the key choice through the delivery (fleet |
| + // secrets key spec §5.2.1), before any app lock. |
| + defer s.lockAccount(acct.Sqid)() |
| + sealer, ok := s.mailSealKey(w, r.Context(), acct, app) |
| if !ok { |
| return |
| } |
| ctx, cancel := context.WithTimeout(r.Context(), mailRotateTimeout) |
| defer cancel() |
| - rec, err := mail.Rotate(ctx, s.claimMailStore(), s.cfg.MailProvisioner, pub, s.cfg.MailDeployment, acct.Sqid, app, time.Now()) |
| + rec, err := mail.Rotate(ctx, s.claimMailStore(), s.cfg.MailProvisioner, sealer, s.cfg.MailDeployment, acct.Sqid, app, time.Now()) |
| switch { |
| case errors.Is(err, mail.ErrNotDeclared): |
| jsonError(w, http.StatusConflict, "no email is declared for this app — declare it first") |
diff --git a/internal/console/apiscan.go b/internal/console/apiscan.go| index f4a82e9a2..6f4b73713 100644 |
| --- a/internal/console/apiscan.go |
| +++ b/internal/console/apiscan.go |
| @@ -22,7 +22,6 @@ package console |
| import ( |
| "context" |
| - "crypto/ecdh" |
| "crypto/rand" |
| "encoding/binary" |
| "errors" |
| @@ -327,10 +326,13 @@ func (s *Server) handleAPIScanGrant(w http.ResponseWriter, r *http.Request) { |
| scanNoEngine(w) |
| return |
| } |
| - var pub *ecdh.PublicKey |
| + var sealer appconfig.Sealer |
| if s.cfg.CallbackSigner != nil { |
| + // The account lock from the key choice through the delivery (fleet |
| + // secrets key spec §5.2.1), before any app lock. |
| + defer s.lockAccount(acct.Sqid)() |
| var ok bool |
| - pub, ok = s.storeSealKey(w) |
| + sealer, ok = s.storeSealKey(w, r.Context(), acct, app) |
| if !ok { |
| return |
| } |
| @@ -419,11 +421,11 @@ func (s *Server) handleAPIScanGrant(w http.ResponseWriter, r *http.Request) { |
| } |
| if s.cfg.CallbackSigner != nil { |
| err = s.appMutation(ctx, acct, app, "scan-regrant", func(ctx context.Context) error { |
| - if err := s.regrantForScanning(ctx, pub, acct, app, addr); err != nil { |
| + if err := s.regrantForScanning(ctx, sealer, acct, app, addr); err != nil { |
| return err |
| } |
| var syncErr error |
| - _, rec, syncErr = s.convergeCallbackKey(ctx, pub, acct, app) |
| + _, rec, syncErr = s.convergeCallbackKey(ctx, acct, app) |
| return syncErr |
| }) |
| if err != nil { |
| @@ -458,7 +460,10 @@ func (s *Server) handleAPIScanRevoke(w http.ResponseWriter, r *http.Request) { |
| if !s.storeWalkGates(w, p) { |
| return |
| } |
| - pub, ok := s.storeSealKey(w) |
| + // The account lock from the key choice through the delivery (fleet |
| + // secrets key spec §5.2.1), before any app lock. |
| + defer s.lockAccount(acct.Sqid)() |
| + sealer, ok := s.storeSealKey(w, r.Context(), acct, app) |
| if !ok { |
| return |
| } |
| @@ -502,7 +507,7 @@ func (s *Server) handleAPIScanRevoke(w http.ResponseWriter, r *http.Request) { |
| // this the record would say enforcement is off while the live policy still |
| // denied reads — the exact drift the whole enforcement design exists to |
| // avoid. |
| - if err := s.regrantForScanning(ctx, pub, acct, app, addr); err != nil { |
| + if err := s.regrantForScanning(ctx, sealer, acct, app, addr); err != nil { |
| log.Printf("console: api scan revoke %s/%s: regrant: %v", acct.Sqid, app, err) |
| jsonError(w, http.StatusBadGateway, |
| "the record was cleared but the store policy was not rewritten — re-run `carlos store grant` to converge it") |
| @@ -549,7 +554,10 @@ func (s *Server) handleAPIScanEnforce(w http.ResponseWriter, r *http.Request) { |
| jsonError(w, http.StatusBadRequest, "say which: `carlos store scan enforce on` or `... off`") |
| return |
| } |
| - pub, ok := s.storeSealKey(w) |
| + // The account lock from the key choice through the delivery (fleet |
| + // secrets key spec §5.2.1), before any app lock. |
| + defer s.lockAccount(acct.Sqid)() |
| + sealer, ok := s.storeSealKey(w, r.Context(), acct, app) |
| if !ok { |
| return |
| } |
| @@ -603,7 +611,7 @@ func (s *Server) handleAPIScanEnforce(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| - if err := s.regrantForScanning(ctx, pub, acct, app, addr); err != nil { |
| + if err := s.regrantForScanning(ctx, sealer, acct, app, addr); err != nil { |
| log.Printf("console: api scan enforce %s/%s: regrant: %v", acct.Sqid, app, err) |
| jsonError(w, http.StatusBadGateway, |
| "the record was updated but the store policy was not rewritten — re-run `carlos store grant` to converge it") |
| @@ -628,7 +636,7 @@ var ( |
| // |
| // A store that was never granted has no policy to converge, so this is a |
| // no-op for it rather than an error. |
| -func (s *Server) regrantForScanning(ctx context.Context, pub *ecdh.PublicKey, acct *Account, app, addr string) error { |
| +func (s *Server) regrantForScanning(ctx context.Context, sealer appconfig.Sealer, acct *Account, app, addr string) error { |
| rec, _, err := objstore.Get(ctx, s.cfg.Releases, acct.Sqid, app) |
| if err != nil { |
| return err |
| @@ -649,13 +657,13 @@ func (s *Server) regrantForScanning(ctx context.Context, pub *ecdh.PublicKey, ac |
| } |
| _, err = claimAppCall(s, ctx, acct, app, "scan-regrant", func(ctx context.Context) (*objstore.Record, error) { |
| return objstore.Grant(ctx, s.cfg.Releases, s.cfg.StoreProvisioner, s.cfg.StoreDeployment, |
| - pub, acct.Sqid, app, addr, source, "", time.Now()) |
| + sealer, acct.Sqid, app, addr, source, "", time.Now()) |
| }) |
| return err |
| } |
| -func (s *Server) deliverCallbackSecret(ctx context.Context, pub *ecdh.PublicKey, acct, app string, rec *objstore.Record, gen int) error { |
| - _, err := s.deliverCallbackRevision(ctx, pub, acct, app, rec, gen) |
| +func (s *Server) deliverCallbackSecret(ctx context.Context, sealer appconfig.Sealer, acct, app string, rec *objstore.Record, gen int) error { |
| + _, err := s.deliverCallbackRevision(ctx, sealer, acct, app, rec, gen) |
| return err |
| } |
| @@ -689,8 +697,12 @@ func (s *Server) handleAPIScanCallbackRotate(w http.ResponseWriter, r *http.Requ |
| if !s.storeWalkGates(w, p) { |
| return |
| } |
| - pub, ok := s.storeSealKey(w) |
| - if !ok { |
| + // The account lock from the key choice through the delivery (fleet |
| + // secrets key spec §5.2.1), before any app lock. The gate refuses an |
| + // app with no key to seal to before anything is written; the delivery |
| + // (convergeCallbackKey) chooses the same key again, under this lock. |
| + defer s.lockAccount(acct.Sqid)() |
| + if _, ok := s.storeSealKey(w, r.Context(), acct, app); !ok { |
| return |
| } |
| if s.cfg.CallbackSigner == nil { |
| @@ -739,7 +751,7 @@ func (s *Server) handleAPIScanCallbackRotate(w http.ResponseWriter, r *http.Requ |
| if err != nil { |
| return err |
| } |
| - _, rec, err = s.convergeCallbackKey(ctx, pub, acct, app) |
| + _, rec, err = s.convergeCallbackKey(ctx, acct, app) |
| return err |
| }) |
| switch { |
diff --git a/internal/console/apiscan_keys_test.go b/internal/console/apiscan_keys_test.go| index 840ce59a5..d18c9f575 100644 |
| --- a/internal/console/apiscan_keys_test.go |
| +++ b/internal/console/apiscan_keys_test.go |
| @@ -8,7 +8,6 @@ import ( |
| "testing" |
| "time" |
| - "github.com/carlosframework/platform/internal/appconfig" |
| "github.com/carlosframework/platform/internal/objstore" |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| @@ -80,11 +79,7 @@ func TestRotateWebhookKeySkipsUnchangedApps(t *testing.T) { |
| counter := &callbackPutCounter{Store: fx.rel} |
| fx.srv.cfg.Releases = counter |
| - pub, err := appconfig.ParsePublicKey(fx.srv.cfg.SecretsPub, "test") |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background(), pub) |
| + remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -100,8 +95,7 @@ func TestRotateWebhookKeyDoesNotDropPrevious(t *testing.T) { |
| enableDeploymentScanning(t, fx) |
| grantScanning(t, fx, token, "titogo") |
| fx.srv.cfg.CallbackSigner = callbackTestSigner(t, "new-master", testWebhookMaster) |
| - pub, _ := appconfig.ParsePublicKey(fx.srv.cfg.SecretsPub, "test") |
| - if _, _, err := fx.srv.rotateWebhookBudget(context.Background(), pub); err != nil { |
| + if _, _, err := fx.srv.rotateWebhookBudget(context.Background()); err != nil { |
| t.Fatal(err) |
| } |
| if fx.srv.cfg.CallbackSigner.previous == nil || fx.srv.cfg.CallbackSigner.previous.id == "" { |
| @@ -163,11 +157,10 @@ func TestRotateIsBudgetedAndResumable(t *testing.T) { |
| } |
| grantScanning(t, fx, token, "second") |
| fx.srv.cfg.CallbackSigner = callbackTestSigner(t, "replacement-master", testWebhookMaster) |
| - pub, _ := appconfig.ParsePublicKey(fx.srv.cfg.SecretsPub, "test") |
| ctx, cancel := context.WithCancel(context.Background()) |
| counter := &callbackPutCounter{Store: fx.rel, cancel: cancel} |
| fx.srv.cfg.Releases = counter |
| - remaining, changed, err := fx.srv.rotateWebhookBudget(ctx, pub) |
| + remaining, changed, err := fx.srv.rotateWebhookBudget(ctx) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -175,7 +168,7 @@ func TestRotateIsBudgetedAndResumable(t *testing.T) { |
| t.Fatalf("bounded rotation = changed %d remaining %d, want 1/1", changed, remaining) |
| } |
| counter.cancel = nil |
| - remaining, changed, err = fx.srv.rotateWebhookBudget(context.Background(), pub) |
| + remaining, changed, err = fx.srv.rotateWebhookBudget(context.Background()) |
| if err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/console/apiscan_rotation_race_test.go b/internal/console/apiscan_rotation_race_test.go| index 0aebba5a6..7f0729bfc 100644 |
| --- a/internal/console/apiscan_rotation_race_test.go |
| +++ b/internal/console/apiscan_rotation_race_test.go |
| @@ -78,9 +78,8 @@ func TestDeploymentRotateDeliversTheGenerationHeldUnderThePermit(t *testing.T) { |
| editRecord(t, fx, func(rec *objstore.Record) { rec.Scanning.WebhookGen++ }) |
| }} |
| fx.srv.cfg.Releases = runner |
| - pub, _ := appconfig.ParsePublicKey(fx.srv.cfg.SecretsPub, "test") |
| - remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background(), pub) |
| + remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -105,7 +104,7 @@ func TestDeploymentRotateSkipsWorkFinishedBeforeThePermit(t *testing.T) { |
| runner = &racingRunner{Store: fx.rel, action: "scan-webhook-rotate", race: func(ctx context.Context) { |
| cur := storedRecord(t, fx, "titogo") |
| gen := cur.Scanning.WebhookGen + 1 |
| - if err := fx.srv.deliverCallbackSecret(ctx, pub, fx.sqid, "titogo", cur, gen); err != nil { |
| + if err := fx.srv.deliverCallbackSecret(ctx, consoleTestSealer(pub, fx.sqid, "titogo"), fx.sqid, "titogo", cur, gen); err != nil { |
| t.Fatal(err) |
| } |
| manifest, err := appconfig.Get(ctx, fx.rel, fx.sqid, "titogo") |
| @@ -121,7 +120,7 @@ func TestDeploymentRotateSkipsWorkFinishedBeforeThePermit(t *testing.T) { |
| }} |
| fx.srv.cfg.Releases = runner |
| - remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background(), pub) |
| + remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -143,9 +142,8 @@ func TestDeploymentRotateLeavesARevokedAppAlone(t *testing.T) { |
| revokeBehindTheDoor(t, fx) |
| }} |
| fx.srv.cfg.Releases = runner |
| - pub, _ := appconfig.ParsePublicKey(fx.srv.cfg.SecretsPub, "test") |
| - remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background(), pub) |
| + remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background()) |
| if err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/console/apistore.go b/internal/console/apistore.go| index bd5bdd789..ef1df0513 100644 |
| --- a/internal/console/apistore.go |
| +++ b/internal/console/apistore.go |
| @@ -34,7 +34,6 @@ package console |
| import ( |
| "context" |
| - "crypto/ecdh" |
| "encoding/json" |
| "errors" |
| "fmt" |
| @@ -684,23 +683,53 @@ func (s *Server) storeWalkGates(w http.ResponseWriter, p Principal) bool { |
| // backend, it is billable, its secret died in this process, and only a reap |
| // finds it again. So grant and rotate refuse before the first backend call |
| // rather than after. Finish does not call this at all: it seals nothing. |
| -func (s *Server) storeSealKey(w http.ResponseWriter) (*ecdh.PublicKey, bool) { |
| - if s.cfg.SecretsPub == "" { |
| - jsonError(w, http.StatusServiceUnavailable, |
| - "this console has no secrets key (CARLOS_SECRETS_PUBKEY) — it cannot deliver a store credential, so it will not mint one") |
| - return nil, false |
| +// |
| +// The key is the app's own (sealKeyFor): its fleet's key for an app placed |
| +// on a fleet, the deployment key for an app placed nowhere. An app on a |
| +// fleet with no key is refused here, never sealed to the deployment key, |
| +// which its boxes do not hold. It takes no lock: the door holds the account |
| +// lock from this call through its write (fleet secrets key spec §5.2.1). |
| +func (s *Server) storeSealKey(w http.ResponseWriter, ctx context.Context, acct *Account, app string) (appconfig.Sealer, bool) { |
| + sealer, err := s.sealKeyFor(ctx, acct.Sqid, app) |
| + var keyless errFleetNoSecretsKey |
| + if errors.As(err, &keyless) { |
| + jsonError(w, http.StatusConflict, fmt.Sprintf("%s has no secrets key, so the console cannot deliver a store credential to %s and will not mint one. run carlos fleets secrets-key %s <pubkey>", keyless.Fleet, app, keyless.Fleet)) |
| + return appconfig.Sealer{}, false |
| } |
| - pub, err := appconfig.ParsePublicKey(s.cfg.SecretsPub, "CARLOS_SECRETS_PUBKEY") |
| - if err != nil { |
| - // Logged with the parse detail, answered without it: the caller cannot |
| - // fix this console's configuration and the sentence they get is the one |
| - // that tells the operator where to look. |
| - log.Printf("console: api store seal key: %v", err) |
| - jsonError(w, http.StatusServiceUnavailable, |
| - "this console's secrets key (CARLOS_SECRETS_PUBKEY) cannot be read — it cannot deliver a store credential, so it will not mint one") |
| - return nil, false |
| + return sealer, sealKeyAnswered(w, "store", acct, app, err, |
| + "this console has no secrets key (CARLOS_SECRETS_PUBKEY) — it cannot deliver a store credential, so it will not mint one", |
| + "this console's secrets key (CARLOS_SECRETS_PUBKEY) cannot be read — it cannot deliver a store credential, so it will not mint one") |
| +} |
| + |
| +// sealKeyAnswered answers every sealKeyFor outcome but a keyless fleet, |
| +// which each door words for its own credential, and reports whether the |
| +// door may go on (err nil). noKey and badKey are the door's sentences for |
| +// a platform app on a console without a usable deployment key, the |
| +// refusals these doors have always made. An app that went since the |
| +// door's gate saw it gets the gate's own 404, as the config door does; any |
| +// other failure (a registry read, a placement naming another account's |
| +// fleet) is logged and refused with the config door's retry sentence: |
| +// nothing was minted, and the detail is not the caller's. |
| +func sealKeyAnswered(w http.ResponseWriter, door string, acct *Account, app string, err error, noKey, badKey string) bool { |
| + var unknown errUnknownApp |
| + switch { |
| + case err == nil: |
| + return true |
| + case errors.Is(err, errNoDeploymentKey): |
| + jsonError(w, http.StatusServiceUnavailable, noKey) |
| + case errors.Is(err, errDeploymentKeyUnreadable): |
| + // Logged with the parse detail, answered without it: the caller |
| + // cannot fix this console's configuration and the sentence they get |
| + // is the one that tells the operator where to look. |
| + log.Printf("console: api %s seal key: %v", door, err) |
| + jsonError(w, http.StatusServiceUnavailable, badKey) |
| + case errors.As(err, &unknown): |
| + http.NotFound(w, nil) |
| + default: |
| + log.Printf("console: api %s seal key %s/%s: %v", door, acct.Sqid, app, err) |
| + jsonError(w, http.StatusBadGateway, "could not read the config — try again") |
| } |
| - return pub, true |
| + return false |
| } |
| // storeBucketName is the bucket a record names, for an audit line: what was |
| @@ -789,7 +818,11 @@ func (s *Server) handleAPIStoreGrant(w http.ResponseWriter, r *http.Request) { |
| if !s.storeWalkGates(w, p) { |
| return |
| } |
| - pub, ok := s.storeSealKey(w) |
| + // The account lock from the key choice through the delivery (fleet |
| + // secrets key spec §5.2.1): a key replacement or a move cannot land |
| + // between them. Taken before the store walk lock and any app lock. |
| + defer s.lockAccount(acct.Sqid)() |
| + sealer, ok := s.storeSealKey(w, r.Context(), acct, app) |
| if !ok { |
| return |
| } |
| @@ -816,7 +849,7 @@ func (s *Server) handleAPIStoreGrant(w http.ResponseWriter, r *http.Request) { |
| defer s.storeWalks.lock(acct.Sqid, app, env)() |
| rec, err := claimAppCall(s, ctx, acct, app, "store-grant", func(ctx context.Context) (*objstore.Record, error) { |
| return objstore.GrantIn(ctx, s.cfg.Releases, s.cfg.StoreProvisioner, s.cfg.StoreDeployment, |
| - pub, acct.Sqid, app, env, addr, objstore.GrantSourceOperator, bucket, time.Now()) |
| + sealer, acct.Sqid, app, env, addr, objstore.GrantSourceOperator, bucket, time.Now()) |
| }) |
| switch { |
| case errors.Is(err, objstore.ErrNotDeclared): |
| @@ -875,7 +908,11 @@ func (s *Server) handleAPIStoreRotate(w http.ResponseWriter, r *http.Request) { |
| if !s.storeWalkGates(w, p) { |
| return |
| } |
| - pub, ok := s.storeSealKey(w) |
| + // The account lock from the key choice through the delivery (fleet |
| + // secrets key spec §5.2.1): a key replacement or a move cannot land |
| + // between them. Taken before the store walk lock and any app lock. |
| + defer s.lockAccount(acct.Sqid)() |
| + sealer, ok := s.storeSealKey(w, r.Context(), acct, app) |
| if !ok { |
| return |
| } |
| @@ -890,7 +927,7 @@ func (s *Server) handleAPIStoreRotate(w http.ResponseWriter, r *http.Request) { |
| defer cancel() |
| defer s.storeWalks.lock(acct.Sqid, app, env)() |
| rec, err := claimAppCall(s, ctx, acct, app, "store-rotate", func(ctx context.Context) (*objstore.Record, error) { |
| - return objstore.RotateIn(ctx, s.cfg.Releases, s.cfg.StoreProvisioner, pub, acct.Sqid, app, env, time.Now()) |
| + return objstore.RotateIn(ctx, s.cfg.Releases, s.cfg.StoreProvisioner, sealer, acct.Sqid, app, env, time.Now()) |
| }) |
| switch { |
| case errors.Is(err, objstore.ErrNotProvisioned), errors.Is(err, objstore.ErrNotDeclared): |
diff --git a/internal/console/apistore_provision.go b/internal/console/apistore_provision.go| index ffee02fbc..83238d178 100644 |
| --- a/internal/console/apistore_provision.go |
| +++ b/internal/console/apistore_provision.go |
| @@ -33,7 +33,11 @@ func (s *Server) handleAPIStoreProvision(w http.ResponseWriter, r *http.Request) |
| if !s.storeWalkGates(w, p) { |
| return |
| } |
| - pub, ok := s.storeSealKey(w) |
| + // The account lock from the key choice through the delivery (fleet |
| + // secrets key spec §5.2.1): a key replacement or a move cannot land |
| + // between them. Taken before the store walk lock and any app lock. |
| + defer s.lockAccount(acct.Sqid)() |
| + sealer, ok := s.storeSealKey(w, preCtx, acct, app) |
| if !ok { |
| return |
| } |
| @@ -60,7 +64,7 @@ func (s *Server) handleAPIStoreProvision(w http.ResponseWriter, r *http.Request) |
| } |
| rec, err := claimAppCall(s, ctx, acct, app, "store-provision", func(ctx context.Context) (*objstore.Record, error) { |
| return objstore.GrantIn(ctx, s.cfg.Releases, s.cfg.StoreProvisioner, s.cfg.StoreDeployment, |
| - pub, acct.Sqid, app, env, e.Decision.By, objstore.GrantSourceAccountApproval, "", time.Now()) |
| + sealer, acct.Sqid, app, env, e.Decision.By, objstore.GrantSourceAccountApproval, "", time.Now()) |
| }) |
| switch { |
| case errors.Is(err, objstore.ErrNotDeclared): |
diff --git a/internal/console/apistore_provision_test.go b/internal/console/apistore_provision_test.go| index 05ab36886..ecda8084a 100644 |
| --- a/internal/console/apistore_provision_test.go |
| +++ b/internal/console/apistore_provision_test.go |
| @@ -272,17 +272,22 @@ func TestAPIStoreAdminServiceDeclarationKeepsServiceAttribution(t *testing.T) { |
| } |
| } |
| +// waitStoreProvisionQueued waits until the second provision is queued |
| +// behind the first. It queues on the account lock, which the door takes |
| +// before the store walk lock from its seal key's choice through the grant |
| +// (fleet secrets key spec §5.2.1), so the first holds both and the second |
| +// waits on the account lock with the walk lock untaken. |
| func waitStoreProvisionQueued(t *testing.T, fx *consoleFixture) { |
| t.Helper() |
| deadline := time.Now().Add(3 * time.Second) |
| for { |
| - fx.srv.storeWalks.mu.Lock() |
| - e := fx.srv.storeWalks.m[storeWalkKey(fx.sqid, "titogo", "")] |
| + fx.srv.acctLocks.mu.Lock() |
| + e := fx.srv.acctLocks.m[fx.sqid] |
| refs := 0 |
| if e != nil { |
| refs = e.refs |
| } |
| - fx.srv.storeWalks.mu.Unlock() |
| + fx.srv.acctLocks.mu.Unlock() |
| if refs == 2 { |
| return |
| } |
diff --git a/internal/console/apisystem.go b/internal/console/apisystem.go| index 77c1ba9dd..8e2309b1a 100644 |
| --- a/internal/console/apisystem.go |
| +++ b/internal/console/apisystem.go |
| @@ -21,7 +21,6 @@ package console |
| import ( |
| "context" |
| - "crypto/ecdh" |
| "errors" |
| "log" |
| "net/http" |
| @@ -70,17 +69,16 @@ func (s *Server) handleAPISystemWebhookRotate(w http.ResponseWriter, r *http.Req |
| jsonError(w, http.StatusTooManyRequests, "too many requests — wait a minute and try again") |
| return |
| } |
| - pub, ok := s.storeSealKey(w) |
| - if !ok { |
| - return |
| - } |
| + // No seal key here: each app's comes from sealKeyFor inside the pass, |
| + // under that app's account lock, and an app whose key cannot be chosen |
| + // is skipped and stays in remaining. |
| if s.cfg.CallbackSigner == nil { |
| scanUnavailable(w, http.StatusServiceUnavailable, "callbacks_not_configured", "scan callbacks are not configured for this deployment (CARLOS_SCAN_WEBHOOK_KEY)") |
| return |
| } |
| ctx, cancel := context.WithTimeout(r.Context(), scanSweepTimeout) |
| defer cancel() |
| - remaining, changed, err := s.rotateWebhookBudget(ctx, pub) |
| + remaining, changed, err := s.rotateWebhookBudget(ctx) |
| if err != nil { |
| log.Printf("console: rotate scan webhook key: %v", err) |
| jsonError(w, http.StatusBadGateway, "callback-key rotation stopped — re-run to resume") |
| @@ -89,7 +87,13 @@ func (s *Server) handleAPISystemWebhookRotate(w http.ResponseWriter, r *http.Req |
| writeJSON(w, http.StatusOK, map[string]int{"rotated": changed, "remaining": remaining}) |
| } |
| -func (s *Server) rotateWebhookBudget(ctx context.Context, pub *ecdh.PublicKey) (remaining, changed int, err error) { |
| +// rotateWebhookBudget delivers the current master's derived secret to every |
| +// scanning-enabled app that lacks it, each sealed to that app's own key |
| +// (sealKeyFor via convergeCallbackKey), each under its account's lock (fleet |
| +// secrets key spec §5.2.1; the caller holds none). An app whose key cannot |
| +// be chosen, such as one on a keyless fleet, is logged and skipped: it is |
| +// left in remaining and the next run tries it again. |
| +func (s *Server) rotateWebhookBudget(ctx context.Context) (remaining, changed int, err error) { |
| accounts, err := s.cfg.Releases.ListDirs(ctx, "apps/") |
| if err != nil { |
| return 0, 0, err |
| @@ -133,15 +137,22 @@ func (s *Server) rotateWebhookBudget(ctx context.Context, pub *ecdh.PublicKey) ( |
| } |
| account := &Account{Sqid: target.acct} |
| var delivered bool |
| + unlock := s.lockAccount(target.acct) |
| err := s.appMutation(ctx, account, target.app, "scan-webhook-rotate", func(ctx context.Context) error { |
| var err error |
| - delivered, _, err = s.convergeCallbackKey(ctx, pub, account, target.app) |
| + delivered, _, err = s.convergeCallbackKey(ctx, account, target.app) |
| if errors.Is(err, objstore.ErrQueueNotPermitted) { |
| delivered = false |
| return nil |
| } |
| return err |
| }) |
| + unlock() |
| + var keyErr errCallbackSealKey |
| + if errors.As(err, &keyErr) { |
| + log.Printf("console: rotate scan webhook key %s/%s: skipped, tried again next run: %v", target.acct, target.app, keyErr.err) |
| + continue |
| + } |
| if err != nil { |
| if !delivered && errors.Is(err, hostops.ErrPending) { |
| continue |
diff --git a/internal/console/fleetsecrets_mint_test.go b/internal/console/fleetsecrets_mint_test.go| new file mode 100644 |
| index 000000000..37131fd1a |
| --- /dev/null |
| +++ b/internal/console/fleetsecrets_mint_test.go |
| @@ -0,0 +1,383 @@ |
| +package console |
| + |
| +// Console-minted credentials for an app on a fleet (fleet secrets key spec |
| +// §5.2, §5.2.1; plan Task 6a). What these pin, in the order they would hurt |
| +// if lost: a store or email credential minted for an app on a keyless fleet |
| +// is refused before the first backend call (nothing minted, nothing billed, |
| +// nothing sealed to a key the fleet's boxes lack); one minted for an app on a |
| +// keyed fleet is sealed to that fleet's key and says so (SealedTo), never to |
| +// the deployment key; the webhook rotation picks each app's own key; and the |
| +// account lock these paths now take never deadlocks against a door that |
| +// already holds it (planLock, the config PUT). |
| + |
| +import ( |
| + "context" |
| + "crypto/ecdh" |
| + "fmt" |
| + "net/http" |
| + "os" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/appconfig" |
| + "github.com/carlosframework/platform/internal/dnsrec" |
| + "github.com/carlosframework/platform/internal/mail" |
| + "github.com/carlosframework/platform/internal/objstore" |
| + "github.com/carlosframework/platform/internal/provision" |
| +) |
| + |
| +// fcmWorld is bab with the fleet home, shop placed on it, and a deployment |
| +// key whose private half the test holds (depPriv), so a test can prove a |
| +// value does NOT open with it. |
| +type fcmWorld struct { |
| + fx *consoleFixture |
| + token string // paul, the owner, on every operator list |
| + fleet skFleetKey |
| + depPriv string |
| +} |
| + |
| +// fcmFleetShop builds the world; withKey registers home's key through the |
| +// key door before shop is placed. |
| +func fcmFleetShop(t *testing.T, code string, withKey bool) *fcmWorld { |
| + t.Helper() |
| + fx, token, _ := fskFixture(t, code) |
| + dep := skNewKey(t) |
| + fx.srv.cfg.SecretsPub = dep.pub |
| + k := skNewKey(t) |
| + if withKey { |
| + skRegister(t, fx, token, "home", k) |
| + } |
| + fskPlaceShop(t, fx, token, "home") |
| + appconfig.SetBoundSealing(false) |
| + t.Cleanup(func() { appconfig.SetBoundSealing(false) }) |
| + return &fcmWorld{fx: fx, token: token, fleet: k, depPriv: dep.priv} |
| +} |
| + |
| +// armStore wires an in-memory store backend with paul as its operator and |
| +// declares each app's store. |
| +func (w *fcmWorld) armStore(t *testing.T, apps ...string) *objstore.MemProvisioner { |
| + t.Helper() |
| + fake := objstore.NewMemProvisioner("eu-west-1") |
| + w.fx.srv.cfg.StoreProvisioner = fake |
| + w.fx.srv.cfg.StoreDeployment = objstore.Deployment{Backend: "mem", Region: "eu-west-1", BucketPrefix: "carlos-"} |
| + w.fx.srv.cfg.StoreOperators = []string{"paul@keymail.dev"} |
| + for _, app := range apps { |
| + if status, out := postJSON(t, storeURL(w.fx, app), map[string]any{}, w.token); status != http.StatusOK { |
| + t.Fatalf("declare %s's store = %d %v", app, status, out) |
| + } |
| + } |
| + return fake |
| +} |
| + |
| +// open opens v for bab/app with a base64 private key. |
| +func (w *fcmWorld) open(t *testing.T, priv, app string, v appconfig.Var) (string, error) { |
| + t.Helper() |
| + pk, err := appconfig.ParsePrivateKey(priv, "test") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + plain, err := appconfig.Open(pk, appconfig.Binding{Account: w.fx.sqid, App: app}, v.Envelope) |
| + return string(plain), err |
| +} |
| + |
| +// sealedToFleet asserts v is sealed to home's key: it says so, it is v2, |
| +// home's private key opens it and the deployment's does not. Returns the |
| +// plaintext. |
| +func (w *fcmWorld) sealedToFleet(t *testing.T, name string, v appconfig.Var) string { |
| + t.Helper() |
| + if v.Kind != "secret" || v.Envelope == "" { |
| + t.Fatalf("%s = %+v, want a sealed secret", name, v) |
| + } |
| + if v.SealedTo != w.fleet.fp { |
| + t.Fatalf("%s sealed_to = %q, want home's %q", name, v.SealedTo, w.fleet.fp) |
| + } |
| + if !appconfig.EnvelopeBound(v.Envelope) { |
| + t.Fatalf("%s is a v1 envelope; fleet-key envelopes are always v2", name) |
| + } |
| + plain, err := w.open(t, w.fleet.priv, "shop", v) |
| + if err != nil { |
| + t.Fatalf("home's private key does not open %s: %v", name, err) |
| + } |
| + if _, err := w.open(t, w.depPriv, "shop", v); err == nil { |
| + t.Fatalf("the deployment's private key opens %s, which shop's boxes must hold alone", name) |
| + } |
| + return plain |
| +} |
| + |
| +func TestStoreGrantOnKeylessFleetRefusesBeforeBackend(t *testing.T) { |
| + w := fcmFleetShop(t, "code-fcm-store-keyless", false) |
| + fake := w.armStore(t, "shop") |
| + want := fmt.Sprintf("home has no secrets key, so the console cannot deliver a store credential to %s and will not mint one. run carlos fleets secrets-key home <pubkey>", "shop") |
| + |
| + for _, verb := range []string{"/grant", "/rotate"} { |
| + status, out := postJSON(t, storeURL(w.fx, "shop")+verb, map[string]any{}, w.token) |
| + if status != http.StatusConflict || out["error"] != want { |
| + t.Fatalf("store %s on a keyless fleet = %d %v, want 409 %q", verb, status, out, want) |
| + } |
| + } |
| + untouched(t, fake, "a grant on a keyless fleet") |
| + if rec := storedRecord(t, w.fx, "shop"); rec == nil || rec.Grant != nil || rec.Provisioned != nil { |
| + t.Fatalf("a refused grant wrote the record: %+v", rec) |
| + } |
| + if v, ok := appVars(t, w.fx, "shop")[objstore.DefaultEnvPrefix+"_SECRET_KEY"]; ok { |
| + t.Fatalf("a refused grant delivered a secret: %+v", v) |
| + } |
| +} |
| + |
| +func TestStoreGrantOnFleetSealsToTheFleetKey(t *testing.T) { |
| + w := fcmFleetShop(t, "code-fcm-store-fleet", true) |
| + fake := w.armStore(t, "shop") |
| + if status, out := postJSON(t, storeURL(w.fx, "shop")+"/grant", map[string]any{}, w.token); status != http.StatusOK { |
| + t.Fatalf("grant = %d %v", status, out) |
| + } |
| + rec := storedRecord(t, w.fx, "shop") |
| + if rec == nil || rec.Provisioned == nil { |
| + t.Fatalf("store record = %+v, want provisioned", rec) |
| + } |
| + vars := appVars(t, w.fx, "shop") |
| + _, _, _, accessName, secretName := objstore.EnvNames(rec.Declared.EnvPrefix) |
| + secret := w.sealedToFleet(t, secretName, vars[secretName]) |
| + keyID := w.sealedToFleet(t, accessName, vars[accessName]) |
| + if keyID != rec.Provisioned.KeyID { |
| + t.Fatalf("delivered access key = %q, want the minted %q", keyID, rec.Provisioned.KeyID) |
| + } |
| + if u, ok := fake.Users[rec.Provisioned.IAMUser]; !ok || u.Keys[keyID] != secret { |
| + t.Fatalf("delivered secret is not the backend's minted secret for %s", keyID) |
| + } |
| + |
| + // A rotation reseals with the same key. |
| + if status, out := postJSON(t, storeURL(w.fx, "shop")+"/rotate", map[string]any{}, w.token); status != http.StatusOK { |
| + t.Fatalf("rotate = %d %v", status, out) |
| + } |
| + w.sealedToFleet(t, secretName+" after rotate", appVars(t, w.fx, "shop")[secretName]) |
| +} |
| + |
| +// fcmArmMail wires an in-memory mail backend and walks shop to a verified |
| +// platform domain, everything short of enable. |
| +func (w *fcmWorld) fcmArmMail(t *testing.T) *mail.MemProvisioner { |
| + t.Helper() |
| + fake := mail.NewMemProvisioner("1") |
| + w.fx.srv.cfg.MailProvisioner = fake |
| + w.fx.srv.cfg.DNSWriter = dnsrec.NewMemWriter() |
| + w.fx.srv.cfg.MailDeployment = mail.Deployment{Region: "eu-west-1", PlatformSuffix: "oncarlos.com"} |
| + w.fx.srv.cfg.MailOperators = []string{"paul@keymail.dev"} |
| + domain := "shop." + w.fx.sqid + ".oncarlos.com" |
| + declareEmail(t, w.fx, w.token, "shop", "hello@"+domain) |
| + fake.StatusOnEnsure = mail.Status{DKIM: "SUCCESS", MailFrom: "SUCCESS", Sending: "SUCCESS"} |
| + ensureEmailDomain(t, w.fx, w.token, "shop", domain) |
| + verifyEmailDomain(t, w.fx, w.token, "shop", domain) |
| + return fake |
| +} |
| + |
| +func TestMailEnableOnFleetSealsToTheFleetKey(t *testing.T) { |
| + w := fcmFleetShop(t, "code-fcm-mail-fleet", true) |
| + w.fcmArmMail(t) |
| + enableEmail(t, w.fx, w.token, "shop") |
| + _, _, userName, passName, _ := mail.EnvNames(mail.DefaultEnvPrefix) |
| + vars := appVars(t, w.fx, "shop") |
| + if vars[userName].Value == "" { |
| + t.Fatalf("no %s delivered: %v", userName, vars) |
| + } |
| + w.sealedToFleet(t, passName, vars[passName]) |
| + |
| + if status, out := postJSON(t, emailURL(w.fx, "shop")+"/rotate", map[string]any{}, w.token); status != http.StatusOK { |
| + t.Fatalf("rotate = %d %v", status, out) |
| + } |
| + w.sealedToFleet(t, passName+" after rotate", appVars(t, w.fx, "shop")[passName]) |
| +} |
| + |
| +func TestMailEnableOnKeylessFleetRefusesBeforeBackend(t *testing.T) { |
| + w := fcmFleetShop(t, "code-fcm-mail-keyless", false) |
| + fake := w.fcmArmMail(t) |
| + want := fmt.Sprintf("home has no secrets key, so the console cannot deliver an email credential to %s and will not enable sending. run carlos fleets secrets-key home <pubkey>", "shop") |
| + for _, verb := range []string{"/enable", "/rotate"} { |
| + status, out := postJSON(t, emailURL(w.fx, "shop")+verb, map[string]any{}, w.token) |
| + if status != http.StatusConflict || out["error"] != want { |
| + t.Fatalf("email %s on a keyless fleet = %d %v, want 409 %q", verb, status, out, want) |
| + } |
| + } |
| + if len(fake.Users) != 0 { |
| + t.Fatalf("a refused enable touched the backend: users %v", fake.Users) |
| + } |
| + rec, _, err := mail.Get(context.Background(), w.fx.rel, w.fx.sqid, "shop") |
| + if err != nil || rec == nil || rec.Provisioned != nil || rec.Grant != nil { |
| + t.Fatalf("a refused enable wrote the record: %+v %v", rec, err) |
| + } |
| +} |
| + |
| +// TestWebhookRotateUsesEachAppsKey: one rotation pass over a platform app |
| +// (cart) and a fleet app (shop). Its targets carry the account's sqid only; |
| +// each app's callback secret must be sealed to its own boxes' key. |
| +func TestWebhookRotateUsesEachAppsKey(t *testing.T) { |
| + w := fcmFleetShop(t, "code-fcm-webhook", true) |
| + if _, err := w.fx.st.CreateAppIn(OpsAccountID, "cart", "paul@keymail.dev", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + w.armStore(t, "shop", "cart") |
| + w.fx.srv.cfg.CallbackSigner = callbackTestSigner(t, testWebhookMaster, "") |
| + w.fx.srv.cfg.StoreScanner = objstore.NewMemScanner() |
| + enableDeploymentScanning(t, w.fx) |
| + for _, app := range []string{"shop", "cart"} { |
| + if status, out := postJSON(t, storeURL(w.fx, app)+"/grant", map[string]any{}, w.token); status != http.StatusOK { |
| + t.Fatalf("grant %s = %d %v", app, status, out) |
| + } |
| + grantScanning(t, w.fx, w.token, app) |
| + } |
| + |
| + w.fx.srv.cfg.CallbackSigner = callbackTestSigner(t, "replacement-master", testWebhookMaster) |
| + status, out := postJSON(t, w.fx.ts.URL+"/api/cli/system/antivirus/rotate-webhook-key", map[string]any{}, w.token) |
| + if status != http.StatusOK || out["rotated"] != float64(2) || out["remaining"] != float64(0) { |
| + t.Fatalf("rotate = %d %v, want both apps rotated", status, out) |
| + } |
| + name := objstore.DefaultEnvPrefix + "_SCAN_CALLBACK_SECRET" |
| + depFP, err := appconfig.PublicFingerprint(w.fx.srv.cfg.SecretsPub) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, app := range []string{"shop", "cart"} { |
| + rec := storedRecord(t, w.fx, app) |
| + want := string(w.fx.srv.cfg.CallbackSigner.DerivedKey(w.fx.sqid, app, rec.Scanning.WebhookGen)) |
| + v := appVars(t, w.fx, app)[name] |
| + var got string |
| + if app == "shop" { |
| + got = w.sealedToFleet(t, "shop's "+name, v) |
| + } else { |
| + dep, err := w.open(t, w.depPriv, "cart", v) |
| + if err != nil { |
| + t.Fatalf("the deployment key does not open cart's %s: %v", name, err) |
| + } |
| + if _, err := w.open(t, w.fleet.priv, "cart", v); err == nil { |
| + t.Fatalf("home's key opens cart's %s", name) |
| + } |
| + if v.SealedTo != depFP { |
| + t.Fatalf("cart's sealed_to = %q, want the deployment's %q", v.SealedTo, depFP) |
| + } |
| + got = dep |
| + } |
| + if got != want { |
| + t.Fatalf("%s's callback secret = %q, want the replacement master's %q", app, got, want) |
| + } |
| + } |
| +} |
| + |
| +// fcmWithin runs do and fails the test if it has not returned within five |
| +// seconds: a door that takes the account lock twice never returns. It |
| +// prints and exits the test binary rather than calling t.Fatal or |
| +// panicking: either runs the fixture's cleanup, which closes a server |
| +// whose handler is stuck forever, and the run would hang until the package |
| +// timeout with the message never printed. |
| +func fcmWithin(t *testing.T, what string, do func() (int, string)) (int, string) { |
| + t.Helper() |
| + type answer struct { |
| + status int |
| + body string |
| + } |
| + done := make(chan answer, 1) |
| + go func() { |
| + s, b := do() |
| + done <- answer{s, b} |
| + }() |
| + select { |
| + case a := <-done: |
| + return a.status, a.body |
| + case <-time.After(5 * time.Second): |
| + fmt.Fprintf(os.Stderr, "--- FAIL: %s: %s did not answer within 5s: the account lock is taken twice\n", t.Name(), what) |
| + os.Exit(1) |
| + return 0, "" |
| + } |
| +} |
| + |
| +// fcmPlans turns the plan catalog on or off: on, the create doors hold the |
| +// account lock (planLock) through what they seal. |
| +func fcmPlans(t *testing.T, fx *consoleFixture, on bool) { |
| + t.Helper() |
| + if on { |
| + fx.srv.cfg.PlanCatalog = examplePlanCatalog(t) |
| + } else { |
| + fx.srv.cfg.PlanCatalog = nil |
| + } |
| +} |
| + |
| +func TestAppCreateAdoptingFleetAppDoesNotDeadlock(t *testing.T) { |
| + for _, plansOn := range []bool{false, true} { |
| + t.Run(fmt.Sprintf("plans=%v", plansOn), func(t *testing.T) { |
| + fx, token, _ := fskFixture(t, fmt.Sprintf("code-fcm-adopt-%v", plansOn)) |
| + skRegister(t, fx, token, "home", skNewKey(t)) |
| + fcmPlans(t, fx, plansOn) |
| + // Objects already under bab/shop's prefix, with a sealed value: |
| + // the create adopts them. |
| + fskSetSecrets(t, fx, map[string]appconfig.Var{"API_KEY": fskSeal(t, fx, "")}) |
| + status, body := fcmWithin(t, "app create", func() (int, string) { |
| + s, _, b := rawReq(t, http.MethodPost, fx.ts.URL+"/api/cli/apps/"+fx.sqid+"/new", token, `{"name":"shop","place":"fleet/home"}`) |
| + return s, b |
| + }) |
| + if status != http.StatusOK && status != http.StatusCreated { |
| + t.Fatalf("adopting create = %d %s", status, body) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestInstanceCreatePrivateStoreOnFleetDoesNotDeadlock(t *testing.T) { |
| + for _, plansOn := range []bool{false, true} { |
| + t.Run(fmt.Sprintf("plans=%v", plansOn), func(t *testing.T) { |
| + w := fcmFleetShop(t, fmt.Sprintf("code-fcm-instance-%v", plansOn), true) |
| + w.armStore(t) |
| + approveStoreAccount(t, w.fx, "operator@keymail.dev") |
| + enableInstances(t, w.fx, "shop", provision.Manifest{Schema: 1, App: "shop", Domain: "shop.example.com", |
| + Pool: "shop", Channel: "stable", Regions: []string{"ie"}, Seed: []string{"seed"}, PrivateStorage: true}) |
| + fcmPlans(t, w.fx, plansOn) |
| + status, body := fcmWithin(t, "instance create", func() (int, string) { |
| + s, _, b := rawReq(t, http.MethodPost, instancesURL(w.fx, w.fx.sqid, "shop"), w.token, `{"host":"a.shop.example.com","region":"ie"}`) |
| + return s, b |
| + }) |
| + if status != http.StatusCreated { |
| + t.Fatalf("instance create = %d %s", status, body) |
| + } |
| + _, _, _, _, secretName := objstore.EnvNames(objstore.DefaultEnvPrefix) |
| + m, err := appconfig.LoadEnvironment(context.Background(), w.fx.rel, w.fx.sqid, "shop", "a") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + w.sealedToFleet(t, "the instance store's "+secretName, m.Vars[secretName]) |
| + }) |
| + } |
| +} |
| + |
| +func TestTeamEnvironmentCreateOnFleetDoesNotDeadlock(t *testing.T) { |
| + for _, plansOn := range []bool{false, true} { |
| + for _, withSecret := range []bool{false, true} { |
| + t.Run(fmt.Sprintf("plans=%v,secret=%v", plansOn, withSecret), func(t *testing.T) { |
| + w := fcmFleetShop(t, fmt.Sprintf("code-fcm-team-%v-%v", plansOn, withSecret), true) |
| + w.fcmArmMail(t) |
| + enableEmail(t, w.fx, w.token, "shop") |
| + fcmPlans(t, w.fx, plansOn) |
| + team := teamToken(t, w.fx.st, OpsAccountID, "alta-shop", "shop", "alta") |
| + set := map[string]any{"TEAM_ONLY": map[string]string{"kind": "env", "value": "1"}} |
| + if withSecret { |
| + set["TEAM_SECRET"] = map[string]string{"kind": "secret", "envelope": skSeal(t, w.fx, w.fleet.pub, true), "sealed_to": w.fleet.fp} |
| + } |
| + status, body := fcmWithin(t, "team environment create", func() (int, string) { |
| + s, _, b := rawReq(t, http.MethodPut, configURL(w.fx, "shop"), team, string(mustJSON(t, map[string]any{"environment": "crew", "set": set}))) |
| + return s, b |
| + }) |
| + if status != http.StatusOK { |
| + t.Fatalf("team PUT into a new environment = %d %s", status, body) |
| + } |
| + m, err := appconfig.LoadEnvironment(context.Background(), w.fx.rel, w.fx.sqid, "shop", "crew") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + _, _, _, passName, _ := mail.EnvNames(mail.DefaultEnvPrefix) |
| + w.sealedToFleet(t, "the environment's "+passName, m.Vars[passName]) |
| + }) |
| + } |
| + } |
| +} |
| + |
| +// consoleTestSealer is the sealer a test hands a walk or a delivery helper |
| +// directly: pub for acct/app, bound as the deployment switch says, which |
| +// is what those took before they took a sealer. |
| +func consoleTestSealer(pub *ecdh.PublicKey, acct, app string) appconfig.Sealer { |
| + return appconfig.NewSealer(pub, appconfig.Binding{Account: acct, App: app}, appconfig.BoundSealing()) |
| +} |
diff --git a/internal/console/instanceprivatestore.go b/internal/console/instanceprivatestore.go| index a2b1029aa..f5fb17da2 100644 |
| --- a/internal/console/instanceprivatestore.go |
| +++ b/internal/console/instanceprivatestore.go |
| @@ -20,7 +20,6 @@ package console |
| import ( |
| "context" |
| - "crypto/ecdh" |
| "errors" |
| "fmt" |
| "log" |
| @@ -207,7 +206,16 @@ var errSeedStoreTaken = errors.New("console: the environment's store is not this |
| // rolled back under the lock: deleted if this call created the record, |
| // else restored to its previous bytes. |
| func (s *Server) instanceStoreProvisionFor(ctx context.Context, w http.ResponseWriter, acct *Account, app, env, actor, seedID string) (*objstore.Record, bool, error) { |
| - pub, ok := s.instanceStorePreflight(ctx, w, acct, app) |
| + // The seal key is chosen here and used by the grant below without the |
| + // account lock being taken in between by this function: the lock is not |
| + // reentrant, and every caller is an entry point that decides it. The |
| + // plain, seeded and imported creates hold it through planLock only when |
| + // plans are on; with plans off this seal runs unlocked, an accepted I2 |
| + // gap (fleet secrets key spec §2.1): a key replacement landing between |
| + // the choice and the grant leaves a value the boxes refuse and |
| + // `instances list` shows, never one sealed to a key outside the |
| + // account. The detached seed copy (runFrom) holds it itself. |
| + sealer, ok := s.instanceStorePreflight(ctx, w, acct, app) |
| if !ok { |
| return nil, false, nil |
| } |
| @@ -312,7 +320,7 @@ func (s *Server) instanceStoreProvisionFor(ctx context.Context, w http.ResponseW |
| } |
| } |
| out, err := objstore.GrantInFor(walkCtx, effectStore, effectProvisioner, s.cfg.StoreDeployment, |
| - pub, acct.Sqid, app, env, e.Decision.By, objstore.GrantSourceAccountApproval, "", seedID, time.Now()) |
| + sealer, acct.Sqid, app, env, e.Decision.By, objstore.GrantSourceAccountApproval, "", seedID, time.Now()) |
| if err != nil && seedID != "" && redeclare { |
| // A seed's declaration must not outlive a grant that wrote nothing: |
| // another path could grant that record later and keep the mark, and |
| @@ -368,9 +376,9 @@ func (s *Server) instanceStoreProvisionFor(ctx context.Context, w http.ResponseW |
| // sealing key. It answers w itself on a refusal. instanceStoreProvisionFor |
| // runs it first; a seed door runs it before reserving its record, so these |
| // refusals never leave an aborted record behind. |
| -func (s *Server) instanceStorePreflight(ctx context.Context, w http.ResponseWriter, acct *Account, app string) (*ecdh.PublicKey, bool) { |
| +func (s *Server) instanceStorePreflight(ctx context.Context, w http.ResponseWriter, acct *Account, app string) (appconfig.Sealer, bool) { |
| if s.refuseTemporary(w, acct, app, "give it object storage") { |
| - return nil, false |
| + return appconfig.Sealer{}, false |
| } |
| if s.cfg.StoreProvisioner == nil { |
| // The manifest carries a policy this deployment cannot honour. The |
| @@ -379,14 +387,14 @@ func (s *Server) instanceStorePreflight(ctx context.Context, w http.ResponseWrit |
| // fact, named as one. |
| jsonError(w, http.StatusServiceUnavailable, |
| "object storage is not configured for this deployment (CARLOS_STORE_BACKEND), and "+app+" gives every instance its own storage — no instance can be created until one is wired or the policy is turned off (carlos instances enable --private-storage=false)") |
| - return nil, false |
| + return appconfig.Sealer{}, false |
| } |
| preCtx, preCancel := context.WithTimeout(ctx, storeTimeout) |
| defer preCancel() |
| if _, ok := s.storeProvisionApproval(preCtx, w, acct); !ok { |
| - return nil, false |
| + return appconfig.Sealer{}, false |
| } |
| - return s.storeSealKey(w) |
| + return s.storeSealKey(w, preCtx, acct, app) |
| } |
| // seedOwnsStore reports whether a seeded create may use rec (spec §4 |
diff --git a/internal/console/planstorage.go b/internal/console/planstorage.go| index 3fb8dcf49..9c54015a0 100644 |
| --- a/internal/console/planstorage.go |
| +++ b/internal/console/planstorage.go |
| @@ -7,7 +7,6 @@ import ( |
| "log" |
| "time" |
| - "github.com/carlosframework/platform/internal/appconfig" |
| "github.com/carlosframework/platform/internal/objstore" |
| ) |
| @@ -82,10 +81,13 @@ func (s *Server) convergeStoreDeny(ctx context.Context, acct *Account, app, env |
| if have == want && applied == want { |
| return nil |
| } |
| - pub, err := appconfig.ParsePublicKey(s.cfg.SecretsPub, "CARLOS_SECRETS_PUBKEY") |
| + // The app's own key (sealKeyFor). An app whose key cannot be chosen, |
| + // such as one on a keyless fleet, is left as it is and tried again on |
| + // the next pass. Task 6b settles this walk's skip and its lock. |
| + sealer, err := s.sealKeyFor(ctx, acct.Sqid, app) |
| if err != nil { |
| - log.Printf("console: plan storage %s: no secrets key, store policies left as they are: %v", acct.Sqid, err) |
| - jobFailed(ctx, fmt.Errorf("plan storage %s: no secrets key, store policies left as they are: %w", acct.Sqid, err)) |
| + log.Printf("console: plan storage %s/%s: no secrets key, store policy left as it is: %v", acct.Sqid, app, err) |
| + jobFailed(ctx, fmt.Errorf("plan storage %s/%s: no secrets key, store policy left as it is: %w", acct.Sqid, app, err)) |
| return nil |
| } |
| action, detail := "store.writes_allowed", fmt.Sprintf("plan storage: %d of %d bytes; new uploads allowed again", st.Used, st.Limit) |
| @@ -107,7 +109,7 @@ func (s *Server) convergeStoreDeny(ctx context.Context, acct *Account, app, env |
| } |
| if _, err := claimAppCall(s, ctx, acct, app, "plan-storage-regrant", func(ctx context.Context) (*objstore.Record, error) { |
| return objstore.GrantIn(ctx, s.cfg.Releases, s.cfg.StoreProvisioner, s.cfg.StoreDeployment, |
| - pub, acct.Sqid, app, env, "plan", source, "", now) |
| + sealer, acct.Sqid, app, env, "plan", source, "", now) |
| }); err != nil { |
| return err |
| } |
diff --git a/internal/console/scan_review_regression_test.go b/internal/console/scan_review_regression_test.go| index bdea002c9..8ffc9c2ad 100644 |
| --- a/internal/console/scan_review_regression_test.go |
| +++ b/internal/console/scan_review_regression_test.go |
| @@ -74,12 +74,8 @@ func TestClaimScanCallbackContentionAndSettlement(t *testing.T) { |
| func TestClaimScanMasterRotationSkipsBusyApp(t *testing.T) { |
| w := newScanClaimWorld(t) |
| w.cx.srv.cfg.CallbackSigner = callbackTestSigner(t, "review-new-master", "claim-fixture-webhook-master") |
| - pub, err := appconfig.ParsePublicKey(w.cx.srv.cfg.SecretsPub, "test") |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - err = w.cx.srv.claimAppMutation(context.Background(), &Account{Sqid: "bab"}, "titogo", "busy-before-rotation", func(context.Context) error { |
| - remaining, changed, err := w.cx.srv.rotateWebhookBudget(context.Background(), pub) |
| + err := w.cx.srv.claimAppMutation(context.Background(), &Account{Sqid: "bab"}, "titogo", "busy-before-rotation", func(context.Context) error { |
| + remaining, changed, err := w.cx.srv.rotateWebhookBudget(context.Background()) |
| if err != nil || remaining != 1 || changed != 0 { |
| t.Errorf("busy rotation remaining=%d changed=%d err=%v", remaining, changed, err) |
| } |
| @@ -88,7 +84,7 @@ func TestClaimScanMasterRotationSkipsBusyApp(t *testing.T) { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - remaining, changed, err := w.cx.srv.rotateWebhookBudget(context.Background(), pub) |
| + remaining, changed, err := w.cx.srv.rotateWebhookBudget(context.Background()) |
| if err != nil || remaining != 0 || changed != 1 { |
| t.Fatalf("resumed rotation remaining=%d changed=%d err=%v", remaining, changed, err) |
| } |
| @@ -105,15 +101,11 @@ func TestScanMasterRotationLeavesTrashedConfigAlone(t *testing.T) { |
| if err := release.TrashApp(context.Background(), fx.rel, fx.sqid, "titogo", "test", time.Now()); err != nil { |
| t.Fatal(err) |
| } |
| - pub, err := appconfig.ParsePublicKey(fx.srv.cfg.SecretsPub, "test") |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background(), pub) |
| + remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background()) |
| if err != nil || remaining != 0 || changed != 0 { |
| t.Errorf("trashed rotation remaining=%d changed=%d err=%v", remaining, changed, err) |
| } |
| - _, _, err = fx.srv.convergeCallbackKey(context.Background(), pub, &Account{Sqid: fx.sqid}, "titogo") |
| + _, _, err = fx.srv.convergeCallbackKey(context.Background(), &Account{Sqid: fx.sqid}, "titogo") |
| if !errors.Is(err, objstore.ErrQueueNotPermitted) { |
| t.Errorf("direct trashed convergence err=%v", err) |
| } |
| @@ -155,11 +147,7 @@ func TestScanMasterRotationRechecksTrashUnderPermit(t *testing.T) { |
| } |
| }} |
| fx.srv.cfg.Releases = runner |
| - pub, err := appconfig.ParsePublicKey(fx.srv.cfg.SecretsPub, "test") |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background(), pub) |
| + remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background()) |
| if err != nil || remaining != 0 || changed != 0 || !runner.raced.Load() || runner.puts.Load() != 0 { |
| t.Errorf("trash race remaining=%d changed=%d raced=%v puts=%d err=%v", remaining, changed, runner.raced.Load(), runner.puts.Load(), err) |
| } |
diff --git a/internal/console/scankeysync.go b/internal/console/scankeysync.go| index 97e4b656c..1d7bd0132 100644 |
| --- a/internal/console/scankeysync.go |
| +++ b/internal/console/scankeysync.go |
| @@ -2,7 +2,6 @@ package console |
| import ( |
| "context" |
| - "crypto/ecdh" |
| "crypto/sha256" |
| "encoding/hex" |
| "encoding/json" |
| @@ -37,25 +36,42 @@ func (s *Server) callbackKeyCurrent(ctx context.Context, acct, app string, rec * |
| return scanSecretHash(manifest.Vars[rec.Declared.EnvPrefix+"_SCAN_CALLBACK_SECRET"]) == rec.Scanning.WebhookConfigHash, nil |
| } |
| -func (s *Server) deliverCallbackRevision(ctx context.Context, pub *ecdh.PublicKey, acct, app string, rec *objstore.Record, gen int) (string, error) { |
| +// deliverCallbackRevision seals app's callback secret for generation gen |
| +// with sealer, the app's own (sealKeyFor), and delivers it. |
| +func (s *Server) deliverCallbackRevision(ctx context.Context, sealer appconfig.Sealer, acct, app string, rec *objstore.Record, gen int) (string, error) { |
| if s.cfg.CallbackSigner == nil || rec.Declared == nil { |
| return "", ErrNoCallbackKey |
| } |
| - envelope, err := appconfig.Seal(pub, appconfig.Binding{Account: acct, App: app}, s.cfg.CallbackSigner.DerivedKey(acct, app, gen)) |
| + v, err := sealer.Seal(appconfig.Binding{Account: acct, App: app}, s.cfg.CallbackSigner.DerivedKey(acct, app, gen)) |
| if err != nil { |
| return "", err |
| } |
| - v := appconfig.Var{Kind: "secret", Envelope: envelope} |
| _, err = appconfig.Apply(ctx, s.cfg.Releases, acct, app, map[string]appconfig.Var{ |
| rec.Declared.EnvPrefix + "_SCAN_CALLBACK_SECRET": v, |
| }, nil) |
| return scanSecretHash(v), err |
| } |
| +// errCallbackSealKey is convergeCallbackKey's failure to choose the app's |
| +// seal key (sealKeyFor), before it wrote anything: a keyless fleet, no |
| +// deployment key, a registry read. The rotation pass skips such an app and |
| +// tries it again on its next run. |
| +type errCallbackSealKey struct{ err error } |
| + |
| +func (e errCallbackSealKey) Error() string { return "choose the seal key: " + e.err.Error() } |
| +func (e errCallbackSealKey) Unwrap() error { return e.err } |
| + |
| // The completion record names the exact sealed value. A concurrent console |
| // can overwrite config after a successful rotation, even when the master ID |
| // is unchanged; the next pass must detect and repair that incomplete state. |
| -func (s *Server) convergeCallbackKey(ctx context.Context, pub *ecdh.PublicKey, acct *Account, app string) (changed bool, result *objstore.Record, err error) { |
| +// |
| +// The secret is sealed to the app's own key (sealKeyFor, read from acct's |
| +// sqid alone, so a hand-built &Account{Sqid: ...} is enough). It is chosen |
| +// only once a delivery is due, so an app whose key is current costs no |
| +// registry read. The caller holds the account lock (spec §5.2.1). |
| +func (s *Server) convergeCallbackKey(ctx context.Context, acct *Account, app string) (changed bool, result *objstore.Record, err error) { |
| + var sealer appconfig.Sealer |
| + chosen := false |
| for attempt := 0; attempt < 4; attempt++ { |
| tomb, err := release.ReadAppTombstone(ctx, s.cfg.Releases, acct.Sqid, app) |
| if err != nil { |
| @@ -74,8 +90,14 @@ func (s *Server) convergeCallbackKey(ctx context.Context, pub *ecdh.PublicKey, a |
| if current, err := s.callbackKeyCurrent(ctx, acct.Sqid, app, rec); err != nil || current { |
| return changed, rec, err |
| } |
| + if !chosen { |
| + if sealer, err = s.sealKeyFor(ctx, acct.Sqid, app); err != nil { |
| + return changed, rec, errCallbackSealKey{err} |
| + } |
| + chosen = true |
| + } |
| gen, prefix := rec.Scanning.WebhookGen, rec.Declared.EnvPrefix |
| - hash, err := s.deliverCallbackRevision(ctx, pub, acct.Sqid, app, rec, gen) |
| + hash, err := s.deliverCallbackRevision(ctx, sealer, acct.Sqid, app, rec, gen) |
| if errors.Is(err, release.ErrCASConflict) { |
| continue |
| } |
diff --git a/internal/console/scankeysync_test.go b/internal/console/scankeysync_test.go| index 59af99cf7..8765b9171 100644 |
| --- a/internal/console/scankeysync_test.go |
| +++ b/internal/console/scankeysync_test.go |
| @@ -47,26 +47,42 @@ func TestCallbackKeyConvergesAcrossConcurrentRotationsWithoutClaims(t *testing.T |
| name = "interrupted delivery resumes despite current key ID" |
| } |
| t.Run(name, func(t *testing.T) { |
| - fx, token, private := rotationRaceFixture(t, "key-sync-race") |
| + fx, _, private := rotationRaceFixture(t, "key-sync-race") |
| if fx.srv.cfg.HostClaim { |
| t.Fatal("this regression must exercise independent writers without claims") |
| } |
| fx.srv.cfg.CallbackSigner = callbackTestSigner(t, "new-sync-master", testWebhookMaster) |
| store := &callbackConfigRaceStore{Store: fx.rel, key: appconfig.Key(fx.sqid, "titogo"), loseReply: loseReply} |
| + // The concurrent app rotation is the door's body, as a writer |
| + // that does not share this console's account lock runs it: the |
| + // door itself now waits on the lock the pass holds per app (fleet |
| + // secrets key spec §5.2.1), so in-process it can no longer land |
| + // inside the pass. |
| store.before = func() { |
| - status, body := postJSON(t, scanURL(fx, "titogo")+"/callback-key/rotate", map[string]any{}, token) |
| - if status != http.StatusOK { |
| - t.Fatalf("concurrent app rotation = %d %v", status, body) |
| + gen, err := randomWebhookGeneration() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + ctx := context.Background() |
| + if _, err := fx.srv.writeScanRecord(ctx, &Account{Sqid: fx.sqid}, "titogo", func(rec *objstore.Record) error { |
| + rec.Scanning.WebhookGen = gen |
| + rec.Scanning.WebhookKeyID = "" |
| + rec.Scanning.WebhookConfigHash = "" |
| + return nil |
| + }); err != nil { |
| + t.Fatalf("concurrent app rotation: %v", err) |
| + } |
| + if _, _, err := fx.srv.convergeCallbackKey(ctx, &Account{Sqid: fx.sqid}, "titogo"); err != nil { |
| + t.Fatalf("concurrent app rotation: %v", err) |
| } |
| } |
| fx.srv.cfg.Releases = store |
| - pub, _ := appconfig.ParsePublicKey(fx.srv.cfg.SecretsPub, "test") |
| - remaining, _, err := fx.srv.rotateWebhookBudget(context.Background(), pub) |
| + remaining, _, err := fx.srv.rotateWebhookBudget(context.Background()) |
| if loseReply { |
| if !errors.Is(err, errCallbackReplyLost) || !store.replyLost.Load() { |
| t.Fatalf("interrupted delivery = %v, want lost-response error", err) |
| } |
| - remaining, _, err = fx.srv.rotateWebhookBudget(context.Background(), pub) |
| + remaining, _, err = fx.srv.rotateWebhookBudget(context.Background()) |
| } |
| if err != nil || remaining != 0 || !store.raced.Load() { |
| t.Fatalf("rotation remaining=%d err=%v raced=%v", remaining, err, store.raced.Load()) |
| @@ -81,18 +97,17 @@ func TestCallbackKeyConvergesAcrossConcurrentRotationsWithoutClaims(t *testing.T |
| } |
| func TestCallbackKeyConvergenceHonorsRevokeDuringDelivery(t *testing.T) { |
| - fx, token, _ := rotationRaceFixture(t, "key-sync-revoke") |
| + fx, _, _ := rotationRaceFixture(t, "key-sync-revoke") |
| fx.srv.cfg.CallbackSigner = callbackTestSigner(t, "new-sync-master", testWebhookMaster) |
| store := &callbackConfigRaceStore{Store: fx.rel, key: appconfig.Key(fx.sqid, "titogo")} |
| + // The concurrent revoke is behind the door, as a writer that does not |
| + // share this console's account lock makes it: the door itself now waits |
| + // on the lock the pass holds per app (fleet secrets key spec §5.2.1). |
| store.before = func() { |
| - status, body := postJSON(t, scanURL(fx, "titogo")+"/revoke", map[string]any{}, token) |
| - if status != http.StatusOK { |
| - t.Fatalf("concurrent revoke = %d %v", status, body) |
| - } |
| + revokeBehindTheDoor(t, fx) |
| } |
| fx.srv.cfg.Releases = store |
| - pub, _ := appconfig.ParsePublicKey(fx.srv.cfg.SecretsPub, "test") |
| - remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background(), pub) |
| + remaining, changed, err := fx.srv.rotateWebhookBudget(context.Background()) |
| if err != nil || remaining != 0 || changed != 0 || !store.raced.Load() { |
| t.Fatalf("rotation after revoke remaining=%d changed=%d err=%v", remaining, changed, err) |
| } |
diff --git a/internal/console/teamcreds.go b/internal/console/teamcreds.go| index bb181541b..61f1e5280 100644 |
| --- a/internal/console/teamcreds.go |
| +++ b/internal/console/teamcreds.go |
| @@ -14,7 +14,6 @@ package console |
| import ( |
| "context" |
| - "errors" |
| "fmt" |
| "log" |
| "net/http" |
| @@ -43,6 +42,12 @@ func (s *Server) mintOwnedEnvironmentCredentials(ctx context.Context, acct *Acco |
| // mintOwnedEnvironmentMail is the mail half: nothing when the app has no |
| // provisioned mail (a later `carlos email enable` mints every owned |
| // environment's then), and the walk when it has. |
| +// |
| +// The password is sealed to the app's own key (sealKeyFor); an app on a |
| +// keyless fleet gets no credential and the error says why. It takes no |
| +// lock: its callers hold the account lock (the config PUT for a team |
| +// write, the email enable door, the environment adopt door), except the |
| +// environment fork door, which takes it in Task 7. |
| func (s *Server) mintOwnedEnvironmentMail(ctx context.Context, acct *Account, app, env string) error { |
| if s.cfg.Releases == nil || s.cfg.MailProvisioner == nil { |
| return nil |
| @@ -54,14 +59,11 @@ func (s *Server) mintOwnedEnvironmentMail(ctx context.Context, acct *Account, ap |
| if rec == nil || rec.Provisioned == nil { |
| return nil |
| } |
| - if s.cfg.SecretsPub == "" { |
| - return errors.New("no secrets key (CARLOS_SECRETS_PUBKEY), so no credential can be delivered") |
| - } |
| - pub, err := appconfig.ParsePublicKey(s.cfg.SecretsPub, "CARLOS_SECRETS_PUBKEY") |
| + sealer, err := s.sealKeyFor(ctx, acct.Sqid, app) |
| if err != nil { |
| - return err |
| + return fmt.Errorf("no key to seal the credential to, so none was delivered: %w", err) |
| } |
| - _, err = mail.EnableEnvironment(ctx, s.claimMailStore(), s.cfg.MailProvisioner, pub, s.cfg.MailDeployment, acct.Sqid, app, env, time.Now()) |
| + _, err = mail.EnableEnvironment(ctx, s.claimMailStore(), s.cfg.MailProvisioner, sealer, s.cfg.MailDeployment, acct.Sqid, app, env, time.Now()) |
| return err |
| } |
diff --git a/internal/console/teamcreds_test.go b/internal/console/teamcreds_test.go| index ef3656a3a..5b2841307 100644 |
| --- a/internal/console/teamcreds_test.go |
| +++ b/internal/console/teamcreds_test.go |
| @@ -68,7 +68,7 @@ func newPlatformWorld(t *testing.T, code string) *platformWorld { |
| if err != nil { |
| t.Fatal(err) |
| } |
| - if _, err := mail.Enable(ctx, fx.rel, p, pub, fx.srv.cfg.MailDeployment, "bab", "titogo", now); err != nil { |
| + if _, err := mail.Enable(ctx, fx.rel, p, consoleTestSealer(pub, "bab", "titogo"), fx.srv.cfg.MailDeployment, "bab", "titogo", now); err != nil { |
| t.Fatal(err) |
| } |
| if _, err := fx.srv.relayEnable(ctx, fx.account(t), "titogo", nil, "paul@keymail.dev"); err != nil { |
| @@ -194,7 +194,7 @@ func TestScanAndMailEventsDeliverNothingToAnOwnedEnvironment(t *testing.T) { |
| t.Fatal(err) |
| } |
| srec, _, _ := objstore.Get(ctx, w.fx.rel, "bab", "titogo") |
| - if _, err := w.fx.srv.deliverCallbackRevision(ctx, pub, "bab", "titogo", srec, 1); err != nil { |
| + if _, err := w.fx.srv.deliverCallbackRevision(ctx, consoleTestSealer(pub, "bab", "titogo"), "bab", "titogo", srec, 1); err != nil { |
| t.Fatal(err) |
| } |
| // Mail events: the verifying key, through the door. |
| @@ -206,7 +206,7 @@ func TestScanAndMailEventsDeliverNothingToAnOwnedEnvironment(t *testing.T) { |
| if _, err := objstore.PutIn(ctx, w.fx.rel, "bab", "titogo", "team", &objstore.Record{Declared: &objstore.Declared{EnvPrefix: "TEAM_S3", At: time.Now(), By: "m"}}, ""); err != nil { |
| t.Fatal(err) |
| } |
| - if _, err := objstore.GrantIn(ctx, w.fx.rel, objstore.NewMemProvisioner("eu-west-1"), objstore.Deployment{Backend: "aws", Region: "eu-west-1", BucketPrefix: "carlos-store-tito-"}, pub, "bab", "titogo", "team", "op", objstore.GrantSourceOperator, "", time.Now()); err != nil { |
| + if _, err := objstore.GrantIn(ctx, w.fx.rel, objstore.NewMemProvisioner("eu-west-1"), objstore.Deployment{Backend: "aws", Region: "eu-west-1", BucketPrefix: "carlos-store-tito-"}, consoleTestSealer(pub, "bab", "titogo"), "bab", "titogo", "team", "op", objstore.GrantSourceOperator, "", time.Now()); err != nil { |
| t.Fatal(err) |
| } |
| def, env := w.vars(t, ""), w.vars(t, "team") |
diff --git a/internal/mail/claim_gate_closure_test.go b/internal/mail/claim_gate_closure_test.go| index 972cb759c..3d64b8b7c 100644 |
| --- a/internal/mail/claim_gate_closure_test.go |
| +++ b/internal/mail/claim_gate_closure_test.go |
| @@ -291,7 +291,7 @@ func TestClaimMailEnableAndStandalonePreflightTransitiveMembers(t *testing.T) { |
| } |
| run := map[string]func(f *claimDomainFixture) error{ |
| "enable": func(f *claimDomainFixture) error { |
| - _, err := Enable(f.ctx, f.marked, f.prov, pub, testDeployment(), claimTestAccount, "alpha", f.now) |
| + _, err := Enable(f.ctx, f.marked, f.prov, mailTestSealer(pub, claimTestAccount, "alpha"), testDeployment(), claimTestAccount, "alpha", f.now) |
| return err |
| }, |
| "standalone": func(f *claimDomainFixture) error { |
diff --git a/internal/mail/sealer_helper_test.go b/internal/mail/sealer_helper_test.go| new file mode 100644 |
| index 000000000..5b26b2099 |
| --- /dev/null |
| +++ b/internal/mail/sealer_helper_test.go |
| @@ -0,0 +1,14 @@ |
| +package mail |
| + |
| +import ( |
| + "crypto/ecdh" |
| + |
| + "github.com/carlosframework/platform/internal/appconfig" |
| +) |
| + |
| +// mailTestSealer is the sealer the walks now take (fleet secrets key, Task |
| +// 6): pub for acct/app, bound or not as the deployment switch says, which is |
| +// what appconfig.Seal chose before the walks took a sealer. |
| +func mailTestSealer(pub *ecdh.PublicKey, acct, app string) appconfig.Sealer { |
| + return appconfig.NewSealer(pub, appconfig.Binding{Account: acct, App: app}, appconfig.BoundSealing()) |
| +} |
diff --git a/internal/mail/walk.go b/internal/mail/walk.go| index 0cdc65d53..8ac4a0583 100644 |
| --- a/internal/mail/walk.go |
| +++ b/internal/mail/walk.go |
| @@ -5,7 +5,6 @@ package mail |
| import ( |
| "context" |
| - "crypto/ecdh" |
| "errors" |
| "fmt" |
| "log" |
| @@ -759,7 +758,7 @@ func EnvDeliveredIn(ctx context.Context, s release.Store, acct, app, env, prefix |
| // checked; anything less and the rest of the walk runs too, because a |
| // missing or stale variable means the app cannot send what the record |
| // promises. |
| -func claimUnserializedEnable(ctx context.Context, s release.Store, p Provisioner, sealPub *ecdh.PublicKey, |
| +func claimUnserializedEnable(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| d Deployment, acct, app string, now time.Time) (*Record, error) { |
| rec, etag, err := Get(ctx, s, acct, app) |
| @@ -878,7 +877,7 @@ func claimUnserializedEnable(ctx context.Context, s release.Store, p Provisioner |
| return nil, err |
| } |
| - if err := writeSMTPEnv(ctx, s, sealPub, acct, app, rec.Declared.EnvPrefix, |
| + if err := writeSMTPEnv(ctx, s, seal, acct, app, rec.Declared.EnvPrefix, |
| d.Region, keyID, secret, rec.Declared.From); err != nil { |
| return nil, err |
| } |
| @@ -945,16 +944,16 @@ func claimUnserializedApplyGrant(ctx context.Context, s release.Store, acct, app |
| // mint+deliver leaves the app running on a key no record names, the pause |
| // aimed at a dead key, and the next rotation hitting IAM's two-key ceiling. |
| // _PASS remains sealed — it IS the secret. |
| -func writeSMTPEnv(ctx context.Context, s release.Store, sealPub *ecdh.PublicKey, |
| +func writeSMTPEnv(ctx context.Context, s release.Store, seal appconfig.Sealer, |
| acct, app, prefix, region, keyID, secret, from string) error { |
| - return writeSMTPEnvIn(ctx, s, sealPub, acct, app, "", prefix, region, keyID, secret, from) |
| + return writeSMTPEnvIn(ctx, s, seal, acct, app, "", prefix, region, keyID, secret, from) |
| } |
| // writeSMTPEnvIn is writeSMTPEnv into one bundle: the app's default bundle |
| // (env == "") or an owned environment's own (team-scoped credentials §3a). |
| // ApplyEnvironment goes through the same applyAt as Apply and keeps the |
| // bundle's owner mark and schema. |
| -func writeSMTPEnvIn(ctx context.Context, s release.Store, sealPub *ecdh.PublicKey, |
| +func writeSMTPEnvIn(ctx context.Context, s release.Store, seal appconfig.Sealer, |
| acct, app, env, prefix, region, keyID, secret, from string) error { |
| hostName, portName, userName, passName, fromName := EnvNames(prefix) |
| @@ -972,7 +971,7 @@ func writeSMTPEnvIn(ctx context.Context, s release.Store, sealPub *ecdh.PublicKe |
| if err := appconfig.ValidVarValue(password); err != nil { |
| return fmt.Errorf("mail: minted credential for %s is not EnvironmentFile-safe: %w", passName, err) |
| } |
| - envelope, err := appconfig.Seal(sealPub, appconfig.Binding{Account: acct, App: app}, []byte(password)) |
| + sealed, err := seal.Seal(appconfig.Binding{Account: acct, App: app}, []byte(password)) |
| if err != nil { |
| return fmt.Errorf("mail: seal %s: %w", passName, err) |
| } |
| @@ -982,7 +981,7 @@ func writeSMTPEnvIn(ctx context.Context, s release.Store, sealPub *ecdh.PublicKe |
| portName: {Kind: "env", Value: SMTPPort}, |
| fromName: {Kind: "env", Value: from}, |
| userName: {Kind: "env", Value: keyID}, |
| - passName: {Kind: "secret", Envelope: envelope}, |
| + passName: sealed, |
| } |
| if env != "" { |
| if _, err := appconfig.ApplyEnvironment(ctx, s, acct, app, env, sets, nil); err != nil { |
| @@ -1029,7 +1028,7 @@ func enforceKeyActive(ctx context.Context, p Provisioner, user, keyID string, ac |
| // |
| // The overlap consumes IAM's ceiling of two access keys per user, which is |
| // exactly why standalone credentials get their own principal. |
| -func claimUnserializedRotate(ctx context.Context, s release.Store, p Provisioner, sealPub *ecdh.PublicKey, |
| +func claimUnserializedRotate(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| d Deployment, acct, app string, now time.Time) (*Record, error) { |
| rec, etag, err := Get(ctx, s, acct, app) |
| @@ -1067,7 +1066,7 @@ func claimUnserializedRotate(ctx context.Context, s release.Store, p Provisioner |
| if err := enforceKeyActive(ctx, p, user, keyID, rec.Provisioned.Active); err != nil { |
| return nil, err |
| } |
| - if err := writeSMTPEnv(ctx, s, sealPub, acct, app, rec.Declared.EnvPrefix, |
| + if err := writeSMTPEnv(ctx, s, seal, acct, app, rec.Declared.EnvPrefix, |
| d.Region, keyID, secret, rec.Declared.From); err != nil { |
| return nil, err |
| } |
| @@ -1093,7 +1092,7 @@ func claimUnserializedRotate(ctx context.Context, s release.Store, p Provisioner |
| if err := enforceKeyActive(ctx, p, ep.IAMUser, envKey, ep.Active); err != nil { |
| return nil, err |
| } |
| - if err := writeSMTPEnvIn(ctx, s, sealPub, acct, app, env, rec.Declared.EnvPrefix, |
| + if err := writeSMTPEnvIn(ctx, s, seal, acct, app, env, rec.Declared.EnvPrefix, |
| d.Region, envKey, envSecret, rec.Declared.From); err != nil { |
| return nil, err |
| } |
| @@ -2028,10 +2027,10 @@ func Declare(ctx context.Context, s release.Store, acct, app, envPrefix, from, a |
| return claimResult0, claimErr |
| } |
| -func Enable(ctx context.Context, s release.Store, p Provisioner, sealPub *ecdh.PublicKey, |
| +func Enable(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| d Deployment, acct, app string, now time.Time) (*Record, error) { |
| if _, enabled := s.(ClaimMailStore); !enabled { |
| - return claimUnserializedEnable(ctx, s, p, sealPub, d, acct, app, now) |
| + return claimUnserializedEnable(ctx, s, p, seal, d, acct, app, now) |
| } |
| var claimResult0 *Record |
| claimErr := WithClaimMailResource(ctx, s, func(ctx context.Context) error { |
| @@ -2040,7 +2039,7 @@ func Enable(ctx context.Context, s release.Store, p Provisioner, sealPub *ecdh.P |
| p = claimMarkedProvisioner{raw: p} |
| } |
| var err error |
| - claimResult0, err = claimUnserializedEnable(ctx, s, p, sealPub, d, acct, app, now) |
| + claimResult0, err = claimUnserializedEnable(ctx, s, p, seal, d, acct, app, now) |
| return err |
| }) |
| }) |
| @@ -2063,10 +2062,10 @@ func ApplyGrant(ctx context.Context, s release.Store, acct, app string, |
| return claimResult0, claimErr |
| } |
| -func Rotate(ctx context.Context, s release.Store, p Provisioner, sealPub *ecdh.PublicKey, |
| +func Rotate(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| d Deployment, acct, app string, now time.Time) (*Record, error) { |
| if _, enabled := s.(ClaimMailStore); !enabled { |
| - return claimUnserializedRotate(ctx, s, p, sealPub, d, acct, app, now) |
| + return claimUnserializedRotate(ctx, s, p, seal, d, acct, app, now) |
| } |
| var claimResult0 *Record |
| claimErr := WithClaimMailResource(ctx, s, func(ctx context.Context) error { |
| @@ -2075,7 +2074,7 @@ func Rotate(ctx context.Context, s release.Store, p Provisioner, sealPub *ecdh.P |
| p = claimMarkedProvisioner{raw: p} |
| } |
| var err error |
| - claimResult0, err = claimUnserializedRotate(ctx, s, p, sealPub, d, acct, app, now) |
| + claimResult0, err = claimUnserializedRotate(ctx, s, p, seal, d, acct, app, now) |
| return err |
| }) |
| }) |
diff --git a/internal/mail/walk_domainremove_test.go b/internal/mail/walk_domainremove_test.go| index 3f88795b3..fe4461c0e 100644 |
| --- a/internal/mail/walk_domainremove_test.go |
| +++ b/internal/mail/walk_domainremove_test.go |
| @@ -354,7 +354,7 @@ func TestRemoveDomainShrinksTheDepartingAppsPolicy(t *testing.T) { |
| if _, err := VerifyDomain(ctx, s, p, testDeployment(), "bag", extra, "eu-west-1", now); err != nil { |
| t.Fatalf("VerifyDomain: %v", err) |
| } |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| user := p.Users[UserName("bag", "harbourmail")] |
diff --git a/internal/mail/walk_enable_test.go b/internal/mail/walk_enable_test.go| index 8da178a63..18fc00d01 100644 |
| --- a/internal/mail/walk_enable_test.go |
| +++ b/internal/mail/walk_enable_test.go |
| @@ -49,7 +49,7 @@ func enableFixture(t *testing.T) (context.Context, release.Store, *MemProvisione |
| // reads arrive, with the right values, and the app changes nothing. |
| func TestEnableDeliversHarbourmailsEnv(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - rec, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + rec, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| @@ -109,7 +109,7 @@ func TestEnableDeliversTheDerivedPasswordNotTheSecret(t *testing.T) { |
| t.Fatalf("ParsePublicKey: %v", err) |
| } |
| - rec, err := Enable(ctx, s, p, ownPub, testDeployment(), "bag", "harbourmail", now) |
| + rec, err := Enable(ctx, s, p, mailTestSealer(ownPub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| @@ -188,7 +188,7 @@ func TestEnsureDomainRefreshesPoliciesWhenItBindsAConfigSet(t *testing.T) { |
| if _, err := VerifyDomain(ctx, s, p, testDeployment(), "bag", "seapointish.bag.oncarlos.com", "eu-west-1", now); err != nil { |
| t.Fatalf("VerifyDomain: %v", err) |
| } |
| - if _, err := Enable(ctx, s, p, pub, noSNS, "bag", "seapointish", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "seapointish"), noSNS, "bag", "seapointish", now); err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| if _, err := CreateStandalone(ctx, s, p, noSNS, "bag", "seapointish", "smoke", "paul@rslw.com", now); err != nil { |
| @@ -238,7 +238,7 @@ func TestEnsureDomainRefreshesPoliciesWhenItBindsAConfigSet(t *testing.T) { |
| // cannot pass vacuously the day EnsureDomain stops binding a set. |
| func TestEnableGrantsTheConfigSetToTheDeliveredUser(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| dom, _, err := GetDomain(ctx, s, "bag", "harbourmail.bag.oncarlos.com") |
| @@ -263,7 +263,7 @@ func TestEnableGrantsTheConfigSetToTheDeliveredUser(t *testing.T) { |
| // regress independently of the delivered one. |
| func TestCreateStandaloneGrantsTheConfigSetToo(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| if _, err := CreateStandalone(ctx, s, p, testDeployment(), "bag", "harbourmail", "smoke", "owner@example.test", now); err != nil { |
| @@ -287,11 +287,11 @@ func TestCreateStandaloneGrantsTheConfigSetToo(t *testing.T) { |
| func TestEnableIsIdempotent(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - first, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + first, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("first Enable: %v", err) |
| } |
| - second, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + second, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("second Enable: %v", err) |
| } |
| @@ -312,7 +312,7 @@ func TestEnableRefusesWithoutAVerifiedDomain(t *testing.T) { |
| Declare(ctx, s, "bag", "harbourmail", "HARBOURMAIL_SMTP", "n@x.com", "owner@example.test", now) |
| EnsureDomain(ctx, s, p, dnsrec.NewMemWriter(), testDeployment(), |
| "bag", "harbourmail", "harbourmail.bag.oncarlos.com", now) // left pending |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err == nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err == nil { |
| t.Fatal("Enable succeeded with only a pending domain") |
| } |
| } |
| @@ -323,7 +323,7 @@ func TestEnableRefusesAnUndeclaredApp(t *testing.T) { |
| now := time.Now().UTC() |
| _, pubB64, _ := appconfig.GenerateKey() |
| pub, _ := appconfig.ParsePublicKey(pubB64, "test") |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != ErrNotDeclared { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != ErrNotDeclared { |
| t.Fatalf("Enable on an undeclared app = %v, want ErrNotDeclared", err) |
| } |
| } |
| @@ -342,7 +342,7 @@ func TestDeclareAcceptsAnyFromButEnableRefusesAnUngrantedOne(t *testing.T) { |
| t.Fatalf("Declare itself may accept any From: %v", err) |
| } |
| // but Enable, which knows the granted domains, must refuse it |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err == nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err == nil { |
| t.Fatal("Enable accepted a From address outside every granted domain") |
| } |
| } |
| @@ -355,7 +355,7 @@ func TestDeclareAcceptsAnyFromButEnableRefusesAnUngrantedOne(t *testing.T) { |
| // silently the next time delivery needed repair. |
| func TestEnableCarriesAPausedActiveForwardThroughARewalk(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != nil { |
| t.Fatalf("first Enable: %v", err) |
| } |
| @@ -377,7 +377,7 @@ func TestEnableCarriesAPausedActiveForwardThroughARewalk(t *testing.T) { |
| t.Fatalf("Unset: %v", err) |
| } |
| - second, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + second, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("re-walk Enable: %v", err) |
| } |
| @@ -398,7 +398,7 @@ func TestEnableCarriesAPausedActiveForwardThroughARewalk(t *testing.T) { |
| // disagreement that would otherwise be permanent. |
| func TestEnvDeliveredAndEnableCatchAStaleRecordedKeyID(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - first, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + first, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("first Enable: %v", err) |
| } |
| @@ -421,7 +421,7 @@ func TestEnvDeliveredAndEnableCatchAStaleRecordedKeyID(t *testing.T) { |
| t.Fatalf("missing = %v, want HARBOURMAIL_SMTP_USER reported", missing) |
| } |
| - second, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + second, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("second Enable: %v", err) |
| } |
| @@ -441,7 +441,7 @@ func TestEnvDeliveredAndEnableCatchAStaleRecordedKeyID(t *testing.T) { |
| // the policy without rotating a credential." |
| func TestEnableRewritesThePolicyWhenASecondDomainIsAdded(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - first, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + first, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("first Enable: %v", err) |
| } |
| @@ -457,7 +457,7 @@ func TestEnableRewritesThePolicyWhenASecondDomainIsAdded(t *testing.T) { |
| t.Fatalf("VerifyDomain second: %v", err) |
| } |
| - rewalked, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + rewalked, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("re-enable: %v", err) |
| } |
| @@ -491,7 +491,7 @@ func TestEnableRewritesThePolicyWhenADomainStopsVerifying(t *testing.T) { |
| t.Fatalf("VerifyDomain second: %v", err) |
| } |
| - first, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + first, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("first Enable: %v", err) |
| } |
| @@ -506,7 +506,7 @@ func TestEnableRewritesThePolicyWhenADomainStopsVerifying(t *testing.T) { |
| t.Fatalf("VerifyDomain regression: %v", err) |
| } |
| - rewalked, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + rewalked, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("re-enable after regression: %v", err) |
| } |
| @@ -530,7 +530,7 @@ func TestEnableRewritesThePolicyWhenADomainStopsVerifying(t *testing.T) { |
| // forever because nothing ever compared _FROM's VALUE. |
| func TestEnableRedeliversAChangedFromAddress(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - first, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + first, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("first Enable: %v", err) |
| } |
| @@ -548,7 +548,7 @@ func TestEnableRedeliversAChangedFromAddress(t *testing.T) { |
| t.Fatalf("missing = %v, want HARBOURMAIL_SMTP_FROM reported after a re-declare changed it", missing) |
| } |
| - second, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + second, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("re-enable: %v", err) |
| } |
diff --git a/internal/mail/walk_environment.go b/internal/mail/walk_environment.go| index 9efea2b23..42222cceb 100644 |
| --- a/internal/mail/walk_environment.go |
| +++ b/internal/mail/walk_environment.go |
| @@ -15,7 +15,6 @@ package mail |
| import ( |
| "context" |
| - "crypto/ecdh" |
| "errors" |
| "fmt" |
| "time" |
| @@ -34,7 +33,7 @@ var ErrEnvironmentNotOwned = errors.New("mail: environment is not owned by a tea |
| // bundle. Idempotent the way Enable is: a healthy delivered environment |
| // (its record names a key and the five variables carry it) is a no-op, |
| // and anything less reaps and re-mints. |
| -func claimUnserializedEnableEnvironment(ctx context.Context, s release.Store, p Provisioner, sealPub *ecdh.PublicKey, |
| +func claimUnserializedEnableEnvironment(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| d Deployment, acct, app, env string, now time.Time) (*Record, error) { |
| if !appconfig.ValidEnvironmentName(env) { |
| @@ -114,7 +113,7 @@ func claimUnserializedEnableEnvironment(ctx context.Context, s release.Store, p |
| if err := enforceKeyActive(ctx, p, user, keyID, active); err != nil { |
| return nil, err |
| } |
| - if err := writeSMTPEnvIn(ctx, s, sealPub, acct, app, env, rec.Declared.EnvPrefix, |
| + if err := writeSMTPEnvIn(ctx, s, seal, acct, app, env, rec.Declared.EnvPrefix, |
| d.Region, keyID, secret, rec.Declared.From); err != nil { |
| return nil, err |
| } |
| @@ -195,10 +194,10 @@ func unsetSMTPEnvIn(ctx context.Context, s release.Store, acct, app, env, prefix |
| return nil |
| } |
| -func EnableEnvironment(ctx context.Context, s release.Store, p Provisioner, sealPub *ecdh.PublicKey, |
| +func EnableEnvironment(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| d Deployment, acct, app, env string, now time.Time) (*Record, error) { |
| if _, enabled := s.(ClaimMailStore); !enabled { |
| - return claimUnserializedEnableEnvironment(ctx, s, p, sealPub, d, acct, app, env, now) |
| + return claimUnserializedEnableEnvironment(ctx, s, p, seal, d, acct, app, env, now) |
| } |
| var claimResult0 *Record |
| claimErr := WithClaimMailResource(ctx, s, func(ctx context.Context) error { |
| @@ -207,7 +206,7 @@ func EnableEnvironment(ctx context.Context, s release.Store, p Provisioner, seal |
| p = claimMarkedProvisioner{raw: p} |
| } |
| var err error |
| - claimResult0, err = claimUnserializedEnableEnvironment(ctx, s, p, sealPub, d, acct, app, env, now) |
| + claimResult0, err = claimUnserializedEnableEnvironment(ctx, s, p, seal, d, acct, app, env, now) |
| return err |
| }) |
| }) |
diff --git a/internal/mail/walk_environment_test.go b/internal/mail/walk_environment_test.go| index 3558304f7..cf275482b 100644 |
| --- a/internal/mail/walk_environment_test.go |
| +++ b/internal/mail/walk_environment_test.go |
| @@ -42,17 +42,17 @@ func TestEnvironmentUserNameAndCallerParsing(t *testing.T) { |
| func TestEnableEnvironmentMintsADistinctCredentialIntoTheOwnedBundle(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - rec, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + rec, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatal(err) |
| } |
| - if _, err := EnableEnvironment(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", "team", now); err != ErrEnvironmentNotOwned { |
| + if _, err := EnableEnvironment(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", "team", now); err != ErrEnvironmentNotOwned { |
| t.Fatalf("EnableEnvironment of a missing environment = %v, want ErrEnvironmentNotOwned", err) |
| } |
| if err := saveUnownedEnvironment(ctx, s, "bag", "harbourmail", "plain"); err != nil { |
| t.Fatal(err) |
| } |
| - if _, err := EnableEnvironment(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", "plain", now); err != ErrEnvironmentNotOwned { |
| + if _, err := EnableEnvironment(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", "plain", now); err != ErrEnvironmentNotOwned { |
| t.Fatalf("EnableEnvironment of an unowned environment = %v, want ErrEnvironmentNotOwned", err) |
| } |
| if _, err := appconfig.ApplyEnvironmentOwned(ctx, s, "bag", "harbourmail", "team", "alta", |
| @@ -60,7 +60,7 @@ func TestEnableEnvironmentMintsADistinctCredentialIntoTheOwnedBundle(t *testing. |
| t.Fatal(err) |
| } |
| before, _ := appconfig.Get(ctx, s, "bag", "harbourmail") |
| - rec, err = EnableEnvironment(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", "team", now) |
| + rec, err = EnableEnvironment(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", "team", now) |
| if err != nil { |
| t.Fatalf("EnableEnvironment: %v", err) |
| } |
| @@ -100,7 +100,7 @@ func TestEnableEnvironmentMintsADistinctCredentialIntoTheOwnedBundle(t *testing. |
| } |
| } |
| // Idempotent: a healthy delivery mints nothing. |
| - again, err := EnableEnvironment(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", "team", now) |
| + again, err := EnableEnvironment(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", "team", now) |
| if err != nil || again.Environments["team"].KeyID != ep.KeyID { |
| t.Fatalf("second EnableEnvironment = %+v, %v; want the same key", again.Environments["team"], err) |
| } |
| @@ -112,7 +112,7 @@ func TestEnableEnvironmentMintsADistinctCredentialIntoTheOwnedBundle(t *testing. |
| map[string]appconfig.Var{"X": {Kind: "env", Value: "1"}}, nil); err != nil { |
| t.Fatal(err) |
| } |
| - rec, err = EnableEnvironment(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", "team-2", now) |
| + rec, err = EnableEnvironment(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", "team-2", now) |
| if err != nil || rec.Environments["team-2"] == nil || rec.Environments["team-2"].KeyID == ep.KeyID { |
| t.Fatalf("second environment = %+v, %v", rec.Environments, err) |
| } |
| @@ -120,19 +120,19 @@ func TestEnableEnvironmentMintsADistinctCredentialIntoTheOwnedBundle(t *testing. |
| func TestEnvironmentCredentialRotatesPausesAndTearsDownWithTheApp(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != nil { |
| t.Fatal(err) |
| } |
| if _, err := appconfig.ApplyEnvironmentOwned(ctx, s, "bag", "harbourmail", "team", "alta", |
| map[string]appconfig.Var{"TEAM_ONLY": {Kind: "env", Value: "1"}}, nil); err != nil { |
| t.Fatal(err) |
| } |
| - rec, err := EnableEnvironment(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", "team", now) |
| + rec, err := EnableEnvironment(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", "team", now) |
| if err != nil { |
| t.Fatal(err) |
| } |
| first := rec.Environments["team"].KeyID |
| - rec, err = Rotate(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + rec, err = Rotate(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -178,7 +178,7 @@ func TestEnvironmentCredentialRotatesPausesAndTearsDownWithTheApp(t *testing.T) |
| t.Fatalf("a second reap: %v", err) |
| } |
| // Teardown deletes an environment's user with the app's. |
| - rec, err = EnableEnvironment(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", "team", now) |
| + rec, err = EnableEnvironment(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", "team", now) |
| if err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/mail/walk_lifecycle_test.go b/internal/mail/walk_lifecycle_test.go| index dca7cb085..ddb502568 100644 |
| --- a/internal/mail/walk_lifecycle_test.go |
| +++ b/internal/mail/walk_lifecycle_test.go |
| @@ -19,13 +19,13 @@ import ( |
| // for minutes after delivery. Killing it at rotation time is an outage. |
| func TestRotateKeepsTheOldKeyLive(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - first, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + first, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| old := first.Provisioned.KeyID |
| - rec, err := Rotate(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + rec, err := Rotate(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("Rotate: %v", err) |
| } |
| @@ -52,14 +52,14 @@ func TestRotateKeepsTheOldKeyLive(t *testing.T) { |
| // pause. |
| func TestRotateDoesNotLiftAPauseAtIAM(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| if _, err := SetPaused(ctx, s, p, "bag", "harbourmail", true, "", now); err != nil { |
| t.Fatalf("SetPaused(true): %v", err) |
| } |
| - rec, err := Rotate(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + rec, err := Rotate(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("Rotate: %v", err) |
| } |
| @@ -80,8 +80,8 @@ func TestRotateDoesNotLiftAPauseAtIAM(t *testing.T) { |
| // using, so it is explicit and separate. |
| func TestRotateFinishClosesTheWindow(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| - rec, _ := Rotate(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| + rec, _ := Rotate(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| old := rec.Provisioned.PrevKeyID |
| done, err := RotateFinish(ctx, s, p, "bag", "harbourmail") |
| @@ -102,7 +102,7 @@ func TestRotateFinishClosesTheWindow(t *testing.T) { |
| // one, and MintKey always hands back a live key. |
| func TestEnableRepairDoesNotLiftAPauseAtIAM(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != nil { |
| t.Fatalf("first Enable: %v", err) |
| } |
| if _, err := SetPaused(ctx, s, p, "bag", "harbourmail", true, "", now); err != nil { |
| @@ -115,7 +115,7 @@ func TestEnableRepairDoesNotLiftAPauseAtIAM(t *testing.T) { |
| t.Fatalf("Unset: %v", err) |
| } |
| - rec, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + rec, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("repair Enable: %v", err) |
| } |
| @@ -137,7 +137,7 @@ func TestEnableRepairDoesNotLiftAPauseAtIAM(t *testing.T) { |
| // and could half-fail into a broken grant. |
| func TestPauseAndResumeToggleTheKeyNotThePolicy(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - rec, _ := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + rec, _ := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| user := UserName("bag", "harbourmail") |
| policyBefore := p.Users[user].Policy |
| @@ -168,8 +168,8 @@ func TestPauseAndResumeToggleTheKeyNotThePolicy(t *testing.T) { |
| // previous credential, so pausing only the current one leaves it sending. |
| func TestPauseTogglesBothKeysDuringARotationOverlap(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| - rec, err := Rotate(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| + rec, err := Rotate(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if err != nil { |
| t.Fatalf("Rotate: %v", err) |
| } |
| @@ -201,7 +201,7 @@ func TestPauseTogglesBothKeysDuringARotationOverlap(t *testing.T) { |
| // laptop credential on the very domain the pause was meant to protect. |
| func TestPauseReachesStandaloneCredentials(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if _, err := CreateStandalone(ctx, s, p, testDeployment(), "bag", "harbourmail", |
| "laptop", "owner@example.test", now); err != nil { |
| t.Fatalf("CreateStandalone: %v", err) |
| @@ -261,7 +261,7 @@ func TestPauseReachesStandaloneCredentials(t *testing.T) { |
| // did not cover. |
| func TestCreateStandaloneDoesNotBypassAPause(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| if _, err := SetPaused(ctx, s, p, "bag", "harbourmail", true, "", now); err != nil { |
| @@ -292,7 +292,7 @@ func TestCreateStandaloneDoesNotBypassAPause(t *testing.T) { |
| // paused. |
| func TestCreateStandaloneReMintWhilePausedStaysInactiveAndResumeReactivates(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| if _, err := SetPaused(ctx, s, p, "bag", "harbourmail", true, "", now); err != nil { |
| @@ -342,7 +342,7 @@ func TestCreateStandaloneReMintWhilePausedStaysInactiveAndResumeReactivates(t *t |
| // overlap. Sharing would work until the first rotation and then break it. |
| func TestStandaloneGetsItsOwnUserAndDoesNotDisturbDelivery(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - rec, _ := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + rec, _ := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| delivered := rec.Provisioned.KeyID |
| creds, err := CreateStandalone(ctx, s, p, testDeployment(), "bag", "harbourmail", "laptop", "owner@example.test", now) |
| @@ -390,7 +390,7 @@ func TestCreateStandaloneRefusesAnInvalidName(t *testing.T) { |
| // Otherwise one app's teardown revokes a sibling's verified domain. |
| func TestTeardownKeepsASharedDomainAlive(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| // A sibling app joins the same domain. |
| if _, _, err := EnsureDomain(ctx, s, p, memWriterForTest(), testDeployment(), |
| "bag", "marketing", "harbourmail.bag.oncarlos.com", now); err != nil { |
| @@ -431,7 +431,7 @@ func TestTeardownKeepsASharedDomainAlive(t *testing.T) { |
| // destroyed out from under it. |
| func TestTeardownDestroyDecisionSeesASiblingThatJoinsBetweenListAndDecision(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| domain := "harbourmail.bag.oncarlos.com" |
| rs := &raceGetStore{ |
| @@ -497,7 +497,7 @@ func (r *raceGetStore) Get(ctx context.Context, key string) ([]byte, string, err |
| // referrer. |
| func TestTeardownRemovesTheIdentityWhenTheLastAppGoes(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now) |
| + Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now) |
| if _, err := CreateStandalone(ctx, s, p, testDeployment(), "bag", "harbourmail", |
| "laptop", "owner@example.test", now); err != nil { |
| t.Fatalf("CreateStandalone: %v", err) |
| @@ -553,7 +553,7 @@ func TestTeardownRemovesTheIdentityWhenTheLastAppGoes(t *testing.T) { |
| // DeleteIdentity and finishes when nothing is really associated. |
| func TestTeardownReachesDeleteIdentityDespiteAFailedDisassociate(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| w := dnsrec.NewMemWriter() |
| @@ -587,7 +587,7 @@ func TestTeardownReachesDeleteIdentityDespiteAFailedDisassociate(t *testing.T) { |
| // failure instead of the disassociate call. |
| func TestTeardownStillRefusesADeleteWhileReallyAssociated(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| w := dnsrec.NewMemWriter() |
| @@ -658,7 +658,7 @@ func TestTeardownDeletesTheLegacyRecordToo(t *testing.T) { |
| // UTC day roll the credential every instance still holds. |
| func TestPerInstanceModeRefusesAResume(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| - if _, err := Enable(ctx, s, p, pub, testDeployment(), "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), testDeployment(), "bag", "harbourmail", now); err != nil { |
| t.Fatal(err) |
| } |
| if _, err := SetPaused(ctx, s, p, "bag", "harbourmail", true, PauseKindCap, now); err != nil { |
diff --git a/internal/mail/walk_verify_test.go b/internal/mail/walk_verify_test.go| index 15a9d7fac..513bebc0b 100644 |
| --- a/internal/mail/walk_verify_test.go |
| +++ b/internal/mail/walk_verify_test.go |
| @@ -196,7 +196,7 @@ func TestVerifyDomainUnbindsWhenTheDeploymentHasNoTopic(t *testing.T) { |
| func TestVerifyDomainRefreshesPoliciesWhenItRebinds(t *testing.T) { |
| ctx, s, p, pub, now := enableFixture(t) |
| d := testDeployment() |
| - if _, err := Enable(ctx, s, p, pub, d, "bag", "harbourmail", now); err != nil { |
| + if _, err := Enable(ctx, s, p, mailTestSealer(pub, "bag", "harbourmail"), d, "bag", "harbourmail", now); err != nil { |
| t.Fatalf("Enable: %v", err) |
| } |
| // Strip the config-set ARN back out of the policy, as it would be on an |
diff --git a/internal/objstore/enforce_test.go b/internal/objstore/enforce_test.go| index 68f7e85a6..14c311c74 100644 |
| --- a/internal/objstore/enforce_test.go |
| +++ b/internal/objstore/enforce_test.go |
| @@ -175,7 +175,7 @@ func TestGrantWritesDenyOnHealthyStore(t *testing.T) { |
| t.Fatal(err) |
| } |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), |
| "bab", "titogo", "op@example.com", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
| @@ -207,7 +207,7 @@ func TestGrantClearsDenyWhenEnforceIsCleared(t *testing.T) { |
| if _, err := Put(ctx, s, "bab", "titogo", stored, etag); err != nil { |
| t.Fatal(err) |
| } |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), |
| "bab", "titogo", "op@example.com", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
| @@ -223,7 +223,7 @@ func TestGrantClearsDenyWhenEnforceIsCleared(t *testing.T) { |
| if _, err := Put(ctx, s, "bab", "titogo", stored, etag); err != nil { |
| t.Fatal(err) |
| } |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), |
| "bab", "titogo", "op@example.com", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/objstore/nameclaim_test.go b/internal/objstore/nameclaim_test.go| index b1d805f74..074f10fc7 100644 |
| --- a/internal/objstore/nameclaim_test.go |
| +++ b/internal/objstore/nameclaim_test.go |
| @@ -34,7 +34,7 @@ func forgetNameClaims(t *testing.T, s release.Store) { |
| func grantStore(t *testing.T, s release.Store, p *MemProvisioner, acct, app, env, adopt string) (*Record, error) { |
| t.Helper() |
| _, pub := testSealKeypair(t) |
| - return GrantIn(context.Background(), s, p, testDeployment(), pub, acct, app, env, "op", GrantSourceOperator, adopt, time.Now().UTC()) |
| + return GrantIn(context.Background(), s, p, testDeployment(), storeTestSealer(pub, acct, app), acct, app, env, "op", GrantSourceOperator, adopt, time.Now().UTC()) |
| } |
| func TestCollidingStoresResolveToTheSameNames(t *testing.T) { |
diff --git a/internal/objstore/walk.go b/internal/objstore/walk.go| index 801fde0fb..baaa15f46 100644 |
| --- a/internal/objstore/walk.go |
| +++ b/internal/objstore/walk.go |
| @@ -6,7 +6,6 @@ package objstore |
| import ( |
| "context" |
| - "crypto/ecdh" |
| "errors" |
| "fmt" |
| "regexp" |
| @@ -189,8 +188,8 @@ func ValidBucketName(name string) bool { return bucketNameRe.MatchString(name) } |
| // whose authority was already established and must not restate it, exactly as |
| // it must not re-choose the bucket. |
| func claimRawGrant(ctx context.Context, s release.Store, p Provisioner, d Deployment, |
| - sealPub *ecdh.PublicKey, acct, app, actor, source, adoptBucket string, now time.Time) (*Record, error) { |
| - return GrantIn(ctx, s, p, d, sealPub, acct, app, "", actor, source, adoptBucket, now) |
| + seal appconfig.Sealer, acct, app, actor, source, adoptBucket string, now time.Time) (*Record, error) { |
| + return GrantIn(ctx, s, p, d, seal, acct, app, "", actor, source, adoptBucket, now) |
| } |
| // GrantIn is Grant for one store of an app: the app's own when env is "", |
| @@ -209,7 +208,7 @@ func claimRawGrant(ctx context.Context, s release.Store, p Provisioner, d Deploy |
| // therefore survives only while its own seed is the only one granting. |
| // A record with no mark is written exactly as before. |
| func claimRawGrantIn(ctx context.Context, s release.Store, p Provisioner, d Deployment, |
| - sealPub *ecdh.PublicKey, acct, app, env, actor, source, adoptBucket, seed string, now time.Time) (*Record, error) { |
| + seal appconfig.Sealer, acct, app, env, actor, source, adoptBucket, seed string, now time.Time) (*Record, error) { |
| // 1. resolve + write the grant block |
| rec, etag, err := GetIn(ctx, s, acct, app, env) |
| if err != nil { |
| @@ -336,7 +335,7 @@ func claimRawGrantIn(ctx context.Context, s release.Store, p Provisioner, d Depl |
| return nil, fmt.Errorf("objstore: mint key for %s: %w", user, err) |
| } |
| // 5. deliver — the secret's ONLY landing place (§7) |
| - if err := writeEnv(ctx, s, sealPub, acct, app, env, rec.Declared.EnvPrefix, bucket, region, d.Endpoint, id, secret); err != nil { |
| + if err := writeEnv(ctx, s, seal, acct, app, env, rec.Declared.EnvPrefix, bucket, region, d.Endpoint, id, secret); err != nil { |
| return nil, err |
| } |
| // 6. record success — after the secret is recorded, never before (§5). |
| @@ -432,15 +431,15 @@ func claimRawGrantIn(ctx context.Context, s release.Store, p Provisioner, d Depl |
| // names the key this walk started from, i.e. no other rotation landed in |
| // between. A blind retry would clobber a concurrent rotate and strand ITS |
| // delivered key, which is the exact failure the retry exists to prevent. |
| -func claimRawRotate(ctx context.Context, s release.Store, p Provisioner, sealPub *ecdh.PublicKey, |
| +func claimRawRotate(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| acct, app string, now time.Time) (*Record, error) { |
| - return RotateIn(ctx, s, p, sealPub, acct, app, "", now) |
| + return RotateIn(ctx, s, p, seal, acct, app, "", now) |
| } |
| // RotateIn is Rotate for one store of an app. Coordinates come from that |
| // store's own record, so a rotation of an environment store never reaches for |
| // the app store's bucket, principal or bundle. |
| -func claimRawRotateIn(ctx context.Context, s release.Store, p Provisioner, sealPub *ecdh.PublicKey, |
| +func claimRawRotateIn(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, |
| acct, app, env string, now time.Time) (*Record, error) { |
| rec, etag, err := GetIn(ctx, s, acct, app, env) |
| if err != nil { |
| @@ -473,7 +472,7 @@ func claimRawRotateIn(ctx context.Context, s release.Store, p Provisioner, sealP |
| } |
| // 4. deliver — same names, same single CAS write, same validation of the |
| // credential halves before sealing (writeEnv owns that rail). |
| - if err := writeEnv(ctx, s, sealPub, acct, app, env, rec.Declared.EnvPrefix, |
| + if err := writeEnv(ctx, s, seal, acct, app, env, rec.Declared.EnvPrefix, |
| pr.Bucket, pr.Region, pr.Endpoint, id, secret); err != nil { |
| return nil, err |
| } |
| @@ -865,7 +864,7 @@ func deleteRecordIfUnchanged(ctx context.Context, s release.Store, acct, app, en |
| // _ENDPOINT would keep pointing every host at an address the deployment no |
| // longer uses. The set half is always non-empty, so this never trips |
| // applyAt's refusal to create a bundle on an unset-only call. |
| -func writeEnv(ctx context.Context, s release.Store, sealPub *ecdh.PublicKey, |
| +func writeEnv(ctx context.Context, s release.Store, seal appconfig.Sealer, |
| acct, app, env, prefix, bucket, region, endpoint, keyID, secret string) error { |
| bucketName, regionName, endpointName, accessKeyName, secretKeyName := EnvNames(prefix) |
| sets := map[string]appconfig.Var{ |
| @@ -891,11 +890,11 @@ func writeEnv(ctx context.Context, s release.Store, sealPub *ecdh.PublicKey, |
| if err := appconfig.ValidVarValue(half.plain); err != nil { |
| return fmt.Errorf("objstore: minted credential for %s is not EnvironmentFile-safe: %w", half.name, err) |
| } |
| - env, err := appconfig.Seal(sealPub, appconfig.Binding{Account: acct, App: app}, []byte(half.plain)) |
| + v, err := seal.Seal(appconfig.Binding{Account: acct, App: app}, []byte(half.plain)) |
| if err != nil { |
| return fmt.Errorf("objstore: seal %s: %w", half.name, err) |
| } |
| - sets[half.name] = appconfig.Var{Kind: "secret", Envelope: env} |
| + sets[half.name] = v |
| } |
| // The bundle the store belongs to, which is the bundle the instances |
| // bound to it already read. ApplyEnvironment is the same one-write |
| @@ -913,29 +912,29 @@ func writeEnv(ctx context.Context, s release.Store, sealPub *ecdh.PublicKey, |
| } |
| return nil |
| } |
| -func Grant(ctx context.Context, s release.Store, p Provisioner, d Deployment, sealPub *ecdh.PublicKey, acct, app, actor, source, adoptBucket string, now time.Time) (claimResult0 *Record, claimResult1 error) { |
| +func Grant(ctx context.Context, s release.Store, p Provisioner, d Deployment, seal appconfig.Sealer, acct, app, actor, source, adoptBucket string, now time.Time) (claimResult0 *Record, claimResult1 error) { |
| claimResult1 = release.WithAppMutation(ctx, s, acct, app, "objstore.Grant", func(claimContext context.Context) error { |
| - claimResult0, claimResult1 = claimRawGrant(claimContext, s, p, d, sealPub, acct, app, actor, source, adoptBucket, now) |
| + claimResult0, claimResult1 = claimRawGrant(claimContext, s, p, d, seal, acct, app, actor, source, adoptBucket, now) |
| return claimResult1 |
| }) |
| return |
| } |
| -func GrantIn(ctx context.Context, s release.Store, p Provisioner, d Deployment, sealPub *ecdh.PublicKey, acct, app, env, actor, source, adoptBucket string, now time.Time) (claimResult0 *Record, claimResult1 error) { |
| - return GrantInFor(ctx, s, p, d, sealPub, acct, app, env, actor, source, adoptBucket, "", now) |
| +func GrantIn(ctx context.Context, s release.Store, p Provisioner, d Deployment, seal appconfig.Sealer, acct, app, env, actor, source, adoptBucket string, now time.Time) (claimResult0 *Record, claimResult1 error) { |
| + return GrantInFor(ctx, s, p, d, seal, acct, app, env, actor, source, adoptBucket, "", now) |
| } |
| // GrantInFor is GrantIn for a seeded create's store: seed is the seed id |
| // whose mark the grant keeps. Every other grant is GrantIn, seed "". |
| -func GrantInFor(ctx context.Context, s release.Store, p Provisioner, d Deployment, sealPub *ecdh.PublicKey, acct, app, env, actor, source, adoptBucket, seed string, now time.Time) (claimResult0 *Record, claimResult1 error) { |
| +func GrantInFor(ctx context.Context, s release.Store, p Provisioner, d Deployment, seal appconfig.Sealer, acct, app, env, actor, source, adoptBucket, seed string, now time.Time) (claimResult0 *Record, claimResult1 error) { |
| claimResult1 = release.WithAppMutation(ctx, s, acct, app, "objstore.GrantIn", func(claimContext context.Context) error { |
| - claimResult0, claimResult1 = claimRawGrantIn(claimContext, s, p, d, sealPub, acct, app, env, actor, source, adoptBucket, seed, now) |
| + claimResult0, claimResult1 = claimRawGrantIn(claimContext, s, p, d, seal, acct, app, env, actor, source, adoptBucket, seed, now) |
| return claimResult1 |
| }) |
| return |
| } |
| -func Rotate(ctx context.Context, s release.Store, p Provisioner, sealPub *ecdh.PublicKey, acct, app string, now time.Time) (claimResult0 *Record, claimResult1 error) { |
| +func Rotate(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, acct, app string, now time.Time) (claimResult0 *Record, claimResult1 error) { |
| claimResult1 = release.WithAppMutation(ctx, s, acct, app, "objstore.Rotate", func(claimContext context.Context) error { |
| - claimResult0, claimResult1 = claimRawRotate(claimContext, s, p, sealPub, acct, app, now) |
| + claimResult0, claimResult1 = claimRawRotate(claimContext, s, p, seal, acct, app, now) |
| return claimResult1 |
| }) |
| return |
| @@ -954,9 +953,9 @@ func RotateFinishIn(ctx context.Context, s release.Store, p Provisioner, acct, a |
| }) |
| return |
| } |
| -func RotateIn(ctx context.Context, s release.Store, p Provisioner, sealPub *ecdh.PublicKey, acct, app, env string, now time.Time) (claimResult0 *Record, claimResult1 error) { |
| +func RotateIn(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, acct, app, env string, now time.Time) (claimResult0 *Record, claimResult1 error) { |
| claimResult1 = release.WithAppMutation(ctx, s, acct, app, "objstore.RotateIn", func(claimContext context.Context) error { |
| - claimResult0, claimResult1 = claimRawRotateIn(claimContext, s, p, sealPub, acct, app, env, now) |
| + claimResult0, claimResult1 = claimRawRotateIn(claimContext, s, p, seal, acct, app, env, now) |
| return claimResult1 |
| }) |
| return |
diff --git a/internal/objstore/walk_env_test.go b/internal/objstore/walk_env_test.go| index 3e91aec30..db0b17195 100644 |
| --- a/internal/objstore/walk_env_test.go |
| +++ b/internal/objstore/walk_env_test.go |
| @@ -52,7 +52,7 @@ func TestGrantInDeliversToTheEnvironmentBundle(t *testing.T) { |
| p.MintSecret = "beta-minted-secret" |
| declareIn(t, s, "bab", "titogo", "beta", "TITO_S3") |
| - rec, err := GrantIn(ctx, s, p, testDeployment(), pub, "bab", "titogo", "beta", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + rec, err := GrantIn(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "beta", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -96,7 +96,7 @@ func TestGrantInDeliversToTheEnvironmentBundle(t *testing.T) { |
| // idempotence short-circuit reads the DEFAULT bundle: every name would |
| // read as missing, and every walk would reap and mint a fresh key. |
| keyID := rec.Provisioned.KeyID |
| - again, err := GrantIn(ctx, s, p, testDeployment(), pub, "bab", "titogo", "beta", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + again, err := GrantIn(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "beta", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -116,12 +116,12 @@ func TestEnvironmentStoreAndAppStoreAreSeparateEstates(t *testing.T) { |
| d := testDeployment() |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - appRec, err := Grant(ctx, s, p, d, pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + appRec, err := Grant(ctx, s, p, d, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| declareIn(t, s, "bab", "titogo", "beta", "TITO_S3") |
| - envRec, err := GrantIn(ctx, s, p, d, pub, "bab", "titogo", "beta", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + envRec, err := GrantIn(ctx, s, p, d, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "beta", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -189,7 +189,7 @@ func TestGrantInRefusesAnUnnameablePrincipal(t *testing.T) { |
| if got := len(MintedBucketIn(d, "bab", app, env)); got != 63 { |
| t.Fatalf("fixture drift: bucket name is %d characters, want 63 (legal)", got) |
| } |
| - _, err := GrantIn(ctx, s, p, d, pub, "bab", app, env, "op", GrantSourceOperator, "", time.Now().UTC()) |
| + _, err := GrantIn(ctx, s, p, d, storeTestSealer(pub, "bab", app), "bab", app, env, "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err == nil || !strings.Contains(err.Error(), "over AWS's 64") { |
| t.Fatalf("GrantIn with an unnameable principal = %v, want the length refusal", err) |
| } |
| @@ -217,12 +217,12 @@ func TestTeardownInLeavesTheAppStoreStanding(t *testing.T) { |
| d := testDeployment() |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - appRec, err := Grant(ctx, s, p, d, pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + appRec, err := Grant(ctx, s, p, d, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| declareIn(t, s, "bab", "titogo", "beta", "TITO_S3") |
| - envRec, err := GrantIn(ctx, s, p, d, pub, "bab", "titogo", "beta", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + envRec, err := GrantIn(ctx, s, p, d, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "beta", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -286,7 +286,7 @@ func TestPurgeGuardSeesAnEnvironmentStore(t *testing.T) { |
| } |
| // No app store at all — only an environment one. |
| declareIn(t, s, "bab", "titogo", "beta", "TITO_S3") |
| - if _, err := GrantIn(ctx, s, p, testDeployment(), pub, "bab", "titogo", "beta", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| + if _, err := GrantIn(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "beta", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
| @@ -319,7 +319,7 @@ func TestGrantInPreservesAnOwnedEnvironment(t *testing.T) { |
| t.Fatal(err) |
| } |
| declareIn(t, s, "bab", "titogo", "team", "TITO_S3") |
| - if _, err := GrantIn(ctx, s, p, testDeployment(), pub, "bab", "titogo", "team", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| + if _, err := GrantIn(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "team", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
| m, _, found, err := appconfig.GetEnvironment(ctx, s, "bab", "titogo", "team") |
diff --git a/internal/objstore/walk_seed_test.go b/internal/objstore/walk_seed_test.go| index 38b03300e..952dc5e1c 100644 |
| --- a/internal/objstore/walk_seed_test.go |
| +++ b/internal/objstore/walk_seed_test.go |
| @@ -32,7 +32,7 @@ func TestFirstGrantClearsAnotherSeedsMark(t *testing.T) { |
| if _, err := PutIn(ctx, s, "bab", "shop", "canary", &Record{Declared: decl}, ""); err != nil { |
| t.Fatal(err) |
| } |
| - rec, err := GrantInFor(ctx, s, NewMemProvisioner("eu-west-1"), testDeployment(), pub, |
| + rec, err := GrantInFor(ctx, s, NewMemProvisioner("eu-west-1"), testDeployment(), storeTestSealer(pub, "bab", "shop"), |
| "bab", "shop", "canary", "op", GrantSourceOperator, "", c.grantFor, time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| @@ -74,11 +74,11 @@ func TestGrantRerunClearsAMarkThatIsNotItsOwn(t *testing.T) { |
| if _, err := PutIn(ctx, s, "bab", "shop", "canary", &Record{Declared: decl}, ""); err != nil { |
| t.Fatal(err) |
| } |
| - first, err := GrantInFor(ctx, s, p, testDeployment(), pub, "bab", "shop", "canary", "op", GrantSourceOperator, "", seedB, time.Now().UTC()) |
| + first, err := GrantInFor(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "shop"), "bab", "shop", "canary", "op", GrantSourceOperator, "", seedB, time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| - rec, err := GrantInFor(ctx, s, p, testDeployment(), pub, "bab", "shop", "canary", "op", GrantSourceOperator, "", c.rerunFor, time.Now().UTC()) |
| + rec, err := GrantInFor(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "shop"), "bab", "shop", "canary", "op", GrantSourceOperator, "", c.rerunFor, time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -109,7 +109,7 @@ func TestGrantLeavesAnUnmarkedDeclarationAsItWas(t *testing.T) { |
| t.Fatal(err) |
| } |
| before, _ := json.Marshal(decl) |
| - if _, err := GrantIn(ctx, s, NewMemProvisioner("eu-west-1"), testDeployment(), pub, "bab", "shop", "canary", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| + if _, err := GrantIn(ctx, s, NewMemProvisioner("eu-west-1"), testDeployment(), storeTestSealer(pub, "bab", "shop"), "bab", "shop", "canary", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
| raw, _, err := s.Get(ctx, KeyIn("bab", "shop", "canary")) |
diff --git a/internal/objstore/walk_test.go b/internal/objstore/walk_test.go| index ae143283c..2bf057e83 100644 |
| --- a/internal/objstore/walk_test.go |
| +++ b/internal/objstore/walk_test.go |
| @@ -34,6 +34,13 @@ func testSealKeypair(t *testing.T) (*ecdh.PrivateKey, *ecdh.PublicKey) { |
| return priv, pub |
| } |
| +// storeTestSealer is the sealer the walks now take (fleet secrets key, Task |
| +// 6): pub for acct/app, bound or not as the deployment switch says, which is |
| +// what appconfig.Seal chose before the walks took a sealer. |
| +func storeTestSealer(pub *ecdh.PublicKey, acct, app string) appconfig.Sealer { |
| + return appconfig.NewSealer(pub, appconfig.Binding{Account: acct, App: app}, appconfig.BoundSealing()) |
| +} |
| + |
| // failingStore fails the FIRST Put to failKeyOnce, then behaves normally — |
| // the crash between mint and delivery the walk has to repair. |
| type failingStore struct { |
| @@ -76,7 +83,7 @@ func TestGrantUndeclaredRefused(t *testing.T) { |
| s := release.NewDirStore(t.TempDir()) |
| _, pub := testSealKeypair(t) |
| p := NewMemProvisioner("eu-west-1") |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); !errors.Is(err, ErrNotDeclared) { |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); !errors.Is(err, ErrNotDeclared) { |
| t.Fatalf("Grant on undeclared app: %v, want ErrNotDeclared", err) |
| } |
| if len(p.Buckets) != 0 || len(p.Users) != 0 { |
| @@ -92,7 +99,7 @@ func TestGrantMintsAndDelivers(t *testing.T) { |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| now := time.Now().UTC() |
| - rec, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op@example.com", GrantSourceOperator, "", now) |
| + rec, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op@example.com", GrantSourceOperator, "", now) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -164,7 +171,7 @@ func TestGrantDeliversEndpointWhenSet(t *testing.T) { |
| d := testDeployment() |
| d.Endpoint = "https://s3.example.net" |
| - rec, err := Grant(ctx, s, p, d, pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + rec, err := Grant(ctx, s, p, d, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -184,7 +191,7 @@ func TestGrantAdoptsExistingBucket(t *testing.T) { |
| p := NewMemProvisioner("eu-west-1") |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - rec, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "titogo-uploads", time.Now().UTC()) |
| + rec, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "titogo-uploads", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -209,7 +216,7 @@ func TestGrantResumesAfterEachStepFailure(t *testing.T) { |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| p.FailNext[method] = errors.New("injected: " + method + " failed") |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); err == nil { |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); err == nil { |
| t.Fatalf("%s failure: Grant returned no error", method) |
| } |
| // The grant block is written before any backend call, so a |
| @@ -219,7 +226,7 @@ func TestGrantResumesAfterEachStepFailure(t *testing.T) { |
| t.Fatalf("record after %s failure = %+v, %v", method, half, err) |
| } |
| - rec, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + rec, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatalf("resume after %s failure: %v", method, err) |
| } |
| @@ -251,7 +258,7 @@ func TestGrantResumesAfterEachStepFailure(t *testing.T) { |
| p := NewMemProvisioner("eu-west-1") |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); err == nil { |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); err == nil { |
| t.Fatal("delivery failure: Grant returned no error") |
| } |
| // The record must NOT claim provisioned: the secret never landed. |
| @@ -259,7 +266,7 @@ func TestGrantResumesAfterEachStepFailure(t *testing.T) { |
| t.Fatalf("record after failed delivery = %+v, %v", rec, err) |
| } |
| - rec, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + rec, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatalf("resume after delivery failure: %v", err) |
| } |
| @@ -289,14 +296,14 @@ func TestGrantRerunKeepsBucketChoice(t *testing.T) { |
| p := NewMemProvisioner("eu-west-1") |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "titogo-uploads", time.Now().UTC()); err != nil { |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "titogo-uploads", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
| // Wipe delivery so the re-run walks the whole sequence again. |
| if _, err := appconfig.Apply(ctx, s, "bab", "titogo", nil, []string{"TITO_S3_BUCKET"}); err != nil { |
| t.Fatal(err) |
| } |
| - rec, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + rec, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -318,13 +325,13 @@ func TestGrantIdempotentWhenHealthy(t *testing.T) { |
| p := NewMemProvisioner("eu-west-1") |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - first, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + first, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| before := mustVars(t, s, "bab", "titogo") |
| - second, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC().Add(time.Hour)) |
| + second, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC().Add(time.Hour)) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -355,7 +362,7 @@ func TestGrantRepairsWrongKindVar(t *testing.T) { |
| p := NewMemProvisioner("eu-west-1") |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
| // Clobber the secret half with a plaintext env var of the same name. |
| @@ -380,7 +387,7 @@ func TestGrantRepairsWrongKindVar(t *testing.T) { |
| t.Fatalf("wrong-kind coordinate: missing = %v, %v", missing, err) |
| } |
| - rec, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + rec, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -440,7 +447,7 @@ func TestGrantRefusesInvalidBucketName(t *testing.T) { |
| p := NewMemProvisioner("eu-west-1") |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - _, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "Other-Bucket/*", time.Now().UTC()) |
| + _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "Other-Bucket/*", time.Now().UTC()) |
| if err == nil || !strings.Contains(err.Error(), "invalid bucket name") { |
| t.Fatalf("adopt of an invalid name: %v", err) |
| } |
| @@ -454,7 +461,7 @@ func TestGrantRefusesInvalidBucketName(t *testing.T) { |
| // A deployment whose prefix mints an illegal name is refused the same way. |
| d := testDeployment() |
| d.BucketPrefix = "Carlos_Store-" |
| - if _, err := Grant(ctx, s, p, d, pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); err == nil || |
| + if _, err := Grant(ctx, s, p, d, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); err == nil || |
| !strings.Contains(err.Error(), "invalid bucket name") { |
| t.Fatalf("minted invalid name: %v", err) |
| } |
| @@ -471,7 +478,7 @@ func TestGrantRefusesUnrenderableSecret(t *testing.T) { |
| p.MintSecret = "bad\"secret\nwith\\newline" |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - _, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err == nil { |
| t.Fatal("unrenderable secret was delivered") |
| } |
| @@ -489,7 +496,7 @@ func TestGrantRefusesUnrenderableSecret(t *testing.T) { |
| } |
| // The wasted key is collected by the next walk's reap. |
| p.MintSecret = "" |
| - rec, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + rec, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -509,7 +516,7 @@ func TestGrantUnsetsStaleEndpoint(t *testing.T) { |
| withEndpoint := testDeployment() |
| withEndpoint.Endpoint = "https://s3.example.net" |
| - if _, err := Grant(ctx, s, p, withEndpoint, pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| + if _, err := Grant(ctx, s, p, withEndpoint, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
| if _, ok := mustVars(t, s, "bab", "titogo")["TITO_S3_ENDPOINT"]; !ok { |
| @@ -517,7 +524,7 @@ func TestGrantUnsetsStaleEndpoint(t *testing.T) { |
| } |
| // Same app, deployment no longer has an endpoint: the record's endpoint no |
| // longer matches, so the walk must run rather than short-circuit. |
| - rec, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + rec, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -548,7 +555,7 @@ func TestEnvDeliveredReportsMissing(t *testing.T) { |
| } |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
| if missing, err = EnvDelivered(ctx, s, "bab", "titogo", "TITO_S3", false); err != nil || len(missing) != 0 { |
| @@ -573,7 +580,7 @@ func TestEnvDeliveredReportsMissing(t *testing.T) { |
| func rotateFixture(t *testing.T, s release.Store, pub *ecdh.PublicKey, p *MemProvisioner) *Record { |
| t.Helper() |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - rec, err := Grant(context.Background(), s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + rec, err := Grant(context.Background(), s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -607,7 +614,7 @@ func TestRotateKeepsOldKeyActive(t *testing.T) { |
| oldID := granted.Provisioned.KeyID |
| now := time.Now().UTC().Add(time.Hour) |
| - rec, err := Rotate(ctx, s, p, pub, "bab", "titogo", now) |
| + rec, err := Rotate(ctx, s, p, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", now) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -669,7 +676,7 @@ func TestRotateTwiceReapsPending(t *testing.T) { |
| first := rotateFixture(t, s, pub, p).Provisioned.KeyID |
| user := "carlos-store-bab-titogo" |
| - second, err := Rotate(ctx, s, p, pub, "bab", "titogo", time.Now().UTC()) |
| + second, err := Rotate(ctx, s, p, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -677,7 +684,7 @@ func TestRotateTwiceReapsPending(t *testing.T) { |
| t.Fatalf("keys after first rotate = %v", p.Users[user].Keys) |
| } |
| - third, err := Rotate(ctx, s, p, pub, "bab", "titogo", time.Now().UTC()) |
| + third, err := Rotate(ctx, s, p, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -715,7 +722,7 @@ func TestRotateResumesAfterResealFailure(t *testing.T) { |
| user := "carlos-store-bab-titogo" |
| s.failKeyOnce = appconfig.Key("bab", "titogo") |
| - if _, err := Rotate(ctx, s, p, pub, "bab", "titogo", time.Now().UTC()); err == nil { |
| + if _, err := Rotate(ctx, s, p, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", time.Now().UTC()); err == nil { |
| t.Fatal("reseal failure: Rotate returned no error") |
| } |
| // The record must still name the key the app is holding — the new one was |
| @@ -732,7 +739,7 @@ func TestRotateResumesAfterResealFailure(t *testing.T) { |
| t.Fatalf("failed rotate moved the app's key to %q, want %q", got, oldID) |
| } |
| - rec, err := Rotate(ctx, s, p, pub, "bab", "titogo", time.Now().UTC()) |
| + rec, err := Rotate(ctx, s, p, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", time.Now().UTC()) |
| if err != nil { |
| t.Fatalf("resume after reseal failure: %v", err) |
| } |
| @@ -765,7 +772,7 @@ func TestRotateFinishDeletesPrev(t *testing.T) { |
| oldID := rotateFixture(t, s, pub, p).Provisioned.KeyID |
| user := "carlos-store-bab-titogo" |
| - rotated, err := Rotate(ctx, s, p, pub, "bab", "titogo", time.Now().UTC()) |
| + rotated, err := Rotate(ctx, s, p, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -827,14 +834,14 @@ func TestRotateUnprovisionedRefused(t *testing.T) { |
| p := NewMemProvisioner("eu-west-1") |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - if _, err := Rotate(ctx, s, p, pub, "bab", "titogo", time.Now().UTC()); !errors.Is(err, ErrNotProvisioned) { |
| + if _, err := Rotate(ctx, s, p, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", time.Now().UTC()); !errors.Is(err, ErrNotProvisioned) { |
| t.Fatalf("Rotate on a declared-only store: %v, want ErrNotProvisioned", err) |
| } |
| if _, err := RotateFinish(ctx, s, p, "bab", "titogo"); !errors.Is(err, ErrNotProvisioned) { |
| t.Fatalf("RotateFinish on a declared-only store: %v, want ErrNotProvisioned", err) |
| } |
| // and on an app with no record at all |
| - if _, err := Rotate(ctx, s, p, pub, "bab", "nostore", time.Now().UTC()); !errors.Is(err, ErrNotProvisioned) { |
| + if _, err := Rotate(ctx, s, p, storeTestSealer(pub, "bab", "nostore"), "bab", "nostore", time.Now().UTC()); !errors.Is(err, ErrNotProvisioned) { |
| t.Fatalf("Rotate on a store-less app: %v, want ErrNotProvisioned", err) |
| } |
| if _, err := RotateFinish(ctx, s, p, "bab", "nostore"); !errors.Is(err, ErrNotProvisioned) { |
| @@ -862,7 +869,7 @@ func TestRotateKeepsRecordedCoordinates(t *testing.T) { |
| d := testDeployment() |
| d.Endpoint = "https://s3.example.net" |
| - granted, err := Grant(ctx, s, p, d, pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + granted, err := Grant(ctx, s, p, d, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -872,7 +879,7 @@ func TestRotateKeepsRecordedCoordinates(t *testing.T) { |
| // Rotate takes no Deployment: the only source for these values is the |
| // record, so this is the assertion that it reads them from there. |
| - rec, err := Rotate(ctx, s, p, pub, "bab", "titogo", time.Now().UTC()) |
| + rec, err := Rotate(ctx, s, p, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -942,7 +949,7 @@ func TestRotateRetriesLostCAS(t *testing.T) { |
| } |
| } |
| - rec, err := Rotate(ctx, s, p, pub, "bab", "titogo", time.Now().UTC()) |
| + rec, err := Rotate(ctx, s, p, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", time.Now().UTC()) |
| if err != nil { |
| t.Fatalf("rotate lost its CAS and gave up: %v", err) |
| } |
| @@ -987,7 +994,7 @@ func TestRotateRefusesRetryAgainstAnotherRotation(t *testing.T) { |
| } |
| } |
| - if _, err := Rotate(ctx, s, p, pub, "bab", "titogo", time.Now().UTC()); !errors.Is(err, release.ErrCASConflict) { |
| + if _, err := Rotate(ctx, s, p, storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", time.Now().UTC()); !errors.Is(err, release.ErrCASConflict) { |
| t.Fatalf("rotate over a concurrent rotation: %v, want ErrCASConflict", err) |
| } |
| stored, _, err := Get(ctx, s, "bab", "titogo") |
| @@ -1001,7 +1008,7 @@ func TestRotateRefusesRetryAgainstAnotherRotation(t *testing.T) { |
| func teardownFixture(t *testing.T, s release.Store, pub *ecdh.PublicKey, p *MemProvisioner) *Record { |
| t.Helper() |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - rec, err := Grant(context.Background(), s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + rec, err := Grant(context.Background(), s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| } |
| @@ -1419,7 +1426,7 @@ func TestGrantRecordsItsSource(t *testing.T) { |
| p := NewMemProvisioner("eu-west-1") |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - rec, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", |
| + rec, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", |
| "op@example.com", GrantSourceAccountApproval, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| @@ -1446,12 +1453,12 @@ func TestGrantDoesNotRestateSourceOnRerun(t *testing.T) { |
| p := NewMemProvisioner("eu-west-1") |
| declare(t, s, "bab", "titogo", "TITO_S3") |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", |
| "op@example.com", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
| // Re-run claiming a different authority; the first one must stand. |
| - rec, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", |
| + rec, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", |
| "someone@example.com", GrantSourceAccountApproval, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatal(err) |
| @@ -1514,7 +1521,7 @@ func TestGrantRetriesLostCAS(t *testing.T) { |
| } |
| } |
| - rec, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| + rec, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()) |
| if err != nil { |
| t.Fatalf("grant lost its CAS and gave up: %v", err) |
| } |
| @@ -1564,7 +1571,7 @@ func TestGrantRefusesRetryAgainstAnotherProvision(t *testing.T) { |
| } |
| } |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); !errors.Is(err, release.ErrCASConflict) { |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op", GrantSourceOperator, "", time.Now().UTC()); !errors.Is(err, release.ErrCASConflict) { |
| t.Fatalf("grant over a concurrent grant: %v, want ErrCASConflict", err) |
| } |
| stored, _, err := Get(ctx, s, "bab", "titogo") |
diff --git a/internal/objstore/writesdenied_test.go b/internal/objstore/writesdenied_test.go| index ce953be2d..fc8fdd972 100644 |
| --- a/internal/objstore/writesdenied_test.go |
| +++ b/internal/objstore/writesdenied_test.go |
| @@ -65,7 +65,7 @@ func TestGrantWritesTheWriteDeny(t *testing.T) { |
| if _, err := SetWritesDenied(ctx, s, "bab", "titogo", "", &WritesDenied{Reason: "plan storage", At: time.Now().UTC()}); err != nil { |
| t.Fatal(err) |
| } |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op@example.com", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op@example.com", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
| if writeDenyOf(t, p.PolicyFor(user)) == nil { |
| @@ -74,7 +74,7 @@ func TestGrantWritesTheWriteDeny(t *testing.T) { |
| if _, err := SetWritesDenied(ctx, s, "bab", "titogo", "", nil); err != nil { |
| t.Fatal(err) |
| } |
| - if _, err := Grant(ctx, s, p, testDeployment(), pub, "bab", "titogo", "op@example.com", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "titogo"), "bab", "titogo", "op@example.com", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| t.Fatal(err) |
| } |
| if writeDenyOf(t, p.PolicyFor(user)) != nil { |