Key management
ulex's cryptographic key hierarchy: the AWS KMS CMK, per-tenant data keys, token signing keys with overlapping rotation, SAML certificates, webhook secrets, API keys, and the exact procedure for every rotation.
Five kinds of key. Confusing them is how a rotation ends up breaking production.
| Kind | Where | Algorithm | Rotation | Who can trigger it |
|---|---|---|---|---|
| KMS CMK | AWS KMS | AES-256 | annual, or on exposure | break-glass, two approvals |
| Data key | generated per request | AES-256-GCM | every ≤ 60 s, transparently | nobody; it is automatic |
| Token signing key | signing_key rows | RS256 default, RS384/512, ES256/384, PS256, EdDSA | POST /tenants/current/rotate-signing-keys | ulex:admin |
| SAML certificate | signing_key, and each connection's x509_certificate | RSA-2048/4096, EC P-256/384 | with the IdP's schedule | write:connections |
| Webhook secret | webhook.secret_encrypted | HMAC-SHA256 | delete and recreate | write:webhooks |
#The KMS CMK
aws kms describe-key --key-id alias/ulex-tenant --region us-east-1{
"KeyMetadata": {
"KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab",
"Arn": "arn:aws:kms:us-east-1:111111111111:key/1234abcd-12ab-34cd-56ef-1234567890ab",
"KeyState": "Enabled",
"KeyUsage": "ENCRYPT_DECRYPT",
"CustomerMasterKeySpec": "SYMMETRIC_DEFAULT",
"KeyManager": "CUSTOMER",
"Origin": "AWS_KMS",
"MultiRegion": false,
"RotationEnabled": false
}
}| Property | Value |
|---|---|
KeyManager | CUSTOMER. AWS does not hold it; we do |
Origin | AWS_KMS, not an imported material. The key material never exists outside KMS in a way we can read |
| Policy | the data-plane role may GenerateDataKey and Decrypt; nobody may PutKeyPolicy, EnableKey, or ScheduleKeyDeletion |
| Deletion | ScheduleKeyDeletion is break-glass, two approvals, with a 30-day waiting period that only a second break-glass can cancel |
| Rotation | annual, in us-east-1 only. Rotating a CMK requires re-encrypting every secret under it, which is a maintenance window, not a button |
#Data keys
Per-request, per-secret, never persisted:
GenerateDataKey(CMK, KeySpec=AES_256)
→ Plaintext 4 KiB, used immediately, cached in the Lambda environment ≤ 60 s
→ CiphertextBlob stored in the DynamoDB attributeThe plaintext data key is never written to disk, never in a log line, never in an exception. It is cleared when the Lambda execution environment freezes.
The cost: one KMS call per secret read, amortised by the 60-second cache. ulex_kms_operations_total{operation="Decrypt"} is the metric; a step change there means a client is reading a secret on a hot path it should have cached.
#Token signing keys
#The hierarchy
{
"id": "key_01M3PSVJA0YP2WDPM2RDR15MGH",
"object": "signing_key",
"purpose": "access_token",
"algorithm": "RS256",
"kid": "key_01M3PSVJA0YP2WDPM2RDR15MGH",
"public_key_pem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkq…\n-----END PUBLIC KEY-----\n",
"private_key_encrypted": "AQICAHh…", // envelope-encrypted
"kms_key_arn": null, // or a CMK ARN instead of inline material
"state": "active",
"activated_at": "2026-03-11T00:00:00.000Z",
"expires_at": "2027-03-11T00:00:00.000Z",
"retired_at": null
}purpose | Signs |
|---|---|
access_token | access tokens and their JWT introspection |
id_token | ID tokens |
webhook | nothing today; reserved so a future signed-payload scheme is possible without a schema change |
saml_request | AuthnRequests ulex sends upstream |
saml_response | assertions and Responses ulex issues |
jwt_bearer | ulex-issued federated assertions |
algorithm defaults to RS256. ES256 and EdDSA are available per application.
#The JWKS
curl -sS "$BASE/oauth2/keys"{
"keys": [
{
"kty": "RSA",
"use": "sig",
"alg": "RS256",
"kid": "key_01M3PSVJA0YP2WDPM2RDR15MGH",
"n": "0vx7agoKGcRMgpjY4XqbJ7Xm3vJ7XQ…",
"e": "AQAB",
"x5c": ["MIIDQjCCAiqgAwIBAgIGATz/FuLiMA0GCSqGSIb3DQ…"],
"x5t": "MfKw2WL8iJ7YQ3n1bPqR0sA=="
}
]
}Public, unauthenticated, and unrate-limited. It must be, because every JWT library fetches it at startup.
#Rotating
curl -sS -X POST "$BASE/tenants/current/rotate-signing-keys" \
-H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"purpose":"access_token","grace_period_seconds":604800}'{
"rotated": true,
"purposes": ["access_token"],
"keys": [
{
"purpose": "access_token",
"new_key": { "id": "key_01M3PSX7B2KQ4V6W8Y0Z1A3B5C", "kid": "key_01M3PSX7B2KQ4V6W8Y0Z1A3B5C", "algorithm": "RS256", "state": "active" },
"previous_key": { "id": "key_01M3PSVJA0YP2WDPM2RDR15MGH", "kid": "key_01M3PSVJA0YP2WDPM2RDR15MGH", "state": "retiring" },
"grace_period_seconds": 604800,
"previous_key_revokes_at": "2026-10-06T15:02:11.000Z",
"jwks_url": "https://ulexid.com/api/v1/oauth2/keys"
}
],
"jwks_url": "https://ulexid.com/api/v1/oauth2/keys"
}The procedure.
Every JWKS consumer must be a kid-keyed map with a TTL. A consumer that pins one kid breaks the moment you rotate. Verify before you rotate, not after.
const cache = new Map<string, { key: JsonWebKey; expiresAt: number }>();
const TTL = 15 * 60_000;
async function keyFor(kid: string): Promise<JsonWebKey> {
const hit = cache.get(kid);
if (hit && hit.expiresAt > Date.now()) return hit.key;
const { keys } = await (await fetch(JWKS_URL)).json() as { keys: JsonWebKey[] };
// Do NOT clear first: in-flight tokens signed by the retiring key must keep
// verifying for the whole overlap.
for (const k of keys) cache.set(k.kid!, { key: k, expiresAt: Date.now() + TTL });
const found = cache.get(kid);
if (!found) throw new Error(`unknown kid ${kid}; JWKS has ${[...cache.keys()].join(", ")}`);
return found.key;
}A consumer that refetches on every verification will thrash during a rotation. One that caches for 24 hours will reject the new kid. The 15-minute TTL is the sweet spot.
| Longest consumer cache | Minimum grace |
|---|---|
| 15 minutes | 30 minutes |
| 1 hour | 2 hours |
| 6 hours | 12 hours |
| 24 hours | 48 hours |
604800 (7 days) is the default and is right for anything you do not control.
curl -sS "$BASE/oauth2/keys" | jq '.keys | length, map({kid, alg})'2
[{"kid":"key_01M3PSX7B2KQ4V6W8Y0Z1A3B5C","alg":"RS256"},
{"kid":"key_01M3PSVJA0YP2WDPM2RDR15MGH","alg":"RS256"}]ulex_jwks_unknown_kid_total should stay at zero. If it is not, a consumer is not caching and you need more grace.
At previous_key_revokes_at the retiring key moves to revoked and leaves the JWKS automatically. Nothing to do.
#On compromise
If a signing key is exposed, the grace window is a liability. Use the minimum that lets caches refresh:
curl -sS -X POST "$BASE/tenants/current/rotate-signing-keys" \
-H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
-d '{"purpose":"access_token","grace_period_seconds":900}'900 seconds is the floor: one 15-minute cache TTL. Consumers will see churn. That is the correct trade against a known-compromised key.
Rotation stops ulex from issuing more tokens with the old key. It cannot un-issue the ones already out there. Any token signed by a compromised key and not yet expired stays valid. Keep access-token lifetimes short for that reason.
#SAML certificates
Two distinct certificates, frequently confused.
| Certificate | Belongs to | Comes from | Rotated by |
|---|---|---|---|
| ulex's signing certificate | signing_key with purpose: saml_response | ulex's signing keys | ulex, on the signing-key schedule |
| the customer's signing certificate | connection.config.saml.x509_certificate | the customer's IdP | the customer |
# ulex's certificate, for your SP to verify assertions
curl -sS "$BASE/applications/$APP_ID/secret" -H "$AUTH" | jq -r '.saml_signing_certificate, .saml_signing_certificate_expires_at'
# a customer's certificate, for ulex to verify their assertions
curl -sS "$BASE/connections/$CON_ID" -H "$AUTH" | jq '.config.saml.x509_certificate[0:60] + "…", .config.saml.x509_certificate_expires_at'A rotation on the customer side:
curl -sS -X PATCH "$BASE/connections/$CON_ID" -H "$AUTH" -H "$JSON" \
-d '{"config":{"strategy":"saml","saml":{ …the full config, with the new "x509_certificate"… }}}' | jq -r .state
curl -sS -X POST "$BASE/connections/$CON_ID/verify" -H "$AUTH" | jq -r .valid
curl -sS -X POST "$BASE/connections/$CON_ID/activate" -H "$AUTH" | jq -r .stateThe connection drops to draft between the patch and the activate. Ask the customer to serve both certificates during an overlap; that removes the window entirely.
Your SP should read ulex's certificate from GET /applications/{id}/secret with a 7-day cache, not from a config file. A SP that pins a certificate breaks once a year.
#Webhook secrets
curl -sS -X POST "$BASE/webhooks" -H "$AUTH" -H "$JSON" -d '{"url":"https://hooks.example.com/ulex","events":["user.created"]}'{ "webhook": { "id": "whk_01M3PSVK981SXWGKG9JXHC1P0Y", "secret_prefix": "whsec_3Kq9" }, "secret": "whsec_3Kq9Xa2mB7yLt4NxZ1pRc6HdE0sJg3AuV8" }Returned once. There is no in-place rotation, because the old secret cannot be re-revealed during an overlap. The procedure:
curl -sS -X POST "$BASE/webhooks" -H "$AUTH" -H "$JSON" \
-d '{"url":"https://hooks.example.com/ulex","events":["user.created"]}' | jq '{id: .webhook.id, secret}'Deliveries go to both endpoints during the overlap, so nothing is missed.
curl -sS -X POST "$BASE/webhooks/$NEW_ID/test" -H "$AUTH" -H "$JSON" -d '{"event":"user.created"}'
curl -sS "$BASE/webhooks/$NEW_ID/deliveries?limit=1" -H "$AUTH" | jq '.[0].data[0] | {status, response_status}'curl -sS -X DELETE "$BASE/webhooks/$OLD_ID" -H "$AUTH"Verify with both secrets for the duration if you can. ulex supports up to 5 verification secrets on one endpoint during an overlap; the others are rejected.
#API keys
There is no key to rotate. The scrypt hash is a verification, not a cipher, and you cannot re-encrypt a hash. Rotation is:
curl -sS -X POST "$BASE/tenants/current/api-keys" -H "$ADMIN" -H "$JSON" -d '{"name":"agent-bootstrap-v2","scope":[…],"expires_in_days":90}'
# deploy the new key
curl -sS -X DELETE "$BASE/tenants/current/api-keys/$OLD_ID" -H "$ADMIN"| Schedule | Trigger |
|---|---|
| Every 90 days | expires_in_days, enforced by the server |
| Immediately | any suspected exposure, any developer who leaves, any log that contained the key |
| Immediately | a mcp.tool_denied loop suggesting a leaked key in the wrong place |
#What ulex never does
- It never stores a key it can show you twice.
- It never logs a secret, at any level, including debug. The scrubber runs before the write.
- It never puts a secret in a URL.
?token=is400; onlyAuthorizationheaders and form bodies are accepted. - It never allows a wildcard in
ip_allowlist. - It never lets an API key with
read:applicationsread a client secret. That needsulex:admin. - It never rotates the CMK without a maintenance window, because rotation means re-encrypting every secret under it.