Skip to content

safekeys/capability-token [built] ​

The capability token is the only secret-bearing artefact an agent reasons about. A short-lived, scoped, audience-bound handle that contains zero secret material, it is safe to pass through prompts, memory, tool calls, and multi-agent buses where a value is not.

Status: built

Why this exists ​

Agents must be able to define, create, transport, and request use of secrets without ever receiving plaintext or long-term keys. A token decouples "the right to use a secret" from "the secret" itself, so authority can travel through untrusted channels — model context, logs, MCP buses — while the value cannot.

Design decisions ​

uri-form [accepted] ​

Decision: Express tokens as a URI: safekey://v1/<id>?scope=<action>&aud=<env>&exp=<unix>&kid=<key-id>

Rationale: A URI is copyable through any transport, self-describing, and easy to redact in logs by matching a prefix. It makes the token obviously a handle rather than a value.

short-ttl-over-long-lived [accepted] ​

Decision: Use short TTL plus a jti denylist rather than long-lived tokens with periodic rotation.

Rationale: Short TTL bounds the damage window of a leaked token; the denylist provides immediate revocation for the cases where waiting is unacceptable. Together they cover both the common and the urgent case.

generic-denials [accepted] ​

Decision: Denials return a generic failure rather than the specific violated check.

Rationale: Detailed denial reasons are a probing oracle for an attacker refining a forged token.

jws-over-query-string [accepted] ​

