carlos / platform Public

platform accounts: bind mints to the live secret, runbook owner, copy

- A per-customer mint now carries the hash of the secret its platform
  credential authenticated with, and the insert transaction requires
  the minter's row to hold it still: a mint paused across a rotation
  is refused and writes nothing (final re-review, Astra). The paused
  mint witness gains a rotate case; revoke was already refused.
- Runbook: a rebuilt manifest for an account with no platform carries
  its first owner from memberships; with none, the operator stops.
- Luna's approved runbook text and ttl line applied verbatim; the held
  log line now reads as the runbook quotes it. Copy table rows and
  approved-copy pins added.
- staticcheck SA4006: the early plan check only refuses.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c067c78c5b26bc861c2c73003ffb71ab04a353ba parent cd3a836
7 files changed, +105 −30
  • approved_platform_accounts_copy_test.go +16 −1
  • docs/site/cli.md +20 −10
  • docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md +15 −1
  • internal/console/apiplatformcredentials.go +6 −1
  • internal/console/apiplatformcustomers.go +8 −5
  • internal/console/platform_credentials.go +18 −9
  • internal/console/platform_credentials_test.go +22 −3

CI cancelled — superseded by a newer push — run details

diff --git a/approved_platform_accounts_copy_test.go b/approved_platform_accounts_copy_test.go
index 8bca5b047..180dd31ef 100644
--- a/approved_platform_accounts_copy_test.go
+++ b/approved_platform_accounts_copy_test.go
@@ -158,7 +158,22 @@ func TestApprovedPlatformAccountsCopy(t *testing.T) {
{"docs.platform_customers.ref", "docs/site/cli.md", "`--ref` is your own id for the customer. Creating again with the same ref returns the same account."},
{"docs.platform_customers_retry", "docs/site/cli.md", "Without `--ref`, a create retried after a timeout can make a second account, so pass `--ref` when your server retries."},
{"docs.platform_credentials", "docs/site/cli.md", "Mints a short-lived credential for one customer account, for deploying into it."},
- {"docs.platform_credentials.ttl", "docs/site/cli.md", "It lasts an hour unless you pass `--ttl`, up to 24 hours. It works only in that one account, and stops working when the platform’s access is turned off. Use it as `CARLOS_SERVICE_TOKEN`."},
+ {"docs.platform_credentials.ttl", "docs/site/cli.md", "It lasts an hour unless you pass `--ttl`, up to 24 hours. It works only in that one account. It stops working when the platform’s access is turned off, or when the platform credential that minted it is revoked or rotated. Use it as `CARLOS_SERVICE_TOKEN`."},
+ {"docs.held_promise.heading", "docs/site/cli.md", "#### A customer create that stays pending"},
+ {"docs.held_promise", "docs/site/cli.md", "When a platform creates a customer account, the console first records a promise for the account. The promise holds the customer’s ref and a place in `--max-customers`. The console then writes the account to the deployment bucket and records it in the database. If the bucket and database disagree, the console stops the create and keeps the promise. Nothing else is written until an operator repairs the mismatch."},
+ {"docs.held_promise.log_intro", "docs/site/cli.md", "While a promise is held, the console logs this line for every request from the platform:"},
+ {"docs.held_promise.scope", "docs/site/cli.md", "Only that platform’s create requests are affected. It can still list customers, update them and use its credentials. A create for the held ref fails. If the reason is `is in this console with no manifest in the bucket`, every create on that platform fails because the bucket gives each new create the same id. The promise counts towards `--max-customers` until it is repaired."},
+ {"docs.held_promise.read", "docs/site/cli.md", "Read the promise and account from the console’s database first:"},
+ {"docs.held_promise.manifest_key", "docs/site/cli.md", "The account’s manifest is `accounts/<sqid>/account.json` in the deployment bucket."},
+ {"docs.held_promise.no_manifest", "docs/site/cli.md", "**The account has no manifest, or the create’s manifest is at its id.** The reason is `is in this console with no manifest in the bucket` or `is another account in this console`. Check that the manifest is missing, or that its `platform_mint` is the mint id and the account row’s `platform_mint` is not the mint id. Then restore the account’s manifest. Write `accounts/<sqid>/account.json` from the row: `id`, `sqid`, `name` and `created_at` as an RFC 3339 UTC time. Add `platform`, `platform_ref` and `platform_mint` when the row has them. Add `deleted_at` as an RFC 3339 UTC time when the row’s value is not 0."},
+ {"docs.held_promise.owner", "docs/site/cli.md", "If the row has no `platform`, also add `owner`: the account’s first owner, from the console’s memberships table. Find it with this query:"},
+ {"docs.held_promise.owner_stop", "docs/site/cli.md", "If the query returns no address, stop and escalate. Do not write the manifest: a rebuilt console would give the account no owner. A customer account with a `platform` has no owner until someone claims it, so leave `owner` out for it."},
+ {"docs.held_promise.no_manifest_end", "docs/site/cli.md", "This replaces the create’s manifest if one is present. The platform’s next request creates the customer with a new id."},
+ {"docs.held_promise.ref", "docs/site/cli.md", "**Another live customer holds the ref.** The reason starts with `holds ref` or `would take ref`. Check which account holds it:"},
+ {"docs.held_promise.ref_repair", "docs/site/cli.md", "If it is the customer the platform intended, the promise is stale. Search the bucket’s account manifests for `\"platform_mint\":\"<mint id>\"`. If one has that value, add `deleted_at` with the current UTC time. Do not delete the manifest: an account id is never given out twice. Then remove the promise:"},
+ {"docs.held_promise.done", "docs/site/cli.md", "After the repair, the log line stops, and `carlos platform customers list --platform <platform>` shows the expected count."},
+ {"docs.held_promise.log_line", "docs/site/cli.md", "console: platform <platform>: pending customer create <mint id> held for account <id>: <reason>; repair the bucket or console"},
+ {"log.held_promise", "internal/console/apiplatformcustomers.go", "console: platform %s: pending customer create %s held for account %d: %s; repair the bucket or console"},
}
for _, row := range rows {
t.Run(row.key, func(t *testing.T) {
diff --git a/docs/site/cli.md b/docs/site/cli.md
index df0e02a33..bc3e21af9 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -2642,17 +2642,17 @@ Turning platform access off stops the platform’s credentials at once. Its cust
#### A customer create that stays pending
-When a platform creates a customer account, the console first records a promise for it. The promise holds the customer’s ref and a place in `--max-customers`. The console then writes the account to the deployment bucket and records it in its database. If the bucket and the database disagree about that account, the console stops and keeps the promise. This is a held promise. Nothing more is written for it until an operator repairs it.
+When a platform creates a customer account, the console first records a promise for the account. The promise holds the customer’s ref and a place in `--max-customers`. The console then writes the account to the deployment bucket and records it in the database. If the bucket and database disagree, the console stops the create and keeps the promise. Nothing else is written until an operator repairs the mismatch.
-While a promise is held, the console logs this line on every request the platform makes:
+While a promise is held, the console logs this line for every request from the platform:
```text
-console: platform <platform>: pending customer create <mint id> held: account <id> <reason>; it stays pending, holding its ref, until an operator repairs the bucket or the console
+console: platform <platform>: pending customer create <mint id> held for account <id>: <reason>; repair the bucket or console
```
-Only that platform is affected, and only its creates. Its customer list, updates and credentials keep working. A create for the held ref fails. When the reason is `is in this console with no manifest in the bucket`, every create on that platform fails, because the bucket offers each new create the same id. The promise counts towards `--max-customers` until it is repaired.
+Only that platform’s create requests are affected. It can still list customers, update them and use its credentials. A create for the held ref fails. If the reason is `is in this console with no manifest in the bucket`, every create on that platform fails because the bucket gives each new create the same id. The promise counts towards `--max-customers` until it is repaired.
-First read the promise and the account in the console’s database:
+Read the promise and account from the console’s database first:
```text
SELECT mint_id, platform, ref, name FROM platform_pending_mints WHERE mint_id = '<mint id>';
@@ -2661,21 +2661,31 @@ SELECT id, sqid, name, created_at, platform, platform_ref, platform_mint, delete
The account’s manifest is `accounts/<sqid>/account.json` in the deployment bucket.
-**The account has no manifest, or the create’s manifest sits at its id.** The reason is `is in this console with no manifest in the bucket` or `is another account in this console`. Check that the manifest is missing, or that its `platform_mint` is the mint id and the account row’s is not. Then give the account its manifest back. Write `accounts/<sqid>/account.json` from the row: `id`, `sqid`, `name`, and `created_at` as an RFC 3339 UTC time. Add `platform`, `platform_ref` and `platform_mint` when the row has them, and `deleted_at`, also as an RFC 3339 UTC time, when the row’s is not 0. This replaces the create’s manifest if one is there. The platform’s next request creates the customer at a new id.
+**The account has no manifest, or the create’s manifest is at its id.** The reason is `is in this console with no manifest in the bucket` or `is another account in this console`. Check that the manifest is missing, or that its `platform_mint` is the mint id and the account row’s `platform_mint` is not the mint id. Then restore the account’s manifest. Write `accounts/<sqid>/account.json` from the row: `id`, `sqid`, `name` and `created_at` as an RFC 3339 UTC time. Add `platform`, `platform_ref` and `platform_mint` when the row has them. Add `deleted_at` as an RFC 3339 UTC time when the row’s value is not 0.
-**Another live customer holds the ref.** The reason starts `holds ref` or `would take ref`. Check which account holds it:
+If the row has no `platform`, also add `owner`: the account’s first owner, from the console’s memberships table. Find it with this query:
+
+```text
+SELECT address FROM memberships WHERE account_id = <id> AND role = 'owner' ORDER BY added_at, address LIMIT 1;
+```
+
+If the query returns no address, stop and escalate. Do not write the manifest: a rebuilt console would give the account no owner. A customer account with a `platform` has no owner until someone claims it, so leave `owner` out for it.
+
+This replaces the create’s manifest if one is present. The platform’s next request creates the customer with a new id.
+
+**Another live customer holds the ref.** The reason starts with `holds ref` or `would take ref`. Check which account holds it:
```text
SELECT id, sqid, name, platform_mint FROM accounts WHERE platform = '<platform>' AND platform_ref = '<ref>' AND deleted_at = 0;
```
-If that is the customer the platform meant, the promise is a stray. Search the bucket’s account manifests for `"platform_mint":"<mint id>"`. If one carries it, add `deleted_at` with the current UTC time to it. Don’t delete it: an account id is never given out twice. Then remove the promise:
+If it is the customer the platform intended, the promise is stale. Search the bucket’s account manifests for `"platform_mint":"<mint id>"`. If one has that value, add `deleted_at` with the current UTC time. Do not delete the manifest: an account id is never given out twice. Then remove the promise:
```text
DELETE FROM platform_pending_mints WHERE mint_id = '<mint id>';
```
-After either repair the log line stops, and `carlos platform customers list --platform <platform>` shows the count you expect.
+After the repair, the log line stops, and `carlos platform customers list --platform <platform>` shows the expected count.
### carlos accounts subdomain
@@ -2946,7 +2956,7 @@ Mints a short-lived credential for one customer account, for deploying into it.
carlos platform credentials mint --platform bcd --customer bdf --json
```
-It lasts an hour unless you pass `--ttl`, up to 24 hours. It works only in that one account, and stops working when the platform’s access is turned off. Use it as `CARLOS_SERVICE_TOKEN`.
+It lasts an hour unless you pass `--ttl`, up to 24 hours. It works only in that one account. It stops working when the platform’s access is turned off, or when the platform credential that minted it is revoked or rotated. Use it as `CARLOS_SERVICE_TOKEN`.
### carlos add
diff --git a/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md b/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md
index fcb07023f..97f891895 100644
--- a/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md
+++ b/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md
@@ -1389,9 +1389,23 @@ Cap names in usage reuse the approved `cliPlanCopyLimit*` labels (apps and insta
|---|---|---|
| docs.accounts_platform | `### carlos accounts platform`, then: Shows an account’s platform grant, or changes it. A platform account can create customer accounts and deploy into them for its own customers. It is a deployment-operator command. Then the three examples: show, `--grant --max-customers 50 --plans free,personal --default-plan free --reason "agreed by email"`, `--revoke --reason "..."`. Then: "Turning platform access off stops the platform’s credentials at once. Its customers’ sites keep serving." | approved |
| docs.platform_customers | `### carlos platform customers`, then: Creates and manages the customer accounts a platform account runs. Each customer account is a full account of its own, with nobody signed in to it. Examples with `--platform bcd`: create `--name shop --ref 4812`, list, show `--ref 4812`, update `--customer bdf --plan personal`. Then: "`--ref` is your own id for the customer. Creating again with the same ref returns the same account." | approved |
-| docs.platform_credentials | `### carlos platform credentials`, then: Mints a short-lived credential for one customer account, for deploying into it. Example: `carlos platform credentials mint --platform bcd --customer bdf --json`. Then: "It lasts an hour unless you pass `--ttl`, up to 24 hours. It works only in that one account, and stops working when the platform’s access is turned off. Use it as `CARLOS_SERVICE_TOKEN`." | approved |
+| docs.platform_credentials | `### carlos platform credentials`, then: Mints a short-lived credential for one customer account, for deploying into it. Example: `carlos platform credentials mint --platform bcd --customer bdf --json`. Then: "It lasts an hour unless you pass `--ttl`, up to 24 hours. It works only in that one account. It stops working when the platform’s access is turned off, or when the platform credential that minted it is revoked or rotated. Use it as `CARLOS_SERVICE_TOKEN`." (final fix wave: revoke and rotate of the minting credential added) | approved (Luna pass 2026-11-19) |
| docs.platform | `### carlos platform` (required by `internal/docsite`'s one-heading-per-top-level-command gate; Task 11 added it and moved the customers and credentials headings under it to `####`), then: "Runs customer accounts from a platform account: `customers` creates and manages them, and `credentials` mints a credential for deploying into one." | approved |
| docs.platform_customers_retry | Appended to docs.platform_customers by Task 11: "Without `--ref`, a create retried after a timeout can make a second account, so pass `--ref` when your server retries." | approved |
+| docs.held_promise.heading | `#### A customer create that stays pending`, under `### carlos accounts platform` (final fix wave, held-promise runbook) | approved (Luna pass 2026-11-19) |
+| docs.held_promise | When a platform creates a customer account, the console first records a promise for the account. The promise holds the customer’s ref and a place in `--max-customers`. The console then writes the account to the deployment bucket and records it in the database. If the bucket and database disagree, the console stops the create and keeps the promise. Nothing else is written until an operator repairs the mismatch. | approved (Luna pass 2026-11-19) |
+| docs.held_promise.log_intro | While a promise is held, the console logs this line for every request from the platform: | approved (Luna pass 2026-11-19) |
+| docs.held_promise.scope | Only that platform’s create requests are affected. It can still list customers, update them and use its credentials. A create for the held ref fails. If the reason is `is in this console with no manifest in the bucket`, every create on that platform fails because the bucket gives each new create the same id. The promise counts towards `--max-customers` until it is repaired. | approved (Luna pass 2026-11-19) |
+| docs.held_promise.read | Read the promise and account from the console’s database first: | approved (Luna pass 2026-11-19) |
+| docs.held_promise.manifest_key | The account’s manifest is `accounts/<sqid>/account.json` in the deployment bucket. | approved (Luna pass 2026-11-19) |
+| docs.held_promise.no_manifest | **The account has no manifest, or the create’s manifest is at its id.** The reason is `is in this console with no manifest in the bucket` or `is another account in this console`. Check that the manifest is missing, or that its `platform_mint` is the mint id and the account row’s `platform_mint` is not the mint id. Then restore the account’s manifest. Write `accounts/<sqid>/account.json` from the row: `id`, `sqid`, `name` and `created_at` as an RFC 3339 UTC time. Add `platform`, `platform_ref` and `platform_mint` when the row has them. Add `deleted_at` as an RFC 3339 UTC time when the row’s value is not 0. | approved (Luna pass 2026-11-19) |
+| docs.held_promise.owner | If the row has no `platform`, also add `owner`: the account’s first owner, from the console’s memberships table. Find it with this query: | approved (Luna pass 2026-11-19; the owner step was added by the fix wave in the same voice, after the pass) |
+| docs.held_promise.owner_stop | If the query returns no address, stop and escalate. Do not write the manifest: a rebuilt console would give the account no owner. A customer account with a `platform` has no owner until someone claims it, so leave `owner` out for it. | approved (Luna pass 2026-11-19; the owner step was added by the fix wave in the same voice, after the pass) |
+| docs.held_promise.no_manifest_end | This replaces the create’s manifest if one is present. The platform’s next request creates the customer with a new id. | approved (Luna pass 2026-11-19) |
+| docs.held_promise.ref | **Another live customer holds the ref.** The reason starts with `holds ref` or `would take ref`. Check which account holds it: | approved (Luna pass 2026-11-19) |
+| docs.held_promise.ref_repair | If it is the customer the platform intended, the promise is stale. Search the bucket’s account manifests for `"platform_mint":"<mint id>"`. If one has that value, add `deleted_at` with the current UTC time. Do not delete the manifest: an account id is never given out twice. Then remove the promise: | approved (Luna pass 2026-11-19) |
+| docs.held_promise.done | After the repair, the log line stops, and `carlos platform customers list --platform <platform>` shows the expected count. | approved (Luna pass 2026-11-19) |
+| log.held_promise | Operator log line, `internal/console/apiplatformcustomers.go` (`held`), quoted by the runbook: `console: platform %s: pending customer create %s held for account %d: %s; repair the bucket or console` | approved (Luna pass 2026-11-19) |
**Task 15 (copy review, Luna pass + Paul 2026-11-19).** Paul approved Luna's rows as written except four, which carry his text: `delete.platform_has_customers` (no count), `audit.revoke`, `Minted` (split into `MintedPublish` and `MintedDeploy`, with `audit.credential` split the same way into `audit.credential_publish` and `audit.credential_deploy`: publish names the customer, deploy names the app in the customer), and `email.lapse_grace` for a platform's owners (new `email.platform.lapse_grace`: the approved `email.lapse_grace` without "unless you choose what stays", which only the customer's own owners can act on; the ordinary owner email keeps `email.lapse_grace`). Task 15 also added `list.failed` and `show.failed`, the read doors' own failure rows for a store error (500), in Paul's wording.
diff --git a/internal/console/apiplatformcredentials.go b/internal/console/apiplatformcredentials.go
index e5e26b38b..aa6e306c2 100644
--- a/internal/console/apiplatformcredentials.go
+++ b/internal/console/apiplatformcredentials.go
@@ -105,12 +105,17 @@ func (s *Server) handlePlatformCredentialMint(w http.ResponseWriter, r *http.Req
}
name := c.P.Name
+ minterHash := ""
if c.P.Kind == PrincipalUser {
name = c.P.Address
+ } else {
+ // The secret this request authenticated with: the mint commits
+ // only while the minter's row still holds it (platformMinterHolds).
+ minterHash = hashToken(bearer(r))
}
raw, expires, err := s.store.NewPlatformCustomerCredential(ctx, PlatformCredentialRequest{
CustomerID: cust.ID, PlatformAccountID: c.Platform.ID, Generation: c.Grant.Generation, Minter: c.P,
- Name: name, MintedBy: c.Actor, Role: role, App: app, Rungs: req.Rungs, TTL: ttl,
+ Name: name, MintedBy: c.Actor, Role: role, App: app, Rungs: req.Rungs, TTL: ttl, MinterTokenHash: minterHash,
}, time.Now())
if err != nil {
s.platformCredentialRefused(w, r, c, err)
diff --git a/internal/console/apiplatformcustomers.go b/internal/console/apiplatformcustomers.go
index 7176042d0..b6a92a766 100644
--- a/internal/console/apiplatformcustomers.go
+++ b/internal/console/apiplatformcustomers.go
@@ -416,8 +416,9 @@ func (s *Server) handlePlatformCustomerCreate(w http.ResponseWriter, r *http.Req
jsonError(w, http.StatusBadRequest, platformCopy["create.ref"])
return
}
- plan, refusal := s.platformCreatePlan(c.Grant, req.Plan)
- if refusal != "" {
+ // The plan itself is taken again under the lock, from the grant as it
+ // stands then; this early pass only refuses.
+ if _, refusal := s.platformCreatePlan(c.Grant, req.Plan); refusal != "" {
jsonError(w, http.StatusBadRequest, refusal)
return
}
@@ -457,7 +458,8 @@ func (s *Server) handlePlatformCustomerCreate(w http.ResponseWriter, r *http.Req
s.platformDoorFailed(w, c)
return
}
- if plan, refusal = s.platformCreatePlan(grant, req.Plan); refusal != "" {
+ plan, refusal := s.platformCreatePlan(grant, req.Plan)
+ if refusal != "" {
jsonError(w, http.StatusBadRequest, refusal)
return
}
@@ -686,8 +688,9 @@ func (s *Server) finishPlatformMint(ctx context.Context, platform *Account, m Pe
return nil, fmt.Errorf("pending customer create %s: no deployment bucket", m.MintID)
}
held := func(id int64, written bool, reason string) error {
- log.Printf("console: platform %s: pending customer create %s held: account %d %s; it stays pending, "+
- "holding its ref, until an operator repairs the bucket or the console", platform.Sqid, m.MintID, id, reason)
+ // The operator's line, as docs/site/cli.md quotes it (approved copy).
+ log.Printf("console: platform %s: pending customer create %s held for account %d: %s; repair the bucket or console",
+ platform.Sqid, m.MintID, id, reason)
err := fmt.Errorf("%w: mint %s, account %d: %s", errPlatformMintHeld, m.MintID, id, reason)
if !written {
err = fmt.Errorf("%w (%w)", err, errMintNotWritten)
diff --git a/internal/console/platform_credentials.go b/internal/console/platform_credentials.go
index 983da29e2..21c57b492 100644
--- a/internal/console/platform_credentials.go
+++ b/internal/console/platform_credentials.go
@@ -63,6 +63,12 @@ type PlatformCredentialRequest struct {
App string
Rungs []string
TTL time.Duration // 0 means PlatformCredentialDefaultTTL
+
+ // MinterTokenHash is the hash of the secret a service minter
+ // authenticated with (hashToken of its bearer). The insert transaction
+ // requires its row to hold that hash still, so a mint admitted before
+ // a rotation cannot commit after it. A person minter leaves it "".
+ MinterTokenHash string
}
// platformCredentialShape checks a per-customer credential's role, app,
@@ -109,8 +115,9 @@ func platformCredentialShape(role svcrole.Role, app string, rungs []string, ttl
// checked inside the insert transaction (Astra r1-2): the customer's link to
// the platform under req.Generation (platformLinkLive), and the minter's own
// authority under it, a service minter's platform credential still
-// unrevoked at that generation, or a person still an owner of the platform
-// account. Any of those gone is ErrPlatformAuthorityEnded, and nothing is
+// unrevoked at that generation and unrotated since the request
+// authenticated (req.MinterTokenHash), or a person still an owner of the
+// platform account. Any of those gone is ErrPlatformAuthorityEnded, and nothing is
// written.
//
// A Deploy credential names an app, so under the host-claim gate its row
@@ -190,21 +197,23 @@ VALUES (?, ?, '', '', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '', '', ?, ?)`,
// platformMinterHolds reports whether the minter still holds the authority
// it was admitted with, read in the mint's transaction: a service minter's
// own row (by credential id) is a live platform credential of this platform
-// at req.Generation; a person is an owner of the platform account. Any
-// other principal holds nothing.
+// at req.Generation, and still holds the secret the request authenticated
+// with (req.MinterTokenHash: a rotation replaces it, a revoke sets
+// revoked_at, and either ends the mint); a person is an owner of the
+// platform account. Any other principal holds nothing.
func platformMinterHolds(ctx context.Context, tx *sql.Tx, req PlatformCredentialRequest, now time.Time) (bool, error) {
var one int
var err error
switch req.Minter.Kind {
case PrincipalService:
- if req.Minter.CredentialID == "" {
+ if req.Minter.CredentialID == "" || req.MinterTokenHash == "" {
return false, nil
}
- err = tx.QueryRowContext(ctx, `SELECT 1 FROM cli_tokens WHERE credential_id = ? AND kind = ? AND role = ?
- AND account_id = ? AND platform_account_id = ? AND platform_generation = ? AND revoked_at = 0
+ err = tx.QueryRowContext(ctx, `SELECT 1 FROM cli_tokens WHERE credential_id = ? AND token_hash = ? AND kind = ?
+ AND role = ? AND account_id = ? AND platform_account_id = ? AND platform_generation = ? AND revoked_at = 0
AND (expires_at = 0 OR expires_at >= ?)`,
- req.Minter.CredentialID, cliKindService, string(svcrole.Platform), req.PlatformAccountID, req.PlatformAccountID,
- req.Generation, now.Unix()).Scan(&one)
+ req.Minter.CredentialID, req.MinterTokenHash, cliKindService, string(svcrole.Platform), req.PlatformAccountID,
+ req.PlatformAccountID, req.Generation, now.Unix()).Scan(&one)
case PrincipalUser:
if req.Minter.Address == "" {
return false, nil
diff --git a/internal/console/platform_credentials_test.go b/internal/console/platform_credentials_test.go
index ef1c17a91..17483dfa0 100644
--- a/internal/console/platform_credentials_test.go
+++ b/internal/console/platform_credentials_test.go
@@ -687,6 +687,25 @@ func TestCustomerCredentialMintPausedAcrossRevokeAndRegrant(t *testing.T) {
})
wantNone("platform credential revoked during the mint", status, out)
+ // Only the minter's own credential rotated (final re-review, Astra):
+ // the credential id and the generation stay, but the secret the mint
+ // authenticated with is gone, so the mint is refused and writes nothing.
+ tok5 := platformToken(t, fx, p.ID, "cms-5")
+ var fresh string
+ status, out, _ = pausedMint(t, fx, set, p.Sqid, cust.Sqid, tok5, func() {
+ var err error
+ if fresh, err = fx.st.RotateServicePrincipal(p.ID, "cms-5", time.Now()); err != nil {
+ t.Error(err)
+ }
+ })
+ wantNone("platform credential rotated during the mint", status, out)
+ if status, _, raw := pausedMint(t, fx, set, p.Sqid, cust.Sqid, fresh, func() {}); status != http.StatusCreated {
+ t.Fatalf("mint with the rotated secret = %d %s, want 201", status, raw)
+ }
+ if n := customerCredentialRows(t, fx.st, cust.ID); n != 1 {
+ t.Fatalf("kind platform rows = %d, want only the rotated secret's mint", n)
+ }
+
// With nothing in the way, the same mint goes through.
tok4 := platformToken(t, fx, p.ID, "cms-4")
if status, _, raw := pausedMint(t, fx, set, p.Sqid, cust.Sqid, tok4, func() {}); status != http.StatusCreated {
@@ -981,7 +1000,7 @@ func TestCustomerCredentialUnderTheGateIsSweptByARevoke(t *testing.T) {
}
now := time.Now()
raw, _, err := s.NewPlatformCustomerCredential(ctx, PlatformCredentialRequest{CustomerID: gateAcct, PlatformAccountID: p,
- Generation: minter.PlatformGeneration, Minter: minter, Name: "cms", MintedBy: "service:bcd/cms", Role: svcrole.Deploy,
+ Generation: minter.PlatformGeneration, Minter: minter, MinterTokenHash: hashToken(platformTok), Name: "cms", MintedBy: "service:bcd/cms", Role: svcrole.Deploy,
App: "blog", Rungs: []string{"edge"}}, now)
if err != nil {
t.Fatalf("gated mint: %v", err)
@@ -1025,7 +1044,7 @@ func TestExpiredTokenSweepUnderTheGateGoesOnPastACustomerCredential(t *testing.T
}
now := time.Now()
deploy, _, err := s.NewPlatformCustomerCredential(ctx, PlatformCredentialRequest{CustomerID: gateAcct, PlatformAccountID: p,
- Generation: minter.PlatformGeneration, Minter: minter, Name: "cms", MintedBy: "service:bcd/cms", Role: svcrole.Deploy,
+ Generation: minter.PlatformGeneration, Minter: minter, MinterTokenHash: hashToken(platformTok), Name: "cms", MintedBy: "service:bcd/cms", Role: svcrole.Deploy,
App: "blog", Rungs: []string{"edge"}, TTL: PlatformCredentialMinTTL}, now)
if err != nil {
t.Fatalf("gated mint: %v", err)
@@ -1076,7 +1095,7 @@ func TestRevokingAPlatformCredentialUnderTheGateEndsItsDeployMints(t *testing.T)
}
now := time.Now()
raw, _, err := s.NewPlatformCustomerCredential(ctx, PlatformCredentialRequest{CustomerID: gateAcct, PlatformAccountID: p,
- Generation: minter.PlatformGeneration, Minter: minter, Name: "cms", MintedBy: "service:bcd/cms", Role: svcrole.Deploy,
+ Generation: minter.PlatformGeneration, Minter: minter, MinterTokenHash: hashToken(platformTok), Name: "cms", MintedBy: "service:bcd/cms", Role: svcrole.Deploy,
App: "blog", Rungs: []string{"edge"}}, now)
if err != nil {
t.Fatalf("gated mint: %v", err)