Keycloak security hardening

A practical guide to hardening a self-managed Keycloak identity provider, covering what to configure, in what order, how to verify it and what to hand over.

On this page

Why Keycloak security hardening starts before go-live

Keycloak security hardening is a set of configuration decisions made across the reverse proxy, the realm, the clients and the logs, and defaults alone do not meet a regulated baseline. A self-managed Keycloak instance will hold sign-in for your applications and access to the admin console, so the choices made before go-live decide how much an attacker gains from a single weakness. The identity provider is a high-value target because compromising it can mint tokens for every connected application, reset or enroll credentials, and change who holds administrative rights. Many of the decisions that matter most are hard to change later: the public hostname and token issuer, the realm structure, how client redirect URIs are registered, and whether logs are captured from day one. Changing an issuer after applications are integrated, for example, means reconfiguring every client that trusts it.

The production guide for Keycloak calls for TLS on all communication, a reverse proxy with path restrictions, and exposing the admin console and Administration REST API on a different hostname or context path from public frontend URLs. Treat those three points as the starting baseline, then confirm each one in your own environment: that no plaintext hop exists between the proxy and the server, that /admin and the administration endpoints are unreachable from the public internet, and that the proxy blocks paths you do not intend to serve. This work is configuration plus verification rather than new software, so the effort sits with the people who own the network, the identity realm and the logging pipeline. Ask your team to write down the intended hostnames, admin access paths and log destinations before the first production realm is created. The Keycloak production configuration guide is the natural reference for that checklist.

Which Keycloak settings and layers carry the hardening

Keycloak hardening is spread across several layers: the edge proxy, the management interface, the admin surface, realm policies, token lifetimes, logs and the database behind them. A gap in one layer can undo controls in another, so review them together rather than one setting at a time.

Edge reverse proxy path rules

The reverse proxy decides which paths reach the internet. Production guidance expects TLS on all communication and path restrictions in front of Keycloak, so that only the public login, OIDC and SAML endpoints are exposed. Check that requests to admin paths and the Administration REST API are blocked at this layer, not only hidden in the UI. Confirm the exact path list against the version you run, because it changes between releases.

Production guide

Separate admin and public hostnames

Production guidance recommends serving the admin console and Administration REST API on a different hostname or context path from public frontend URLs. This separation lets you restrict admin access by network, VPN or identity-aware proxy without affecting users signing in to applications. Verify that the public hostname never advertises admin URLs in discovery documents or redirects.

Management interface and metrics endpoint

The metrics endpoint at /metrics is served on the management interface and is only enabled when --metrics-enabled=true is set. Keep the management port off the public path and scrape it from inside your monitoring network. Metrics can reveal usage patterns and internal topology, so treat exposure as a decision to review, not a default.

Metrics guide

Brute force and password policies

Brute force detection and password policies are set per realm, so each realm needs its own review. Confirm the failure thresholds, lockout behavior and password rules that match your risk profile, and test them with a non-production user. Remember that a lockout policy can also be used to lock out legitimate users, so align it with your help desk process.

Token and session lifetimes

Access token, refresh token and SSO session lifetimes determine how long a stolen token or an unattended browser stays useful. Shorten them where the application allows, and set them per client when one application needs a different window. Test the user experience with the shorter values before go-live so teams do not lengthen them to fix sign-in complaints.

Event and admin event logs

Login events and admin events are only useful if they are enabled, stored and forwarded before an incident. Decide which event types to keep, how long to retain them, and where they are shipped outside the cluster. Review who can read the admin event log, because it records configuration changes made by administrators.

Database and persisted login failures

Keycloak 26.8 persists login failures to the database by default, so the database now holds security-relevant records as well as configuration. Plan its backup, retention, access control and growth, and confirm that the failure data does not expose more than your policy allows. The database also backs the brute force counters, so its availability affects sign-in protection.

26.8 settings that now matter

The 26.8 upgrade notes enforce SMTP StartTLS without plaintext fallback and require signature validation of backchannel logout tokens from external providers. Check that your mail relay supports StartTLS and that logout integrations sign their tokens, or sign-in notifications and logout flows may fail after upgrade. Read the upgrade notes for your exact starting version before changing anything.

