Smart card and X.509 login with Keycloak: when teams need it
Teams need certificate-based sign-in when a regulated organization must authenticate staff with PIV, CAC or other client certificates, and must keep the whole chain inside infrastructure it controls. Keycloak supports X.509 client certificate authentication as a browser login method, but the design work sits in four places: the reverse proxy that terminates TLS and requests the certificate, the revocation checks that decide whether a presented certificate is still valid, the identity mapping that connects a certificate field to a Keycloak user, and the way the certificate is combined with other factors in the authentication flow.
This page covers each of those decisions in turn: where mutual TLS is handled (at the proxy or in Keycloak), how CRL and OCSP checks are configured and what happens when a revocation service is unreachable, which certificate fields map to usernames or email addresses and how collisions are resolved, and how a smart card login is paired with a second factor or kept as a single factor for a defined population. DeployOpen plans and builds this inside the client's own cloud accounts, data centers or air-gapped networks, and delivers the configuration, test evidence and runbooks that the client's security and compliance teams review.
DeployOpen prepares the system, controls and evidence for an assessment, but it does not issue audit reports, attestations or certifications. Before scoping the work, confirm with your certificate authority and your assessor which revocation method your policy requires, which certificate policies and extensions your smart cards carry, and whether your assurance requirements allow certificate login as a single factor. Those answers determine the proxy and flow design more than any Keycloak setting does.
How a smart card login reaches Keycloak
The login starts in the browser, where the user presents a certificate from a smart card. The reverse proxy performs the TLS client authentication and, if configured, the revocation check, then forwards the certificate details to Keycloak. Keycloak maps the certificate to a user and asks for any second factor before issuing tokens to the application. Check the trust boundary: Keycloak should accept forwarded certificate headers only from the proxy, never directly from the internet.
Request path from smart card through the proxy and Keycloak to the application.
Choosing where certificates are validated
This table compares validating client certificates at the reverse proxy with validating them inside Keycloak, and mutual TLS limited to login with broader client certificate use. Read each column against your own network layout and confirm every product setting against the documentation for your Keycloak release before you commit to a design.
| Decision point | Validate at the reverse proxy | Validate inside Keycloak |
|---|---|---|
| Trust boundary | The proxy terminates TLS, checks the client chain and revocation, then passes identity data to Keycloak. Keycloak trusts the proxy, so the proxy becomes a critical control point. | Keycloak receives the certificate itself and validates the chain against its own truststore. The trust boundary stays with the identity provider, but the proxy must still pass the certificate through. |
| What must be forwarded | The verified certificate or its subject and serial in a trusted header, plus a signal that verification succeeded. Headers must be stripped from outside clients. | The full client certificate in the header Keycloak is configured to read, passed only from the proxy. Confirm the header name and format for your release. |
| What must be trusted | Only the proxy's header output, which Keycloak must accept only from the proxy address or mutual connection. | The proxy's forwarding behavior and the certificate content it relays. Keycloak's truststore and certificate settings carry the validation logic. |
| Revocation handling | Usually handled by the proxy's CRL or OCSP configuration. Confirm whether the proxy's revocation results reach Keycloak in any form. | Keycloak's CRL and OCSP settings, including how responses are cached and what happens when the responder is unreachable. Confirm current options in the server administration guide. |
| Operational fit | Fits teams that already run a managed proxy with certificate policy. Changes to trust anchors happen in one place, but proxy configuration errors affect all apps behind it. | Fits teams that want validation rules close to the identity provider. Changes require Keycloak truststore updates and restarts or reloads, so plan them into upgrade and rotation work. |
| Mutual TLS for login only | Client certificates are requested only on the login path, using path or host rules. Other applications stay on standard TLS. | Certificate authentication is limited to the browser login flow. Confirm how flows are scoped so that other clients do not receive the certificate prompt. |
| Broader client certificate use | The proxy can enforce certificates for APIs and services as well, which widens the proxy's role and its certificate policy. | Keycloak handles only identity flows. Services that need certificates for their own APIs still need separate validation, so this option does not cover them. |
CRL and OCSP checking: what to decide before go-live
Certificate login is only as strong as the revocation checks behind it. The four decisions below determine whether a revoked card or certificate stops working in Keycloak, and how quickly. Each depends on the PKI your organization already runs, so confirm every answer with your certificate authority team before the login flow goes live.
CRL source and refresh cadence
Decide where Keycloak reads its certificate revocation lists, which distribution points it trusts, and how often the list is refreshed. A list that refreshes less often than your CA publishes new revocations leaves a window where a revoked card still signs in. Ask the CA team for the publication interval, the next-update value in each CRL, and whether the distribution point is reachable from the Keycloak network segment. Confirm the refresh settings against the Keycloak documentation for your release.
Keycloak docsOCSP responder availability
Decide whether OCSP is used alongside or instead of CRLs, and who operates the responder. A single responder in one data center becomes a login dependency for every user. Ask whether the CA runs redundant responders, what their uptime targets are, and whether responses are signed by a delegated responder certificate that Keycloak can validate. Test a revoked certificate and a valid one against each responder before go-live.
Behavior when a responder is unreachable
Decide whether a login fails closed (denied when revocation status cannot be checked) or fails open (allowed with a logged warning). Fail closed suits high-assurance workforce access but can lock out staff during a CA outage. Fail open keeps logins working but accepts certificates that may have been revoked. Document the choice, the owner who can switch it, and the alert that fires when a check fails. Treat this as a risk acceptance that your security and compliance leads sign.
Removing revoked credentials from active sessions
A revocation check at sign-in does not end sessions that already exist. Decide how a revoked certificate affects tokens already issued, how long those tokens remain valid, and whether Keycloak sessions tied to that user are ended. Plan the procedure an administrator follows when a card is reported lost, including disabling the linked user, revoking sessions, and confirming the CA status. Test this path end to end, because it is the one most often missed in go-live checklists.
Confirm the PKI decisions with the CA team
The answers above depend on the CA hierarchy, the publication model, and the agency or enterprise policy that governs the cards. Bring the CA team a written list of questions covering CRL URLs, OCSP URLs, responder certificates, publication schedules, and the revocation reasons they record. Ask who owns each responder and who is contacted during an outage. Record the answers in the design document so the Keycloak configuration can be traced back to them.
Setting up certificate login step by step
This sequence takes certificate login from a trust chain on paper to a working Keycloak flow that refuses revoked certificates, maps identities predictably, and keeps a fallback path for users who cannot sign in with a card.
Confirm the trust chain and issuing CAs
Before touching Keycloak, the team that owns the PKI lists every root and intermediate CA that may issue login certificates, the certificate policies or key usages each one enforces, and whether the CA publishes CRL distribution points or OCSP responders the login path can reach. The output is a written trust list signed off by the identity and security owners. Check it by building the chain for one real user certificate from the card or a test PKI and confirming every intermediate is present and validates to the trusted root. Any certificate that fails this step should not be added to the trust store.
Configure TLS and proxy path restrictions
The platform team sets up TLS on the reverse proxy and Keycloak, then decides where client certificates are verified: at the proxy, which forwards identity headers to Keycloak, or inside Keycloak using its X.509 authenticator. Whichever point is chosen, the proxy must expose only the login endpoints that need certificate handling, keep the admin console and Administration REST API on a separate hostname or context path as the production guide recommends, and strip any client-supplied certificate headers from untrusted sources. The output is a documented routing table. Verify it by sending requests to the login endpoint with and without a certificate and confirming the admin paths remain unreachable from the public hostname.
Set up the X.509 authenticator and revocation
An administrator adds the X.509 browser flow or the client certificate authenticator in the realm, loads the trusted CA certificates, and enables revocation checking with CRL, OCSP, or both, matching the behavior the CA publishes. Decide and record what happens when a revocation endpoint cannot be reached, because a fail-open setting quietly accepts revoked certificates. The output is a saved authentication flow with the revocation settings visible in configuration. Verify it by logging in with a revoked test certificate and confirming the attempt is refused, then repeating with the revocation responder blocked to confirm the failure behavior matches the recorded decision.
Define certificate-to-user mapping
The identity team chooses which certificate field identifies the user, such as a subject alternative name or a field that carries an employee identifier, and sets the matching rule that links it to an existing Keycloak user. Ambiguous mappings are the most common source of wrong-account logins, so the rule should fail closed when no single user matches and should never fall back to matching on display name. Document the mapping in a table that lists the certificate field, the normalization applied, and the user attribute it matches. Verify it with at least one card or certificate per user population, including a user whose name is shared with another person, and confirm each login lands on the correct account.
Test with real cards and a test PKI
Testing runs in two passes. First, a test PKI issues certificates covering valid, expired, revoked, wrong-issuer, and untrusted-root cases, and each must produce the expected result in a non-production realm. Second, real smart cards from the pilot group are enrolled, with middleware and reader drivers recorded for each workstation image. The output is a test matrix with expected and actual results. Verify that every negative case is refused and that the reader and browser combinations in use support the certificate prompt, since card middleware differences often cause failures that look like Keycloak errors.
Add the second factor and confirm fallback
Once certificate identity is proven, the team adds the second factor the requirement calls for, such as an OTP or a passkey step after the certificate check, using a conditional or ordered flow so the second factor cannot be skipped by changing the request. The fallback path for lost or locked cards is designed at the same time, with the recovery owner and identity checks written down. The output is an updated flow and a recovery procedure. Verify with a test user that a certificate without the second factor is refused and that the fallback route works without weakening the certificate requirement for other users.
Verify logout, session behavior, and monitoring
The last step checks what happens after sign-in. Confirm that logout ends the Keycloak session and any application sessions, that removing a certificate from the trust store or revoking it stops new logins, and that existing sessions end within the token lifetimes the team set. Confirm that failed certificate attempts are logged with enough detail for investigation, and that metrics for login failures are visible to operations. The output is a signed-off checklist and an operations note. Verify by revoking a test user's certificate during an active session, then confirming the revocation takes effect on the next sign-in attempt and that the event appears in the logs.
Mapping certificate fields to Keycloak users
The first decision is which certificate field identifies the person, because that choice determines whether a sign-in lands on the right account. Common candidates are the subject distinguished name, the subject alternative name (for example a user principal name carried in an otherwise-name extension for smart cards), or a serial number or employee identifier embedded in the certificate. Pick one field that the issuing authority populates reliably and that maps to a stable attribute in your directory or in Keycloak. Avoid fields that change when a certificate is reissued, such as the certificate serial number, as the matching key. Keycloak's X.509 browser flow lets you choose which certificate attribute is used and whether a regular expression extracts the value, so write down the exact field, the expression and the user attribute it must match before you touch the configuration.
Normalize the extracted value before comparing it. Case differences, leading or trailing whitespace, and differing formats of the same identifier (for example an email address in one field and a UPN in another) cause silent mismatches that look like random lockouts. Define one canonical form, apply it in the regular expression or mapping step, and test it against real certificates from each issuing certificate authority, since each CA may populate subject and alternative name fields differently. Confirm the exact field names, mapper options and matching behavior in the Keycloak release you run, because these settings have changed between releases and the Keycloak server administration guide is the reference for your version.
Decide in advance how the flow treats users who must already exist and what happens when the match fails. For a workforce that is provisioned from a directory, require an existing user with the matched attribute and do not let a valid certificate create accounts on its own. Duplicates need a rule as well: two accounts sharing the same identifier, or one identifier claimed by two certificates, should stop the sign-in and raise an event for an administrator, not pick one account arbitrarily. Unknown identities should be denied with a clear message and logged. Ask your security team to confirm how these failures are recorded and who reviews them, and plan a test for each case: a matching user, an unknown certificate, a duplicate identifier, and a certificate from an issuer you did not intend to trust.
Security and operational risks to design out
Certificate login moves trust into certificate authorities, proxies, revocation services and card logistics. The risks below sit at those seams, and each one is easy to miss when the sign-in works in a demo.
Header spoofing from the proxy
When a reverse proxy performs mutual TLS and forwards certificate details to Keycloak in a header, any client that can reach Keycloak directly can send that header itself. Confirm that only the proxy can reach Keycloak's listener, that the proxy strips any client-supplied certificate header on every route, and that Keycloak trusts the header only from the proxy's address. Test this with a request that carries a forged header and no client certificate.
Production guideCertificates from untrusted authorities
A certificate that chains to any trusted root is not the same as a certificate issued to the person you expect. Limit the trusted CA bundle to the issuers your program actually uses, including any intermediates, and review that bundle whenever an issuer is added or retired. Map identities only from fields that your issuer policy defines, such as a subject alternative name or a dedicated attribute, and reject certificates that lack them.
Weak revocation handling
Lost or terminated cards remain valid until revocation is checked and enforced. Decide whether your deployment uses CRL, OCSP or both, how often the lists refresh, and what happens when the revocation service is unreachable: fail closed for privileged roles is the usual choice. Confirm the behavior in the Keycloak version you run, because the setting names and defaults vary by release.
Lost card recovery paths
A lost card should not turn into a password reset that bypasses the certificate requirement. Define in advance what the help desk does: temporary access through a second factor, a time-limited alternate credential, or a reissued card after identity proofing. Each path needs its own audit trail and an owner, and none should quietly reopen password login for accounts that are meant to be card-only.
Admin paths reachable without certificates
Keycloak's production guide recommends exposing the admin console and Administration REST API on a different hostname or context path from public frontend URLs. Certificate login on the public realm does not protect an admin console that also accepts a password on the same host. Route admin traffic through a separate hostname with its own certificate and admin flow, then test that no admin URL responds on the public hostname.
Production guideFailed certificate login visibility
Certificate rejections show up as ordinary login failures unless someone collects them. Enable metrics with --metrics-enabled=true, which exposes Prometheus-format data at /metrics on the management interface, and keep that interface off public routes. Pair the metrics with server logs that record rejected certificates, and alert on bursts of failures and on any login with a revoked serial.
Metrics guideQuestions buyers ask before adding smart card login
What drives the cost and effort of smart card login in Keycloak?
The main drivers are the PKI behind the cards, the number of issuing certificate authorities, the proxy design and the factor combinations you require. A single internal CA with one trust chain is far simpler than several issuing CAs, each with its own revocation endpoints and certificate policies. Proxy design matters because mutual TLS can terminate at the reverse proxy or inside Keycloak, and each choice changes how client certificates are forwarded and validated. Combining a certificate with a password or OTP adds flow design and testing. Testing with real cards from your own issuer is usually the largest unknown, so ask any partner to name the card types, middleware and readers they will test with. A written quote should list each of these as a separate line item.
How long does smart card login take to build?
Duration depends on how many certificate authorities you trust, whether revocation checking is already served by your PKI, how many applications change, and how quickly your teams can supply test cards and a staging environment. Work that starts with an existing PKI, a single issuing CA and one or two applications is much shorter than work that spans several agencies, business units or CAs. The reader must supply certificate chains, CRL or OCSP endpoint details, a named identity source for mapping certificate fields to users, and access to a test population. Ask the partner for a timeline tied to these inputs, with dependencies on your PKI and network teams stated explicitly, and confirm it against your own change calendar before signing.
Can an internal team implement smart card login without outside help?
Yes, a capable identity team can do it, provided it has skills in Keycloak authentication flows, TLS and PKI. The work is not only configuration: it includes trust store management, certificate field mapping, revocation checking, failure handling and regression testing of every login path. Teams that have run Keycloak in production and understand their own certificate issuance usually cope well, while teams new to either topic often underestimate the testing. A useful test is whether someone on your team can explain how a revoked card is rejected, and what happens when OCSP is unreachable. Many organizations choose a fixed-scope engagement for the design and testing, then run the platform themselves.
What does the work need from identity, PKI and network teams?
Each team owns a different part of the chain. The PKI team provides the trust anchors, issuing CA certificates, certificate policy details and the CRL or OCSP endpoints. The identity team decides which certificate field, such as a user principal name or an email attribute, maps to which Keycloak user, and owns the user lifecycle when a person leaves. The network team handles load balancer and reverse proxy configuration, including how client certificates are passed to Keycloak, and firewall rules that let revocation checks reach their endpoints. Security should review how the admin console and administration endpoints stay on a separate hostname or path. Agree on these responsibilities in writing at the start, since gaps between teams are the most common cause of delay.
How is fallback handled when a smart card is lost?
Fallback should be designed before rollout, not improvised after the first lost card. Common options include a second factor enrolled in advance, such as a security key or an OTP credential, or a temporary access path that a help desk can issue after a documented identity check. Whichever you choose, the fallback path must not weaken the certificate requirement for everyone else, so test that a user without a card cannot reach the same application through the backup flow. Keycloak's support for recovery codes, credential resets and required actions can cover parts of this, and the MFA recovery content in this series covers those steps. Ask the partner to document the help desk procedure, the admin reset steps and the audit trail each action produces.
What is one-time work and what recurs after go-live?
One-time work includes the initial design, trust store and flow configuration, certificate mapping, proxy changes, test card setup, the test plan and the first round of documentation. Recurring work includes renewing and rotating trust material when your PKI changes, reviewing revocation checking after CA changes, updating Keycloak when new releases arrive, retesting flows after configuration changes, and handling lost-card cases. Keycloak minor releases arrive several times a year according to the project's stated plan, so budget time for upgrade testing of any custom authenticator or certificate handling. Ask any quote to separate one-time fees from ongoing support, and to state what a retainer covers, such as upgrade and regression testing, rather than leaving it implied.
Should certificate login be combined with another factor?
Often yes. A certificate proves possession of a card and its private key, but it does not by itself prove the person presenting it, and a stolen or unlocked card can be used if the PIN step is weak or missing. Combining the certificate with a second factor or a PIN check gives stronger assurance for sensitive applications. The trade-off is user experience and support load, so decide per application which assurance level you need rather than applying one rule everywhere. Confirm with your security team which assurance requirements apply to each application, and have the partner test each combined path, including the one where the second factor is skipped by mistake.
Which compliance controls does smart card login help you evidence?
Smart card login touches identifier, authenticator and access control requirements, so auditors will ask how the certificate chain is trusted, how revoked certificates are rejected, and how logins are logged. Keycloak can produce login event records and you should confirm where they are stored and how long they are kept. This work prepares configuration, test records and evidence for your assessors, but it does not produce an audit report or certification, which only an independent auditor or certification body can issue. Ask the partner which control families the design maps to and which evidence they will deliver with the handover.
How DeployOpen scopes and delivers certificate login
DeployOpen scopes certificate login as a written, fixed-scope engagement that begins with the trust model, not with Keycloak configuration. Before work starts, the scope document should settle which certificate authorities are trusted, which certificate fields identify a user, how those fields map to Keycloak users, and whether a reverse proxy or Keycloak itself validates the client certificate. It should also name the revocation method, whether CRL checking, OCSP or both, and the fallback behavior when the revocation service is unreachable. Those decisions set the effort, so the quote follows from them. DeployOpen plans these decisions with your security and PKI owners, and the written scope lists the deliverables and the environments in scope before any build begins.
Delivery happens in your own infrastructure, on your cloud accounts, data centers or restricted networks. DeployOpen implements the chosen proxy or Keycloak settings, the certificate-to-user mapping, and any combined flow with passwords, OTP or WebAuthn, then tests the flow against the trust model: valid, expired, revoked and untrusted certificates, mismatched identity fields, and users with no mapping. Configuration is documented so your team can operate and review it, and test results are kept as evidence. DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports, attestations or certifications. Independent auditors and certification bodies make those determinations, so the scope should name which frameworks your assessor will test against. Ongoing support, upgrades and retesting after Keycloak releases are available as a retainer, which is worth pricing alongside the initial build.

