15. Client certificates on every connection
- Status: Accepted
- Date: 2026-11
- Supersedes: ADR 0014
Context
The client wants two locks on every login. The browser first presents the person’s company client certificate, then the person signs in through Keycloak as before. A session cookie stolen by malware is then worthless on its own: whoever replays it also needs that person’s working client certificate. The client’s security team reviews this as hardening of an SSO-protected endpoint.
ADR 0014 had already built the machinery: the ingress verifies company certificates and proves itself to the gateway with a certificate from kornercode’s internal CA, and the gateway verifies the forwarded certificate again (chain, dates, revocation). It was used only for break-glass, on a hostname of its own. That work was unreleased, so its values, variables and cookie names could change without a migration.
Decision
The certificate check becomes a feature gate for the normal addresses, and break-glass becomes a button on the normal dashboard.
- One feature gate (
clientCertificates.enabled), off by default. Off means kornercode behaves as it did before break-glass: no certificate prompt, no certificate checks, no break-glass. - Gate on: a certificate on every connection, for everyone. The
dashboard, IDE (
dev.) and test-application (test.) addresses all require a valid company client certificate. The gateway verifies it on every request (chain, dates, revocation, a single subject CN), not only at sign-in. - Gate on: then Keycloak, as before. Users and administrators sign in
through OIDC after presenting the certificate. Teams, admin rights and
identity (
sub) come from the token as before. - The certificate must belong to the person signed in. At sign-in the certificate’s CN must equal a configurable claim of the ID token. Every later request on any of the three addresses must present a certificate with that same CN. A stolen cookie with anyone else’s certificate is refused.
- Configurable claims. The identity claim compared with the CN
(
gateway.oidc.identityClaim, defaultpreferred_username; the client’s Keycloak puts the user’s hex ID there) and the groups claim that teams and admin rights are read from (gateway.oidc.groupsClaim, defaultgroups). The groups claim setting applies whether or not the gate is on. - One address. There is no separate break-glass address. With the gate
on, the gateway serves the three hosts only on the listener that requires
the ingress’s client certificate (port 8444); the plain listeners answer
/healthzand nothing else. - Break-glass stays, and never contacts Keycloak. A button on the
sign-in page and on the “identity provider is unavailable” page signs an
administrator in with the certificate alone: certificate valid, CN found
exactly in
breakGlass.mapping, session issued for that entry. No OIDC request is made. It is an explicit click: presenting a certificate never opens a session by itself. - No gate, no break-glass. A mapping without the gate fails the chart render and stops the gateway at start-up, and break-glass sessions are not accepted while the gate is off.
- The audit stays. Every certificate refusal, every break-glass login and
refusal, and the
breakGlassflag on admin actions are recorded. - One revocation policy for everyone.
clientCertificates.revocation.onUnavailable(denyby default, orallow) covers every user and every request, break-glass included. - Cross-site check for every client. State-changing requests on the
dashboard address need exactly one
Originequal to the dashboard’s own origin, andSec-Fetch-Siteabsent orsame-origin, whether the gate is on or off. The client certificate, like the cookie, is ambient authority, and this closes the cross-site request gap on the normal dashboard too.
Details chosen while building it:
- The CN and the identity claim are compared without regard to case (Keycloak lowercases usernames), with no trimming; a missing or empty claim refuses the sign-in. The break-glass mapping, and the later requests of a break-glass session, need the exact CN.
- The session is bound to the CN, not to one certificate: a renewed certificate for the same person keeps working, and revocation of the old one is still checked on every request.
- Bridged sessions on the dev and test hosts are re-verified on every request like the dashboard’s, which closes the gap ADR 0014 documented.
- Open requests (IDE WebSockets, log streams) end when the certificate or the login expires, and the certificate is verified again every 30 seconds while they are open.
- A session from before the gate was turned on (bound to no CN) is signed out quietly. A session bound to another CN is refused, audited and cleared; a page load then shows the sign-in page.
- A sign-in whose identity differs from the CN also ends that identity
provider session (RP-initiated logout with
id_token_hint), so a browser that kept the previous person’s sign-in is not signed in as them again. - Break-glass sessions use the normal session cookie and last at most 8 hours
(
breakGlass.sessionMaxLifetimeSeconds). Each request also needs the CN still mapped to the same identity, so removing or editing an entry ends that person’s break-glass sessions once the gateway runs with the new mapping.
Trust model
The chain for every request with the gate on:
- The browser proves possession of the person’s private key to the ingress (TLS client authentication against the company CA).
- The ingress proves itself to the gateway (client certificate from kornercode’s
internal CA, DNS name
kornercode-ingress). - The gateway verifies the forwarded certificate (chain, dates, revocation, single CN), then checks the CN against the session (normal) or the mapping (break-glass).
It protects against a session cookie replayed from another machine, a stolen cookie combined with another person’s certificate, revoked or expired certificates, and forged certificate headers from anything but the ingress.
It does not protect against malware on the user’s own machine. Malware running
as the user can drive the user’s browser, or use a private key that the
operating system lets that user’s processes use, so it can act with the cookie
and the certificate together. Hardware or non-exportable keys make the key
harder to steal but do not stop its misuse on the infected machine. A
compromised ingress, and anyone able to obtain a kornercode-ingress certificate
from the internal CA issuer, remain trusted, as in ADR 0014.
Consequences
- One revocation policy means one failure mode for everyone. With
deny, an outage of the company’s revocation-list servers that outlasts the cached lists locks everyone out, administrators and break-glass included. Withallow, requests go through unchecked during the outage and each person is audited once a minute withrevocation: unchecked. The documentation says so next to the setting. - Scripts that call the dashboard API with
POST,PUT,PATCHorDELETEmust send anOriginheader equal to the dashboard origin, gate on or off. Browsers do this on their own. - The identity claim must hold the same value as the certificate CN, up to
case. A provider that puts something else in
preferred_usernameneedsgateway.oidc.identityClaimset to a claim that matches. A person whose certificate and account disagree cannot sign in, and cannot be helped by break-glass unless they are in the mapping. - Long-lived requests do not outlive their authority: they are closed within 30 seconds of the certificate being refused (revoked, for example) and at the moment the certificate or the login expires.
- With the Traefik dialect the main Ingress needs its own TLS Secret
(
gateway.ingress.tls.secretName): the TLS option uses strict SNI, which ignores the ingress default certificate. Other ingress controllers must be configured by the operator of the platform (client-certificate verification, the header, and HTTPS to the gateway with the ingress client certificate). - Refusals are audited under
auth.certificate, throttled to one entry per CN and reason per minute, as in ADR 0014. Cross-site refusals are logged, not audited: no certificate or identity was judged. - Malware on the user’s machine is out of scope, as stated above. The control is meant against stolen cookies, not against a compromised workstation.