Upgrading guide

Which hardening options fit your risk and operating model

This table compares the main Keycloak hardening choices against the risk they reduce and the operating cost they add. Read each row as a decision: find the option that matches your exposure, then check the operational cost in the last column before you commit. Most teams land on the stricter option for admin access and a middle setting for user-facing controls.

DecisionStricter option and when it fitsLenient option and when it fitsOperational cost to plan for
Hostnames for admin and public endpointsSeparate admin hostname or context path, reached only from a management network. Fits regulated estates and any deployment with privileged admin access from outside the corporate network.Single public hostname for console and frontend. Fits small internal deployments with a tight network boundary and no external admin access.Separate routing needs proxy rules, DNS, certificates and a documented way for admins to reach the console. Confirm the split against the production guide before go-live.
Where path restrictions are enforcedBlock admin and management paths at the reverse proxy, so the application never receives those requests from the public network. Fits defense in depth and most assessor reviews.Rely on application-level restrictions only. Fits teams with no separate proxy layer, but the protection then depends on one configuration.Proxy rules need testing after every upgrade, since new endpoints may appear. Ask who owns proxy changes and how they are reviewed.
Access token lifetimeShort access tokens with refresh tokens and session checks. Fits applications handling sensitive data or APIs with high privilege.Longer access tokens with fewer refreshes. Fits low-risk internal tools where sign-in friction is the main concern.Short lifetimes raise token refresh traffic and make session-related support tickets more frequent. Long lifetimes extend the window after a stolen token is used.
Password and lockout policyStrict password rules and brute force protection with tuned lockout thresholds. Fits public-facing sign-in and privileged accounts.Lighter rules with minimal lockout. Fits internal sign-in where the directory already enforces policy, with that dependency documented.Strict lockouts create help desk load and user friction. Tune thresholds with support data, and confirm which policies a federated directory enforces instead.
Multi-factor authentication for adminsRequire a second factor for administrator and realm management accounts. Fits any tenant with privileged realm changes.Second factor for users only. Fits low-risk applications where admin accounts are few and separately controlled.Second factors need enrollment support and recovery planning. Recovery codes and a documented reset process reduce lockout incidents.
Event storageStore login and admin events in the database and forward them to a log pipeline for retention and alerting. Fits audit requirements that expect central, tamper-resistant records.Keep events in the database only, or enable only the event types you need. Fits small deployments with short retention needs.Login failures are persisted by default in recent releases, so database growth and log volume both rise. Confirm retention, storage sizing and the event types in scope.
Security release cadenceScheduled upgrade windows tied to each published minor release, with a staging realm test before production. Fits teams with change control and audit obligations.Upgrade when needed, with no fixed window. Fits short-lived or low-exposure environments only.Upgrade effort recurs with each minor release. Read upgrade notes for changes such as enforced SMTP StartTLS and mandatory backchannel logout signature validation.

How to harden Keycloak in sequence

