Security

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.

KindWhereAlgorithmRotationWho can trigger it
KMS CMKAWS KMSAES-256annual, or on exposurebreak-glass, two approvals
Data keygenerated per requestAES-256-GCMevery ≤ 60 s, transparentlynobody; it is automatic
Token signing keysigning_key rowsRS256 default, RS384/512, ES256/384, PS256, EdDSAPOST /tenants/current/rotate-signing-keysulex:admin
SAML certificatesigning_key, and each connection's x509_certificateRSA-2048/4096, EC P-256/384with the IdP's schedulewrite:connections
Webhook secretwebhook.secret_encryptedHMAC-SHA256delete and recreatewrite:webhooks

#The KMS CMK

bash
aws kms describe-key --key-id alias/ulex-tenant --region us-east-1
json
{
  "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
  }
}
PropertyValue
KeyManagerCUSTOMER. AWS does not hold it; we do
OriginAWS_KMS, not an imported material. The key material never exists outside KMS in a way we can read
Policythe data-plane role may GenerateDataKey and Decrypt; nobody may PutKeyPolicy, EnableKey, or ScheduleKeyDeletion
DeletionScheduleKeyDeletion is break-glass, two approvals, with a 30-day waiting period that only a second break-glass can cancel
Rotationannual, 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:

text
GenerateDataKey(CMK, KeySpec=AES_256)
  → Plaintext    4 KiB, used immediately, cached in the Lambda environment ≤ 60 s
  → CiphertextBlob  stored in the DynamoDB attribute

The 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

json
{
  "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
}
purposeSigns
access_tokenaccess tokens and their JWT introspection
id_tokenID tokens
webhooknothing today; reserved so a future signed-payload scheme is possible without a schema change
saml_requestAuthnRequests ulex sends upstream
saml_responseassertions and Responses ulex issues
jwt_bearerulex-issued federated assertions

algorithm defaults to RS256. ES256 and EdDSA are available per application.

#The JWKS

bash
curl -sS "$BASE/oauth2/keys"
json
{
  "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

bash
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}'
json
{
  "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.

1
1. Fix the consumers first

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.

ts
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.

2
2. Rotate with a grace window longer than twice the longest cache
Longest consumer cacheMinimum grace
15 minutes30 minutes
1 hour2 hours
6 hours12 hours
24 hours48 hours

604800 (7 days) is the default and is right for anything you do not control.

3
3. Confirm two keys are live
bash
curl -sS "$BASE/oauth2/keys" | jq '.keys | length, map({kid, alg})'
text
2
[{"kid":"key_01M3PSX7B2KQ4V6W8Y0Z1A3B5C","alg":"RS256"},
 {"kid":"key_01M3PSVJA0YP2WDPM2RDR15MGH","alg":"RS256"}]
4
4. Watch the error rate

ulex_jwks_unknown_kid_total should stay at zero. If it is not, a consumer is not caching and you need more grace.

5
5. Let the old key expire

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:

bash
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.

Warning

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.

CertificateBelongs toComes fromRotated by
ulex's signing certificatesigning_key with purpose: saml_responseulex's signing keysulex, on the signing-key schedule
the customer's signing certificateconnection.config.saml.x509_certificatethe customer's IdPthe customer
bash
# 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:

bash
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 .state

The 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

bash
curl -sS -X POST "$BASE/webhooks" -H "$AUTH" -H "$JSON" -d '{"url":"https://hooks.example.com/ulex","events":["user.created"]}'
json
{ "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:

1
1. Create a second endpoint with a new secret
bash
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.

2
2. Deploy the new secret to your receiver and verify with a test
bash
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}'
3
3. Delete the old endpoint
bash
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:

bash
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"
ScheduleTrigger
Every 90 daysexpires_in_days, enforced by the server
Immediatelyany suspected exposure, any developer who leaves, any log that contained the key
Immediatelya 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= is 400; only Authorization headers and form bodies are accepted.
  • It never allows a wildcard in ip_allowlist.
  • It never lets an API key with read:applications read a client secret. That needs ulex:admin.
  • It never rotates the CMK without a maintenance window, because rotation means re-encrypting every secret under it.

#Reference