Chaos engineering for identity: breaking auth on purpose
Most teams discover that their identity provider is a single point of failure in the worst possible way: during the outage, with customers locked out and no runbook. The whole product goes dark not because the product broke but because nobody could log in, and nobody had ever tested what happens when auth is slow, degraded, or gone. Chaos engineering flips that discovery earlier and safer, into a controlled game day where you break auth on purpose and watch what falls over.
Why identity is the scariest thing to test and the most important
Teams happily run chaos experiments on stateless services and shy away from auth, precisely because auth failure is so total. That reluctance is the reason it goes untested, and untested is the reason it hurts. The failure modes are specific and worth rehearsing: the identity provider is unreachable, token validation is slow, the session store is partitioned, signing keys fail to rotate, or a dependency the login flow calls (email for magic links, a database for lookups) degrades. Each produces a different blast radius, and you want to know which before a customer finds out.
Start with a hypothesis and a blast radius
A chaos experiment is not "turn off auth and see." It is a falsifiable hypothesis with a tightly bounded scope and an abort condition. Write down what you expect to happen, limit the damage to a single canary tenant or a small traffic percentage, and define the signal that means "stop now." If you cannot state what should happen, you are not ready to run the experiment; you are gambling.
# A scoped chaos experiment: inject latency into token validation
# for 1% of traffic, and assert the system degrades gracefully.
experiment:
name: auth-token-validation-latency
hypothesis: >
When token validation p99 rises to 800ms for 1% of requests,
existing sessions keep working via cached validation and
error rate stays under 0.5%, with no cascading timeouts.
blast_radius:
scope: canary_tenant # not production at large
traffic_percent: 1
injection:
target: auth.validate_token
fault: latency
added_ms: 750
duration: 10m
abort_if:
- metric: auth_error_rate
over: 0.05 # 5% -> halt immediately
- metric: downstream_timeouts
over: 100
steady_state:
- metric: login_success_rate
expected: ">= 0.995"The experiments worth running first
Prioritize the failures that are both plausible and painful. Four earn their place early. IdP unreachable: block the login service and confirm that already-authenticated sessions survive instead of every request re-validating against a dead dependency and failing. Validation latency: as above, confirm caching and timeouts protect callers. Session store partition: split the session datastore and see whether users get logged out en masse or the system reads a stale replica safely. Key rotation failure: simulate a signing key that fails to roll and confirm old tokens still validate during the overlap window.
// The property most auth chaos experiments are really testing:
// a transient dependency failure must NOT invalidate live sessions.
async function validateSession(token: string): Promise<Principal | null> {
const cached = cache.get(token);
if (cached && !cached.expired) return cached.principal; // survive IdP blip
try {
return await idp.validate(token);
} catch (e) {
// Fail toward the last known-good within a bounded grace window,
// rather than logging everyone out because the IdP hiccuped.
if (cached && cached.withinGrace()) return cached.principal;
throw e;
}
}Guardrails so the experiment does not become the outage
The whole point is that the controlled break stays controlled. That means an automated abort wired to real metrics, a canary scope that cannot spill into the general population, a feature flag or kill switch you can hit in seconds, and a human watching, not a fire-and-forget script. Run the first few in a staging environment that mirrors production load, then graduate to a production canary during low traffic with the team present.
The dependencies auth drags along
Auth is rarely self-contained; the login path fans out to a surprising number of dependencies, and each is a hidden failure mode. Magic-link and password-reset flows depend on email delivery, so inject an email-provider outage and confirm users are told clearly rather than left staring at a spinner. Social and enterprise SSO depend on an external identity provider you do not control, so simulate that provider timing out and verify your flow degrades to a clear error instead of hanging every tab. Map the full dependency graph of a single login before you decide you have tested it, because the part that breaks in production is usually the one nobody drew on the diagram.
Game days turn findings into fixes
A chaos experiment that surfaces a weakness is only valuable if the finding becomes a change: a cache added, a timeout tightened, a grace window introduced, a runbook written. Run these as scheduled game days with the on-call team, treat every surprise as a documented action item, and re-run the experiment after the fix to confirm the hypothesis now holds. The goal is a login path whose failure modes are boring because you have already seen each one.
Run it yourself
Bastionary is free, open-source software. Follow the quick start to have it running on your own server, or browse the releases on Git.