This sequence moves a Keycloak deployment from default-open settings to a server where transport is encrypted, administration is isolated from public traffic, and sign-in abuse, token lifetimes, audit trails and patching are each set deliberately and checked. Each step builds on the one before it, so the order matters.

  1. Enforce TLS on the edge and between components

    Start by putting TLS on every hop: browser to the reverse proxy, proxy to Keycloak, and Keycloak to the database and any directory or external identity provider it calls. Keycloak's production guide expects TLS on all communication, so the platform team issues certificates from the organization's chosen authority, configures the server with those certificates and disables plaintext listeners that are not needed. Confirm the result by requesting the public login URL over plain HTTP and checking that it redirects or is refused, then inspecting the certificate chain and protocol version presented on the HTTPS endpoint with an external scanner or openssl s_client.

  2. Separate the admin console from public endpoints

    Keycloak's production guide recommends exposing the admin console and the Administration REST API on a different hostname or context path from public frontend URLs. Decide the admin hostname, set it as the admin URL in the server configuration, and restrict who can reach it at the network layer, for example through a private network path, VPN or allow-listed addresses. The check is simple and should be repeated after every configuration change: request the admin console and admin REST path from the public hostname and confirm the request is refused, then confirm the admin hostname loads for an authorized administrator.

  3. Write reverse proxy path rules for required endpoints only

    Once the admin surface is separated, configure the reverse proxy to forward only the paths the public needs: the realm endpoints for sign-in, token, certificate and discovery documents used by your clients, plus static resources the login pages require. Deny everything else by default, including the management interface, metrics and any admin path on the public hostname. The security or platform engineer owns the rule set and keeps it in version control. Verify it with a path inventory: request each denied path through the public hostname and confirm refusal, and request each required path and confirm success for a sample sign-in flow.

  4. Set brute force detection and password policies

    In each realm, enable brute force detection and set its thresholds, wait times and lockout behavior to match the organization's risk tolerance and help desk process, since locked-out users generate support load. Then define the password policy: length, character rules, banned values and history, applied to the users and credential types the realm actually uses. If user federation or external identity providers hold the password, confirm which settings apply there instead. The check is an automated test: make repeated failed sign-ins against a test user in a non-production realm and confirm the account is locked as configured, then confirm the lockout clears as expected.

  5. Set token and session lifetimes per client type

    Review access token, refresh token, SSO session and client session settings for each client, rather than accepting one realm-wide value for everything. A public browser single-page application, a confidential server-side web application and a backend API have different exposure and usually need different lifetimes and refresh behavior. Record the chosen values alongside the business reason for each, and have the application owners confirm that their sign-out and session expiry behavior matches. Verify by decoding a sample token from each client type and confirming its lifetime and claims match the record.

  6. Enable event and admin event auditing

    Turn on user event logging and admin event logging for the realms in scope, and decide where events are stored and how long they are retained according to your audit and retention requirements. Confirm that login failures are persisted: the 26.8 upgrade notes say login failures are persisted to the database by default, so check that setting in your version rather than assuming it. Also decide whether the metrics endpoint is enabled for monitoring, and keep it on the management interface behind the path rules from earlier. The check is a deliberate failed sign-in followed by a query or console review that shows the failure event and an admin change, such as a changed setting, appearing in the admin event log.

  7. Subscribe to security releases and plan the patch cadence

    Keycloak plans four minor releases a year and a major release every two to three years, and minor releases can carry security fixes, so the team needs a standing process rather than ad hoc upgrades. Subscribe to the project's release announcements and advisories, and if you run a supported distribution, follow that vendor's notices as well. Agree a patch window, a test realm or staging environment where each release is checked, and an owner for approving production changes. If you run the Keycloak Operator, use manual approval mode for operator updates, as the operator documentation recommends. The completion check is a written cadence with named owners and a dated record of the most recent release applied in each environment.

How hardening differs by deployment model

A single Keycloak node is the simplest model to harden and the easiest to weaken with small gaps. Everything in the production guide still applies: TLS on all communication, a reverse proxy with path restrictions, and the admin console and Administration REST API served on a different hostname or context path from public frontend URLs. With one node, the proxy usually sits on the same host, so hostname and path rules are the main isolation boundary.

  • Proxy: terminate TLS at the proxy or on the node, and allow only the public paths your applications need on the public hostname.
  • Admin path blocking: deny admin paths on the public hostname at the proxy, and test that a request to them fails from outside your network.
  • Management interface: keep the management port and /metrics off public interfaces, and enable metrics with --metrics-enabled=true only when a scraper on a private network reads them.
  • Database: use a supported production database, since the default dev-file database is for development only, and restrict the connection to the node's address.
  • Recovery: a single node has no failover, so restore testing and a planned maintenance window carry more weight.

Check that the admin hostname does not resolve publicly and that the proxy rules block admin paths on the public hostname before go-live.

What drives hardening effort and how to keep it down

This table lists the factors that change how much work a Keycloak hardening project takes, why each one matters, and how to reduce it. Read it before scoping, because most of the effort comes from repetition across realms, clients, hostnames and environments.

