Runbooks
Twelve copy-paste runbooks for ulex: a login that always 401s, a SAML signature failure, a stuck directory sync, a dark webhook endpoint, a leaked API key, a stuck deployment, an org that cannot enable SSO, a duplicate-user problem, interpreting resource counts, a JWKS rotation break, and how to verify the audit chain.
Every runbook is: symptom → confirm → fix → verify. Copy the curl blocks.
#Setup
export BASE="https://ulexid.com/api/v1"
export AUTH="Authorization: Bearer $ULEX_API_KEY"
export JSON="Content-Type: application/json"
# Per-run correlation, so everything below is findable in the audit log.
export RUN="runbook-$(date +%Y%m%d-%H%M%S)"
curl_out() { curl -sS -H "$AUTH" -H "$JSON" -H "X-Ulex-Correlation-Id: $RUN" "$@"; }#1. Every login returns 401 or 403
Confirm
curl -sS "$BASE/connections/$CON_ID" -H "$AUTH" | jq '{id, state, domains, domains_state, last_auth_result, last_auth_error}'
curl -sS -G "$BASE/connections/$CON_ID/auth-attempts?limit=5" -H "$AUTH" | jq '.data[] | {outcome, stage, error_code, error_message}'state / error_code | Cause | Fix |
|---|---|---|
state: "draft" | never activated | curl -sS -X POST "$BASE/connections/$CON_ID/activate" -H "$AUTH" |
error_code: "connection_not_active" | same | activate |
state: "inactive" | deactivated | PATCH /connections/{id} with {"state":"active"} |
error_code: "domain_not_verified" | the login routed on an unverified domain | POST /organizations/{id}/domains/{domainId}/verify |
error_code: "access_denied" and org is sso_only | wrong connection | point the org at the right connection_id |
error_code: "user_not_found" | not in config.mock.seed_users | add them; for OIDC, set require_jit_provisioning: false to allow JIT creation (true disables it) |
error_code: "invalid_token" | audience or issuer mismatch | the client is using a token issued for another host or a rotated key |
Verify
curl -sS -X POST "$BASE/simulator/authenticate" -H "$AUTH" -H "$JSON" \
-d '{"application_id":"'"$APP_ID"'","email":"dana@acme.example","connection_id":"'"$CON_ID"'"}' \
| jq '{outcome, stage, code: (.code | length > 0)}'{ "outcome": "success", "stage": "complete", "code": true }#2. SAML signature failure
Confirm
curl -sS -X POST "$BASE/connections/$CON_ID/verify" -H "$AUTH" | jq '{valid, checks: [.checks[] | select(.status != "pass")]}'{
"valid": false,
"checks": [
{ "name": "x509_parse", "status": "pass", "detail": "RSA-2048" },
{ "name": "certificate_not_expired", "status": "fail", "detail": "expired 2026-09-27T00:00:00.000Z" }
]
}Fix
# Download the current certificate from the customer's IdP, then:
CERT=$(curl -sS https://globex.okta.com/app/exk9r2mz1hRtXQ2N5s0d7/sso/saml \
| openssl x509 -noout -fingerprint 2>/dev/null || true)
# …obtain the PEM from the IdP admin console or the app's signing key page, then:
curl_out -X PATCH "$BASE/connections/$CON_ID" \
-d '{"config":{"strategy":"saml","saml":{ …same config, with the new "x509_certificate"… }}}' | jq '{state}'
curl -sS -X POST "$BASE/connections/$CON_ID/verify" -H "$AUTH" | jq .valid
curl -sS -X POST "$BASE/connections/$CON_ID/activate" -H "$AUTH" | jq -r .statevalid: true, then active. Order matters: a certificate patch drops the connection to draft.
Verify
curl -sS -G "$BASE/connections/$CON_ID/auth-attempts?outcome=failure&limit=5" -H "$AUTH" | jq '.data | length'If the customer can serve both certificates during an overlap, you get zero downtime. Ask for that before the old one expires, not after.
#3. A directory sync is stuck or failing
Confirm
curl -sS -G "$BASE/directories/$DIR_ID/syncs?limit=5" -H "$AUTH" | jq '.data[] | {id, state, trigger, error, stats, finished_at}'{
"id": "job_01M3PSVQ68YGZREJKDVZSMQ64T",
"state": "running",
"trigger": "scheduled",
"error": null,
"stats": { "users_created": 0, "users_updated": 0, "users_deactivated": 0, "users_failed": 0, "groups_synced": 0 },
"started_at": "2026-09-29T14:45:00.000Z",
"finished_at": null
}A running job with a started_at more than 15 minutes old is stuck. That is 4× the expected wall clock.
Fix
# A stuck job does not need cancelling; the next trigger supersedes it.
curl_out -X POST "$BASE/directories/$DIR_ID/sync" | jq '{id, state}'
SYNC=$(curl_out -X POST "$BASE/directories/$DIR_ID/sync" | jq -r .id) # trigger, capture
for i in $(seq 1 30); do
sleep 2
STATE=$(curl -sS "$BASE/directories/$DIR_ID/syncs?limit=1" -H "$AUTH" | jq -r '.data[0].state')
[ "$STATE" = "succeeded" ] && break
[ "$STATE" = "failed" ] && break
done
curl -sS "$BASE/directories/$DIR_ID/syncs?limit=1" -H "$AUTH" | jq '.data[0] | {state, error, stats}'state | error | Fix |
|---|---|---|
failed | 401 | PATCH /directories/{id} with a new scim_token, using env: |
failed | 400 invalidFilter | fix user_filter; test it against the provider directly |
partial | non-null | stats.users_failed > 0; those users exist upstream and not here. Report them to the customer |
pending | — | the queue is backed up. Check GET /environments/prod/health for queue |
Verify
curl -sS -G "$BASE/directories/$DIR_ID/users?limit=5" -H "$AUTH" | jq '.data[] | {email, status, external_id}'
curl -sS -G "$BASE/audit-events" -H "$AUTH" --data-urlencode 'action_prefix=directory.' --data-urlencode 'limit=5' | jq '.data[].action'#4. A webhook endpoint went dark
Confirm
curl -sS "$BASE/webhooks/$WHK_ID" -H "$AUTH" | jq '{status, failure_count, disabled_at, disabled_reason, last_delivery_status}'
curl -sS -G "$BASE/webhooks/$WHK_ID/deliveries?limit=5" -H "$AUTH" | jq '.data[] | {event, attempt, response_status, error, duration_ms}'Fix
# 1. Test the receiver without touching the endpoint's status
curl_out -X POST "$BASE/webhooks/$WHK_ID/test" | jq '{id, status}'
sleep 3
curl -sS "$BASE/webhook-deliveries/$DLV_ID" -H "$AUTH" | jq '{status, response_status, response_body, error}'
# 2. Re-enable only after the test delivers
curl_out -X POST "$BASE/webhooks/$WHK_ID/enable" | jq '{status, failure_count}'response_status | Cause |
|---|---|
null + error | the receiver is unreachable: wrong host, firewall, or it is not running |
400 | your signature verification is wrong. That is a code bug |
429 | you are rate-limiting yourself at 25 rps |
5xx | your handler is throwing |
Verify and reconcile — events raised while disabled are not replayed:
curl -sS -G "$BASE/webhooks/$WHK_ID/deliveries?status=dead_lettered" -H "$AUTH" | jq -r '.data[].event_id' | sort -u > lost.txt
wc -l < lost.txtRe-fetch current state for each affected resource. Do not replay payloads; they are point-in-time snapshots.
#5. A leaked API key
Confirm
curl -sS "$BASE/tenants/current/api-keys" -H "$ADMIN" | jq '.data[] | {id, name, prefix, last_used_at, last_used_ip_hash, expires_at, revoked_at}'Fix — revoke first
curl_out -X DELETE "$BASE/tenants/current/api-keys/$KEY_ID" | jq '{id, revoked_at}'
curl_out -X POST "$BASE/tenants/current/api-keys" \
-d '{"name":"agent-bootstrap-v2","scope":["mcp:tools","read:organizations","write:organizations","read:users","write:users"],"expires_in_days":90}' \
| jq '{id, prefix, key: (.key | length > 0)}'Verify — what did the old key do?
curl -sS -G "$BASE/audit-events" -H "$ADMIN" \
--data-urlencode "actor_id=$KEY_ID" \
--data-urlencode 'since='"$(date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%S.000Z)" \
--data-urlencode 'limit=200' | jq -r '.data[] | "\(.timestamp) \(.action) \(.outcome)"' | sort | uniq -c | sort -rnIf impersonation.started appears and you did not cause it, this is a SEV-1. See Incident response.
#6. A deployment is stuck
Confirm
curl -sS "$BASE/deployments/$DEP_ID" -H "$AUTH" | jq '{state, progress_percent, running: [.steps[] | select(.state=="running") | .name], error}'Fix
curl -sS -X POST "$BASE/deployments/$DEP_ID/cancel" -H "$AUTH" | jq '{state, finished_at}'
# A prod deployment needs an explicit confirm, or it is 400 on `confirm`
curl_out -X POST "$BASE/deployments" \
-d '{"application_id":"'"$APP_ID"'","environment":"prod","commit_sha":"9f3c1a7b2d4e6f8a0b2c4d6e8f0a2b4c6d8e0f2a4b","strategy":"simulated","confirm":true}' | jq '{id, state}'Cancelling a terminal deployment is 409. If the deployment already succeeded, you are looking at the wrong record — check GET /deployments?application_id=…&order=desc.
Verify
curl -sS "$BASE/deployments/$DEP_ID/logs?tail=50" -H "$AUTH" | jq -r '.lines[] | select(.level=="error" or .level=="warn") | "[\(.level)] \(.step): \(.message)"'#7. An organization cannot enable SSO
Confirm
curl -sS "$BASE/organizations/$ORG_ID" -H "$AUTH" | jq '{sso_only, connection_id, allow_profiles_outside_organization}'
curl -sS "$BASE/organizations/$ORG_ID/domains" -H "$AUTH" | jq '.data[] | {name, state}'Fix
# Domain first — sso_only with a domain-routed connection requires a verified domain
DOM_ID=$(curl_out -X POST "$BASE/organizations/$ORG_ID/domains" -d '{"domain":"acme.example","verification_strategy":"dns"}' | jq -r .domain.id)
curl_out -X POST "$BASE/organizations/$ORG_ID/domains/$DOM_ID/verify" | jq -r .state
# Then the connection
CON_ID=$(curl_out -X POST "$BASE/connections" -d '{"name":"Acme SSO","organization_id":"'"$ORG_ID"'","domains":["acme.example"],"config":{"strategy":"mock_sso","mock":{"seed_users":[{"email":"'"$ADMIN_EMAIL"'"}]}}}' | jq -r .id)
curl -sS -X POST "$BASE/connections/$CON_ID/activate" -H "$AUTH" | jq -r .state
# Then bind it
curl_out -X PATCH "$BASE/organizations/$ORG_ID" -d '{"connection_id":"'"$CON_ID"'","default_connection_id":"'"$CON_ID"'","sso_only":true}' | jq '{sso_only, connection_id}'When allow_mocks is false and verification_strategy: "dns", the TXT record must exist first:
dig +short TXT _ulex-challenge.acme.exampleVerify
curl_out -X POST "$BASE/simulator/authenticate" -d '{"application_id":"'"$APP_ID"'","email":"'"$ADMIN_EMAIL"'","organization_id":"'"$ORG_ID"'","connection_id":"'"$CON_ID"'"}' | jq '{outcome, stage}'#8. Duplicate users
Confirm
curl -sS -G "$BASE/users" -H "$AUTH" --data-urlencode 'search=pat@acme.example' | jq '.data[] | {id, email, external_id, directory_id, created_at}'usr_01M3PSWBPGS08FWV4NV7P9VNFN pat@acme.example okta-00u9xK2mB7yLt4N dir_01M3PSV… 14:47:03
usr_01M3PSW0YRNEQQAP9T1JP9FC2Y pat@acme.example null null 14:52:11Two users, one email. Note email is unique per tenant, so this is not a constraint violation; it means the two records have different email values that normalise differently, or one was created with a distinct external_id and a variant address.
Cause, in order of likelihood
external_idchanged upstream, so a sync created rather than updated.- Two directory entries for one human (contractor plus employee).
- A typo'd address upstream.
Fix
# The one with the older, directory-linked record wins.
KEEP=usr_01M3PSWBPGS08FWV4NV7P9VNFN
DROP=usr_01M3PSW0YRNEQQAP9T1JP9FC2Y
# Carry memberships and groups across
curl -sS "$BASE/users/$DROP/memberships" -H "$AUTH" | jq -r '.data[] | "\(.organization_id) \(.role) \(.group_ids|join(","))"'
# …re-add each to $KEEP with POST /organizations/{id}/members, then:
curl -sS -X PATCH "$BASE/users/$KEEP" -H "$AUTH" -H "$JSON" -d '{"metadata": {"merged_from": "'"$DROP"'"}}'
curl_out -X DELETE "$BASE/users/$DROP" | jq -r .deletedPrevent
- Pin
attribute_mapping.external_idto an attribute the upstream does not regenerate. - Enable a rule group on the organization:
source: "rule",match: { email_domain: "acme.example" }, so humans are discoverable by domain. - Alert on
user.createdrate. A duplicate shows up as a sudden doubling.
#9. Interpreting tenant resource counts
Confirm
Pricing is usage-based. ulex_get_status and ulex_get_usage return informational resource counts; they do not report quota ceilings or headroom, and reaching a count does not block resource creation.
For 429 too_many_requests, inspect Retry-After and rate-limit settings. Do not delete resources to resolve a rate-limit response.
#10. A signing-key rotation broke a consumer
Confirm
curl -sS "$BASE/oauth2/keys" | jq '.keys[] | {kid, alg, use}'Two keys means a rotation is in progress. A consumer that pins kid: "…" and gets an unknown kid is failing.
Fix — fix the cache, then rotate
// The consumer must keep a kid-keyed map, not a pinned kid.
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 res = await fetch("https://ulexid.com/api/v1/oauth2/keys", {
headers: { Authorization: `Bearer ${process.env.ULEX_API_KEY!}` },
});
const jwks = (await res.json()) as { keys: JsonWebKey[] };
// Do NOT clear before repopulating: in-flight tokens signed by the old key
// must keep verifying during the overlap.
for (const k of jwks.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;
}# With the consumer fixed, rotate with a full grace window
curl_out -X POST "$BASE/tenants/current/rotate-signing-keys" -d '{"purpose":"access_token","grace_period_seconds":604800}' \
| jq '{rotated, keys: [.keys[] | {kid: .new_key.kid, state: .new_key.state}]}'Verify
curl -sS "$BASE/oauth2/keys" | jq '.keys | length'Two keys for the grace window, then one.
#11. Rate-limited by MCP
Confirm
curl -sS -D- -o /dev/null "$BASE/me" -H "$AUTH" | grep -i 'x-ratelimit'x-ratelimit-limit: 600
x-ratelimit-remaining: 0
x-ratelimit-reset: 1790693172Fix — batch, do not slow down uniformly.
| Instead of | do |
|---|---|
ulex_create_user × 500 | 5 × POST /scim/v2/Bulk with 100 operations |
ulex_add_organization_member × 500 | 3 × ulex_list_users({ organization_id, limit: 200 }) |
| poll a deployment every 100 ms | every 250 ms, or the deployment.succeeded webhook |
| poll sync status every 500 ms | every 2 s, or the dsync.* webhook |
ulex_simulate_login per assertion | ulex_mint_access_token |
GET /audit-events in a loop | one export with format=ndjson and a date window |
The shield's general request bucket is per source IP and Lambda container. Honor Retry-After; pricing is usage-based and the tenant usage report does not expose a rate quota.
#12. Verify the audit chain
Confirm
curl -sS -G "$BASE/audit-events/export" -H "$AUTH" -H "Accept: application/x-ndjson" \
--data-urlencode 'format=ndjson' \
--data-urlencode 'since=2026-09-01T00:00:00.000Z' \
--data-urlencode 'until='"$(date -u +%Y-%m-%dT%H:%M:%S.000Z)" \
-o /tmp/ulex-audit.ndjsonnode -e '
const fs = require("fs");
const rows = fs.readFileSync("/tmp/ulex-audit.ndjson", "utf8").trim().split("\n").map(JSON.parse);
// Order by the links, not by the order the rows arrived in. There is no
// sequence number: two entries written in the same second cannot be ordered by
// one, and trusting the export order reports intact chains as broken.
const byHash = new Map(rows.map((r) => [r.entry_hash, r]));
const linkedTo = new Set(rows.map((r) => r.previous_hash).filter(Boolean));
const reachable = new Set();
for (const tip of rows.filter((r) => !linkedTo.has(r.entry_hash))) {
let cur = tip;
while (cur && !reachable.has(cur.entry_hash)) {
reachable.add(cur.entry_hash);
cur = cur.previous_hash ? byHash.get(cur.previous_hash) : undefined;
}
}
const orphan = rows.find((r) => !reachable.has(r.entry_hash));
// The one check that still carries information once the order comes from the
// links: the chain must not run backwards against the clock.
let backwards = null;
for (const r of rows) {
const prev = r.previous_hash ? byHash.get(r.previous_hash) : null;
if (prev && prev.timestamp > r.timestamp) { backwards = r.id; break; }
}
console.log(
`${rows.length} events; chain ${orphan || backwards ? "BROKEN at " + (orphan ?? backwards).id : "INTACT"}`
);
'8471 events; chain INTACTA broken chain is not automatically a SEV-1. Only hash_mismatch — an entry's contents no longer hashing to the value recorded on it — means somebody altered the log, and that is the one that makes everything else in your post-mortem unreliable. An entry nothing links to, or a chain that runs backwards, is ulex having written the log wrong: a lost write, two appenders racing for the same predecessor, or a clock behind. Take those to support. See Runbook 14 and Incident response.
#13. Burst traffic returns 500, not 429
Symptom. Under concurrent load — a morning login burst, a pipeline fleet redeploying, a load test — a fraction of requests return 500. Clients retry indefinitely because a 500 looks transient. The function logs are empty.
Do this first. An empty function log with a 500 means the request never reached the function. That single observation eliminates the entire application layer — no code path, no store call and no bug in this repository produces it — and sends you to the platform. Do not read application logs looking for this.
# The gateway's own account, next to the stage. They are frequently not equal,
# and the gap is the whole answer.
aws lambda get-account-settings --query 'AccountLimit.ConcurrentExecutions'
# Concurrent executions: 10 <- an account ceiling, not a stage setting
aws apigateway get-account --query 'throttleSettings'
# {"burstLimit": 5000, "rateLimit": 10000}
aws apigateway get-stage --rest-api-id <api> --stage-name v1 \
--query 'methodSettings.*/*.throttlingRateLimit'
# 4000Why the account ceiling is the usual answer. API Gateway reports a Lambda concurrency shortage as 500 InternalServerErrorException, not 429 and not Rate Exceeded. The gateway could not obtain an execution slot, so it never invoked the function — which is why the function log is empty and why integrationLatency in the access log is single-digit milliseconds rather than tens or hundreds.
That combination is the tell:
| Observation | Points to |
|---|---|
Rate Exceeded, empty logs | stage rate or burst throttle |
InternalServerErrorException, empty logs, <20 ms latency | Lambda concurrency ceiling |
InternalServerErrorException, logs present | the function threw — a real bug |
Confirming it. Find the concurrency at which it starts failing; the ceiling is at or just below it.
for N in 4 8 12 20 40; do
printf "%2d concurrent: " "$N"
seq 1 "$N" | xargs -P "$N" -I{} curl -s -o /dev/null -w "%{http_code}\n" \
-X POST https://<host>/oauth2/token \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials&client_id=invalid' | sort | uniq -c | tr '\n' ' '
echo
doneClean at 20 and failing at 40 is a ceiling in that band. The AWS default for concurrent executions is 1000; an account sitting at 10 has never had the quota raised and cannot self-serve it.
Fixing it. Open an AWS Support case asking for the Lambda concurrent-execution quota to be raised. Give them the account id, the current value, and the error signature above. There is no CDK change for this: it is an account-level quota and RequestServiceQuotaIncrease only works for quotas already above the service default, which this one is not.
Raising it is the right request rather than a workaround. Ten concurrent executions is below what a single identity provider should serve, and no amount of stage or shield configuration reaches it — the stage throttle is a different limit, and raising it only moves the failure to a higher number.
What not to do. Raising the stage throttle to "fix" this. If the stage is throttling, the access log says Rate Exceeded; if the account is, it says InternalServerErrorException. Raising the wrong one hides the symptom until the next burst and makes the next diagnosis harder.
The in-app shield is per-container. services/api/src/shield.ts holds its per-IP token buckets in module scope, so N warm containers each allow the full per-IP budget. This is a documented trade-off — no DynamoDB write per request — and the stage throttle is the distributed backstop. When the account ceiling is raised, per-IP limits get weaker in aggregate, so revisit DEFAULT_LIMITS.generalPerMinute at the same time.
#14. The audit chain does not verify
Symptom. POST /api/v1/audit-events/verify_chain — or ulex_verify_audit_chain — answers valid: false with a failure. Read failure.kind first; the four values mean different things, and three of the four are not a security event.
failure.kind | guidance.severity | What it means | What to do |
|---|---|---|---|
unverifiable | operational | The entry's hash was written by a version whose formula cannot be recomputed from storage. | See below. Not an incident. |
missing_predecessor | operational | An entry is on no branch of the chain: it links at a hash nothing produced, or nothing links to it. An ulex write was lost. | Open a support case with failure.at and the window. |
broken_link | operational | An entry sits somewhere other than where the links put it, or the chain runs backwards against the clock. Both are ulex-side: two appenders racing for the same predecessor, or a clock behind. | Open a support case with failure.at and the window. Do not open an incident on this evidence alone. |
hash_mismatch | security | An entry's contents no longer match the hash recorded on it. The row was altered in place. | Preserve the log and escalate. This is the only kind that is evidence the log was altered. |
Only hash_mismatch says somebody changed the log. Everything else says ulex wrote it wrong, which is a support case and not an incident — telling a customer to page their security team at 3am over our own concurrency is the same false accusation as calling a lost write tampering, and it trains people to ignore the check.
The verifier derives the window's order from the entries' own links, so a healthy log whose entries share a timestamp — normal under concurrency — verifies clean. If you are chasing a report of missing_predecessor or broken_link from before that, re-verify first: the old implementation read the storage layer's sort order and called intact chains damaged.
Also check windowStartsMidChain. A window that began part-way through the chain has its first link unchecked, so valid: true from a 24-hour slice means nothing inside the slice is wrong — not that this slice is a whole chain. Widen the window before telling anyone the log verified.
#Every entry written before ulex 0.2.0 is unverifiable
The entry hash was sha256(... : JSON.stringify(metadata)). JSON.stringify encodes the object's key order at write time, and DynamoDB returns a map in an unspecified order, so those hashes cannot be recomputed from the stored row by anyone. This was measured, not inferred: on a live five-key event the stored hash matched the writer's key order and matched neither the read-back order nor sorted order, and all 120 permutations of those keys were tried.
There is no migration, because the information needed to reproduce the old hashes was never stored. The formula is now canonical — recursively sorted keys, with semantics chosen to agree with the storage round trip — and every entry carries a hash_version.
A legacy log written before 0.2.0 is therefore unverifiable from its first entry. Start a fresh tenant or contact Support if you have a legacy sandbox log you need rotated cleanly.
#Checking integrity is still worth doing
A window of legacy entries still gets a real structural answer. Reachability and order come from the links, which are readable on every entry, so a window whose hashes cannot be recomputed still reports a lost predecessor, an entry on no branch, or a chain that disagrees with the clock. What it cannot do is rule out alteration: unverifiable means nothing was established about this entry's contents, not that they are intact. A window containing only entries written by the current version verifies fully.
The order is derived from the links, which is what makes a healthy log verify under concurrency — several entries sharing a timestamp is normal. It also means "does this entry link to the previous one" is true by construction and is not a check. The ordering property that does carry information is monotonicity: no entry may be dated before the one it links from.