Decision: Carry the token as a standard RFC 7515 compact JWS in the URI fragment (safekey://v1/<sid>#<JWS>) rather than the blueprint's bespoke query-string claims with a separate sig claim.

Rationale: The blueprint's form is a bespoke signed-URL scheme: neither the canonicalisation of the signed bytes nor the parameter ordering/escaping is defined by any standard, so every implementation would have to reproduce our rules byte-for-byte and a mismatch in one language would be a silent authorisation bypass. JWS moves that risk into reviewed, widely implemented libraries. Decisively for this product, standardisation is what makes government-grade assurance reachable: FIPS 140-3 validated modules support EdDSA/ES256 but no private format, an auditor can verify RFC 7515 conformance quickly, third-party resolvers and HSMs interoperate on day one, and the format outlives the team. The blueprint's semantics (sid, scope, aud, exp, nbf, jti) are preserved exactly; only the signing envelope changes.

Alternatives considered:

  • Literal query-string form from the blueprint (safekey://v1/<id>?scope=…&aud=…&exp=…&kid=…&sig=…) — rejected: Bespoke signed-URL construction with no standard covering canonicalisation or signing rules — we would own a crypto-critical parsing and signing surface. No FIPS story, expensive to audit, and a canonicalisation mismatch between implementations is a silent auth bypass.
  • JWS carried as a query parameter rather than a fragment — rejected: Standard, but base64url-heavy JWS bloats the URL and risks truncation by intermediaries; the fragment also keeps the credential out of server logs and proxy records by construction.
  • Custom binary token format — rejected: Maximum control at maximum cost: no library support, no interoperability, and an entirely novel format to audit.

Consequences: One deliberate deviation from the blueprint's documented wire format, recorded as an ADR. Implementations must enforce the alg allowlist and kid resolution, which are header-level concerns not expressible in the claims schema. Format is frozen at v1 and additive-only.

Date: 2026-09-22

alg-allowlist [accepted] ​

Decision: Permit only EdDSA and ES256; reject alg 'none' and all symmetric algorithms (HS256/384/512).

Rationale: alg: none is the classic JWT attack, and accepting a symmetric algorithm lets a verifier be tricked into treating a published verification key as a shared secret (algorithm-confusion). A closed allowlist makes both classes of bug unreachable rather than merely discouraged. EdDSA is the modern default; ES256 is permitted for FIPS-oriented deployments.

Alternatives considered:

  • Trust the token's own alg header and verify accordingly — rejected: This is precisely the algorithm-confusion vulnerability — the attacker chooses the verification algorithm.
  • Accept any asymmetric algorithm — rejected: Unbounded risk surface, including weak or deprecated curves, with no way to reason about the whole set.

Consequences: Adding an algorithm is a new major format version. Header constraints are enforced by the verifier, not the claims schema, and are covered by header conformance vectors.

Date: 2026-09-22

key-custody-hsm [accepted] ​

Decision: Require the token signing key to be HSM- or secure-element-backed from Phase 1; never a bare file in production.

Rationale: The token format protects the authority of the signature, so the signature's key is the root of that authority. A key on disk is exfiltratable by the same host compromise the rest of the architecture is designed to survive. Custody is where government-grade assurance actually originates — algorithm choice, key custody, and sidecar enforcement — not the envelope encoding.

Consequences: kid resolution must support an HSM-backed key source. No format change; only where the key lives. Recorded so an integrator does not ship a file-based signing key in production.

Date: 2026-09-22

How it works ​

Mint a capability token (mint-token) ​

The control plane issues a signed token for a specific object, scope, and audience.

  1. Receive — Control plane receives an object id, requested scope, audience, and TTL from the sidecar.
  2. Validate — Policy is evaluated — is this requester allowed to mint this scope for this object and audience?
  3. Generate — Generate claims (sid, scope, aud, exp, nbf, jti) and sign with the active kid.
  4. Record — Persist the jti so it can be revoked and audited.
  5. Receive — Caller receives the token URI; no secret material is present in the response.

Verify a token at the sidecar (verify-token) ​

The sidecar is the only component that validates a token before resolving.

  1. Parse — Parse the safekey:// URI and extract the token and claims.
  2. Validate — Verify signature against the issuer's key (kid), then expiry (exp/nbf).
  3. Validate — Verify the audience matches this resolver/environment identity.
  4. Validate — Verify the requested operation is within the token's scope (least privilege).
  5. Validate — Check the jti against the revocation denylist.
  6. Observe — On any failure, deny by default without revealing why beyond a generic denial code.

Guarantees ​

token-contains-no-secrets ​

A capability token must never contain plaintext, key material, or anything that yields it.

Acceptance criteria:

  • [ ] Claims are limited to object identifier, scope, audience, time bounds, unique id, and signature
  • [ ] No field may carry the secret value, a DEK, or a KEK
  • [ ] A token captured from a prompt or log is not sufficient to decrypt a folder without a reachable sidecar and key authority

short-lived-and-scoped ​

Tokens are least-privilege and short-lived by construction.

Acceptance criteria:

  • [ ] TTL measured in minutes to hours, never days
  • [ ] scope is one of read, unwrap, inject-env, inject-file, sign
  • [ ] aud binds the token to an intended resolver identity or environment

revocable ​

Every token can be invalidated immediately, independent of its TTL.

Acceptance criteria:

  • [ ] A unique jti is issued and recorded at mint time
  • [ ] Revocation is enforced by a denylist checked on every resolve
  • [ ] Revocation takes effect without waiting for expiry

signature-verifiable ​

The sidecar can verify authenticity offline of the issuing control plane's authority.

Acceptance criteria:

  • [ ] Tokens are signed and carry a key id
  • [ ] Signature verification happens before any key-store interaction
  • [ ] An unverifiable token is denied

Test specifications ​

token-has-no-secret-material ​

Given:

  • secret_value: "super-secret-value"

When: mint-token

Then:

  • assertion: the minted token string does not contain the secret value in any encoding
  • assertion: decoding the token yields only the declared claims
  • assertion: no DEK or KEK identifier resolves to recoverable key bytes

Contracts verified: token-contains-no-secrets

expired-token-denied ​

Given:

  • ttl_seconds: 1
  • wait_seconds: 2

When: verify-token

Then:

  • assertion: resolution is denied with a generic denial
  • assertion: no key-store unwrap is attempted

Contracts verified: short-lived-and-scoped

wrong-audience-denied ​

Given:

  • aud: "env-production"
  • resolver_identity: "env-staging"

When: verify-token

Then:

  • assertion: resolution is denied
  • assertion: no plaintext is materialised

Contracts verified: short-lived-and-scoped

revoked-token-denied-immediately ​

Given:

  • revoke_before_use: true
  • ttl_seconds: 3600

When: verify-token

Then:

  • assertion: resolution is denied even though the token has not expired

Contracts verified: revocable

Implementation ​

  • Primary: pkg/protocol/token.go
  • Test code: pkg/protocol/protocol_test.go
  • Test code status: manual

See Also ​

  • safekeys/secret-transport
  • safekeys/token-revocation
  • safekeys/sidecar-resolution
  • safekeys/control-plane-db