DriverWhy it changes effortHow to keep it down
Number of realms and clientsEach client needs its own redirect URI, token lifetime, PKCE and scope review, so effort grows with every client and realm.Create standard client templates for web, mobile and API clients and apply them through the operator or import files.
Public and admin hostnamesEach hostname needs its own TLS certificate, proxy rule and access check, and the admin console must sit apart from public endpoints.Keep the hostname count small, use one admin hostname per environment and confirm the production guide's separation pattern early.
Existing proxy and certificate toolingIf the reverse proxy and certificate issuance are already automated, work is mostly configuration. If not, teams build both from scratch.Reuse the existing proxy ruleset and certificate automation, and write one reviewed set of path restrictions that every environment shares.
User population with MFA or federated directoriesEnforcing MFA, WebAuthn or passkeys for many users, or testing LDAP and Active Directory federation paths, adds policy and recovery testing.Set one authentication flow policy per user group, pilot with a small group and document recovery codes before wide rollout.
Custom SPIs and themesCustom user storage providers, event listeners and login themes must be retested on every minor release and each security update.Limit customizations to what is needed, keep them in version control and include them in the regression suite for each upgrade.
Compliance evidence requirementsAssessors often ask for configuration exports, event logs, change records and proof of patch cadence, which take time to collect and format.Agree the evidence list before work starts, export realm configuration as code and send audit events to the logging system from the start.
Number of environmentsEach environment repeats TLS, proxy, realm and policy checks, and drift between them creates findings.Build one parameterized deployment and promote the same configuration through development, test and production.

Access control and secrets handling for the hardened setup

The controls in this section decide who can change a Keycloak realm, where credentials live and who can read operational data. Each card covers one control, and together they keep the hardening work from being undone by an over-privileged admin, a leaked secret or an open metrics port. Confirm the specifics of each control against your own security policy before you apply them.

Separate admin accounts

Give platform operators named accounts that are separate from the everyday accounts used to sign in to applications. Grant admin rights only through the built-in master realm roles that the team needs, and avoid one shared administrator account. Review who holds admin access on a fixed schedule and remove access when people change roles. Ask your identity team to confirm how admin accounts are provisioned and how MFA applies to them.

Keycloak admin docs

Least-privilege realm roles

Scope administration per realm so that a team managing one application cannot change another realm's clients, users or sign-in flows. Use realm-management client roles such as view-only roles for auditors and narrow manage roles for operators. Document which role maps to which duty, and check that service accounts used by automation hold only the permissions their job needs. Confirm this model with the teams that own each realm.

Network restriction for the admin hostname

Serve the admin console and Administration REST API on a hostname or context path that is separate from public frontend URLs, as the production guide recommends. At the reverse proxy or load balancer, limit that hostname to administrator networks, a VPN or a bastion, and block it from the internet. Test the restriction from outside the allowed network before go-live. Confirm the approved source ranges with your network security team.

Production guide

Database credentials and TLS keys outside images

Keep the database password, TLS private key and keystore passwords out of container images, Git repositories and plain configuration files. Supply them at runtime from your secrets manager or the platform's secret store, and restrict read access to the service account that runs Keycloak. Rotate the database credential under a documented procedure, and confirm how private keys are backed up and destroyed. Your security team should confirm the storage standard that applies to these secrets.

Database configuration

Metrics endpoint on the monitoring network

Keycloak exposes Prometheus-format metrics at /metrics on its management interface when metrics are enabled. Those metrics reveal login volumes, error rates and internal health, so keep the management interface off public routes and allow scraping only from the monitoring network. Verify that the public hostname does not forward /metrics. Confirm the scrape source addresses and the authentication approach with your monitoring team.

Metrics configuration

Client secret rotation

Confidential clients authenticate with secrets that should be rotated on a schedule and after any suspected exposure. Plan rotation so that the application can accept the new secret before the old one is removed, which avoids a sign-in outage. Record each client's owner, secret location and rotation date. Ask your application owners to confirm how each application stores and reloads its secret.

How to keep up with Keycloak security releases

Plan for four minor releases a year and treat each one as a security decision, not a routine upgrade. Since Keycloak 26.0, the project has planned four minor releases a year and a major release every two to three years, and it states that breaking changes in a minor release will be opt-in. That makes minor upgrades less risky than they once were, but it does not remove the need to read what changed. The current release is 26.8.1, published October 13, 2026. Your hardening baseline should name the version you run, the date you last reviewed it, and the version you intend to move to next.

Before each release, read the upgrade notes for the versions between your current build and the target, and look for changes that touch your hardening controls. The 26.8 notes, for example, enforce StartTLS for SMTP without plaintext fallback, require signature validation of backchannel logout tokens from external providers, and persist login failures to the database by default. Each of these can alter sign-in behavior, mail delivery or audit data. Test the upgrade against a copy of your realms in a non-production environment, with the same brute force detection, password policies, token lifetimes and event listeners you run in production. Confirm that your event and metrics pipelines still receive data after the upgrade. Ask your vendor or partner to confirm which settings in your environment depend on opt-in or deprecated features.

Decide in advance who owns the patch decision. Name one accountable owner in the identity team, someone who approves each upgrade window, and a second approver from security. The Keycloak Operator documentation strongly recommends manual approval mode for operator updates to avoid unintended automatic upgrades, so if you run on Kubernetes, keep that setting and record who approves each change. Document the time you need from release notice to production change, and agree on how quickly an out-of-cycle security fix must be applied. Your support arrangement, whether community or the Red Hat build of Keycloak, determines what patches you receive and how you get them, so confirm that with the provider before go-live.

What to monitor, back up and document after hardening

Hardening is not finished at go-live. The controls only stay effective if someone watches the signals they produce, restores from copies that match the running configuration, applies security releases on a schedule and keeps the baseline current. The cards below cover those ongoing tasks for a self-managed Keycloak deployment.

Login failures and admin events

Brute force protection only helps if someone sees the attempts it blocks. Review login failure events and admin console activity, such as realm, client and user changes, on a set schedule. Confirm that Keycloak 26.8 persists login failures to the database by default in your version, and that event storage and retention meet your log policy. Alert on bursts of failures against privileged accounts.

Production guide

Metrics from the management interface

Enable metrics with --metrics-enabled=true and scrape the Prometheus-format endpoint at /metrics on the management interface, never through the public frontend. Restrict who can reach that interface at the network level. Track login failure rates, request latency and cache health, and set alerts with thresholds your team has tested against normal traffic.

Metrics guide

Certificate expiry and TLS settings

TLS covers the proxy, the database connection and any outbound links to identity providers or the SMTP server. Track certificate expiry for every endpoint, including internal certificates that are easy to forget, and renew them well before they lapse. Recheck cipher and protocol settings after each upgrade, and confirm that SMTP still enforces StartTLS, which 26.8 requires without plaintext fallback.

Realm exports, database and proxy rules

Back up the database on the schedule your recovery targets require, and export realm configuration separately so clients, flows, roles and policies can be reviewed and restored. Keep the reverse proxy path rules under version control with the Keycloak configuration. A restore is only tested when someone has rebuilt the environment from these copies and logged in. Store backups in the client's infrastructure, encrypted, with access limited to the identity team.

Database guide

Upgrade tasks tied to release notes

Keycloak plans four minor releases a year, and breaking changes in a minor release are opt-in. Before each upgrade, read the upgrade notes for behavior changes such as signature validation of backchannel logout tokens, then test the realm against a staging copy. Decide in advance whether schema migration runs automatically at startup or manually, and for the Operator, keep manual approval mode so updates are applied on purpose.

Release update policy

Hardening baseline and evidence register

Keep a written baseline that records each hardening setting, its value, the reason for it and the owner who reviews it. Log every approved exception with an expiry date and a compensating control. Store evidence such as configuration exports, test results and change tickets alongside the baseline. DeployOpen can prepare this evidence for a compliance assessment, but it does not issue audit reports or attestations. Independent auditors and certification bodies do that work.

Questions teams ask about hardening Keycloak

How much effort does a Keycloak hardening pass take?

The effort depends mostly on how many realms, clients and custom flows the instance already has, and on how far the current setup is from the production guidance. A fresh single-realm deployment with a few clients is a much smaller job than a multi-realm estate with federated directories, custom authenticators and an admin console reachable from the internet. Ask any partner to break the estimate into TLS and proxy work, admin separation, password and brute force policy, token lifetime review, event logging and retesting, because each item scales differently. No effort figure is given here, so request one in writing from a scoped review of your own environment.

Can our own team harden Keycloak without a partner?

Yes, many teams do this in-house, provided they have people who understand TLS termination, reverse proxy rules, Keycloak realm settings and their own application token handling. The work is mostly configuration and verification rather than new code, but it crosses several teams, so the main risk is gaps nobody owns. A partner adds value when the team lacks recent Keycloak experience, needs an independent check before an assessment, or wants a fixed-scope retest. Compare the internal time each option consumes, including the people who must approve changes.

What does a hardening pass need from identity, network and application owners?

Identity owners decide password, MFA, lockout and session policies and confirm which realms and clients are in use. Network owners control DNS, certificates, load balancers, firewall rules and whether the admin hostname can be reached from outside the corporate network. Application owners must confirm redirect URIs, token lifetimes their apps tolerate, and how they store and refresh tokens. Each group should name a reviewer before work starts, because changes to the reverse proxy or client settings can break sign-in if approved late.

How long does it take to verify that the hardening worked?

Verification time depends on the number of realms, clients and sign-in paths, plus the test environments available. A useful check covers direct requests to the admin console and Administration REST API from the public hostname, certificate and TLS configuration, brute force lockout behavior, password policy enforcement, token expiry, event log output and metrics exposure. Ask for the verification plan as part of the written scope, and confirm whether retesting after fixes is included. No duration is stated here because it varies with the environment.

Will hardening break existing sign-ins?

It can, most often when proxy path rules block a URL an application still uses, when a client expects a token lifetime that has been shortened, or when a stricter password or lockout policy catches service accounts. Redirect URI and logout changes also surprise integrations. Reduce the risk by testing in a non-production realm that mirrors production clients, rolling out changes in stages, and keeping a documented rollback for the proxy configuration. Read the upgrade notes for each Keycloak release, since some security defaults change between versions.

What should we ask for in a written hardening scope?

A written scope should list the Keycloak version and deployment method, the realms and clients in scope, the environments covered, and each control area with the specific settings to be reviewed or changed. It should name the deliverables, such as a configuration record, change log, test results and a findings report, and state whether a retest is included. Ask who performs the work, who approves production changes, what access the team needs, and what happens to issues found outside the agreed scope. Clear exclusions prevent disputes later.

Does a hardening pass produce a compliance certification?

No. A hardening pass prepares configuration, evidence and records that auditors may review, but independent auditors and certification bodies issue any audit report or certification. Ask your assessor which evidence they expect for identity controls, such as password policy settings, MFA configuration, logging and change records, before the work starts so that the scope matches the assessment.

How DeployOpen scopes, hardens and hands over Keycloak

DeployOpen works on Keycloak security hardening inside your own infrastructure, from a written scope through testing to a handover your team can run. We configure, test and document the controls, then leave your identity and platform staff with the evidence and runbooks to keep them in place.

How we scope

  • Review the realms, public hostnames and admin paths currently exposed, and record which ones need to change.
  • Agree in writing which hardening areas are in scope, such as TLS, proxy rules, token lifetimes and event auditing.
  • Confirm the Keycloak version, database and deployment method, including whether the Keycloak Operator is in use.

How we build

  • Separate the admin console and Administration REST API from public frontend URLs, and enforce path restrictions at the reverse proxy.
  • Set brute force protection, password policies, token and session lifetimes, and event logging, then test each setting against sign-in flows.
  • Test the hardened realms in a non-production environment, including negative tests for blocked admin paths and failed logins.

How we hand over

  • Deliver a configuration record and runbook covering each hardened setting, its owner and the reason it was chosen.
  • Document the audit event coverage and where your team reviews login failures and admin actions.
  • Walk your identity and platform staff through the upgrade path, including reviewing upgrade notes before each security release.

How we support

  • Offer ongoing support, upgrades and continuous testing as a retainer if your team wants help keeping pace with releases.
  • Retest the hardened configuration after upgrades, configuration changes or new applications are onboarded.
  • Confirm support terms, response expectations and escalation paths in the written scope before work starts.

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.