Running Keycloak as a Windows service

Running Keycloak as a Windows service suits organizations that must keep identity on Windows Server. This page covers the setup sequence, the configuration decisions, and the point where Linux or containers are the safer host.

On this page

Can Keycloak run as a Windows service, and when should you choose it?

Yes. Keycloak can be installed as a Windows service using the kc.bat tools windows-service command, which wraps the server with Procrun, the Apache Commons service wrapper. Choosing this host is a question of standardizing your infrastructure, not of getting different features: the server behaves the same way whether it runs under Windows or Linux. The service model gives you what Windows administrators already rely on, namely start on boot, restart handling and management through the Services console and standard Windows tooling, so Keycloak sits alongside your other line-of-business services.

The production requirements do not change with the host. You still need TLS on all communication, a supported production database rather than the dev-file database, a reverse proxy with path restrictions, and the admin console and Administration REST API served on a separate hostname or context path from public frontend URLs. The same is true for the release cadence: the project plans four minor releases a year, and the current release is 26.8.1, so your Windows host must follow the same upgrade and testing discipline as any other. Confirm with your own team whether your Windows Server version and Java runtime are on the support list for the release you choose, because the Keycloak docs define the supported combinations, not Windows alone.

Choose Windows when your organization already operates Windows Server with mature patching, monitoring and backup processes, and when no container platform or Linux capacity is available to your identity team. Consider Linux or containers when you want images that are reproducible across environments, when your team already runs Kubernetes or OpenShift, or when you expect to automate promotion between environments. Those paths also make the config-as-code and upgrade-by-image-tag workflows easier to keep consistent. Ask your team who will own service accounts, certificates and Windows updates for the identity server, because those owners decide whether a Windows host stays supportable over several years.

Which Keycloak hosting option fits your estate

This table compares four ways to host Keycloak: a Windows service, a Linux virtual machine or bare metal host, a container runtime, and OpenShift or Kubernetes with the Keycloak Operator. Read each row against your existing platform skills and the operating work your team would keep, then confirm the open items with the vendor or in the Keycloak docs before you choose.

Host optionWhen it fitsWhat your team operatesConfirm before choosing
Windows service (kc.bat with Procrun)Windows Server estate where the identity team already runs services, patches and backups on WindowsJava runtime, Procrun service configuration, service account, system-wide KC_ variables, TLS files, reverse proxy and databaseSupported Windows Server and Java versions for your Keycloak release, and whether the Windows service tooling covers your startup options
Linux virtual machine or bare metalLinux-first operations, or teams that want a plain systemd-style service with fewer Windows-specific stepsOS patching, Java runtime, service unit, file permissions, certificates, backups and the Keycloak upgrade processSupported Linux distributions and Java versions in the Keycloak server guides, and the exact service manager steps you will use
Container runtime (Docker or Podman on a host)Teams that already build and deploy images, want the same artifact across environments, and can run a container hostImage build or pinning by tag, container host patching, environment variables, health checks, volumes and restartsImage tags and health endpoints for your release, and how your container host is supported in your environment
OpenShift or Kubernetes with the Keycloak OperatorClusters already in production, several Keycloak instances, or a need for declarative resources and automated realm importCluster operations, Operator lifecycle, routes or ingress, database, scaling and the operator approval policyOperator and cluster versions supported together, and whether the Operator fits your platform, since it does not run on Windows

How the Windows service, database and proxy fit together

Illustrative layout: users and applications reach the reverse proxy on the public hostname, which forwards only the public paths to the Keycloak service on the Windows host. The service runs under a dedicated service account, reads its system-wide KC_ variables at start, and connects to the external database across the internal network boundary. Check that the admin hostname or path is not reachable from the public side, and that the metrics endpoint on the management interface is open only to your monitoring host.

Illustrative layout of trust boundaries, hand-offs and admin and metrics paths.

Setup sequence for a Keycloak Windows service

This sequence takes a Keycloak server from a supported production database and Java runtime to a Windows service that starts on boot, serves its public hostname over TLS, and keeps the admin console on a separate hostname. Each step ends with a check you can run before moving on.

  1. Confirm database and Java runtime requirements

    Check the Keycloak database guide and the server installation requirements for the release you plan to run, before you install anything. Confirm that your database is one of the supported production options, such as PostgreSQL in the version range the guide lists, and confirm the Java runtime version the release requires. The dev-file database is for development only and cannot be used in production, so the Windows host must point at an external database from the start. Record the database host, port, and driver details in your build notes. Done when a written requirements checklist exists and your team has signed off on the database and runtime versions.

  2. Create a least-privilege service account

    Create a dedicated local or domain service account that the Keycloak service will run as, with no membership in administrator groups. Grant it read and execute access to the Keycloak installation directory and read access only to the TLS keystore and truststore files, plus write access to the log directory. Do not give it rights to other applications' data. Confirm the account can read the TLS material by logging in as that account and opening the keystore path with icacls or an equivalent check. Done when the account exists, its permissions are documented, and the read test succeeds without elevated rights.

  3. Set system-wide KC_ variables

    Set the configuration as system-wide environment variables prefixed with KC_ so the service reads the same values on every start. Cover the database settings (such as KC_DB, KC_DB_URL, KC_DB_USERNAME, and KC_DB_PASSWORD), the public hostname settings, the proxy settings if a reverse proxy sits in front, and the TLS keystore settings. Store the database password in a location the service account can read but other users cannot, and avoid putting it in shared scripts. Confirm the variable names against the configuration guide for your release. Done when a PowerShell session started under the service account lists every variable with the expected value.

  4. Run the optimized build step

    Run kc.bat build from the Keycloak installation directory so the server is built with the database and features you chose before the service starts. Running the build with the same variables set in the previous step ensures the optimized configuration is baked in. Watch the output for warnings about unsupported database choices, missing TLS settings, or feature flags. Done when the build completes without errors and the output confirms the database vendor you selected.

  5. Install the service with kc.bat tools windows-service

    Install the Windows service using the kc.bat tools windows-service command, which wraps the server in the Procrun service wrapper, and set the service to run under the least-privilege account you created. Enter the account credentials when prompted rather than placing them in a file. Review the generated service definition, including the startup type and the log file location. Done when services.msc or Get-Service lists the Keycloak service with the expected account and startup type.

  6. Start the service and check the health endpoint

    Start the service and watch the log file until the server reports that it is ready. Then call the health endpoint on the management interface and confirm it returns a healthy status, which shows that the server can reach the database and the TLS listener is up. If the health check fails, check the database connection string and the keystore path first, since those are the most common causes. Done when the health endpoint responds with a healthy status and the log shows no startup errors.

  7. Verify the admin console is only on the admin hostname

    Request the admin console from the public frontend hostname and confirm it is not served there, then open it on the separate admin hostname or context path you configured. Confirm the Administration REST API follows the same restriction. Check that the certificate presented on each hostname matches that name. This test proves that the production guide's separation of admin and public URLs is in place on this host. Done when the admin console loads only on the admin hostname and the public hostname refuses the admin paths.

Applying configuration changes to a running Windows service

Configuration changes are the most frequent and the easiest to reverse, but they still take effect only after the service restarts. Keycloak reads KC_ variables when it starts, so an edit made to a system-wide variable does nothing to the running process until the service is restarted. Treat each change as a numbered record: the variable name, the old value, the new value, and the time of the change.

  • Record the current state: Export the current KC_ variables and the service definition before editing, so you can restore the exact previous values.
  • Stop, change, start: Stop the service with the Windows Service Control Manager or sc.exe, change the system-wide variable, then start the service and wait for the startup log to show the server is ready.
  • Change one setting at a time: Apply one variable per window where possible, so a failure points to a single cause.
  • Test mail and logout: Keycloak 26.8 enforces SMTP StartTLS without plaintext fallback, so send a test password reset or account email from the realm settings. Also confirm that backchannel logout tokens from external providers validate, because signature validation is now mandatory.
  • Keep the previous values: Store the prior variable set with the change ticket so rollback is a restore, not a reconstruction.

After each change, confirm the admin console loads, a test user can sign in to a sample client, and the startup log has no new warnings about the changed setting.

Security controls for Keycloak on Windows Server

Running Keycloak on Windows Server puts the identity provider under the same host controls as any other Windows workload, plus Keycloak-specific settings for TLS, hostnames, metrics and secrets. The cards below cover the controls the Keycloak production guide expects you to set, and the checks to run after each one.

Service account rights and password handling

Keycloak runs as the Windows service under the account you assign, so that account defines what a compromised process can reach. Use a dedicated local or domain service account with read access to the Keycloak install directory, write access only to the data and log paths it needs, and no membership in administrator groups. Confirm how the password is stored and rotated, and that interactive logon is denied to the account.

Keycloak production guide

Keeping secrets out of plain-text files

Database passwords, the bootstrap admin credentials and keystore passwords should not sit in plain text in service scripts, batch files or the conf file in a shared folder. Set them as system-wide KC_ environment variables scoped to the service, or load them from a secret store your team already operates, and restrict read access on the configuration directory to the service account and administrators. Check the file ACLs after every change.

Keycloak production guide

TLS on all communication

The production guide calls for TLS on all communication, so the Windows host should serve HTTPS with a certificate issued for the public hostname, and database connections should be encrypted where the driver supports it. Keep keystore and truststore files outside the public web root, set their passwords through protected configuration, and test the chain from a client machine that does not trust the internal CA by default.

Keycloak production guide

Admin console on a separate hostname

The production guide recommends exposing the admin console and the Administration REST API on a different hostname or context path from public frontend URLs. On Windows this usually means a reverse proxy or IIS rule that serves the admin paths only on an internal name, with public paths for login and token endpoints. Verify from outside your network that the admin console is unreachable, and confirm the separate admin hostname in the server settings.

Metrics exposure on the management interface

Metrics are exposed at /metrics on the management interface only when the server starts with --metrics-enabled=true. Enabling metrics on Windows does not expose them publicly by default, but the reverse proxy or Windows Firewall rules must keep the management port reachable only from your monitoring servers. Decide which histograms you need before enabling the optional request and cache metrics, since they add series to your monitoring store.

Keycloak metrics guide

Patching and change control

Windows updates and Keycloak releases both change the server, and they should go through the same change process. Test each Keycloak release on a copy of the production realm and database before the Windows service restarts, and read the upgrade notes for each release, since the 26.8 notes changed SMTP and backchannel logout behavior. Keep the previous install folder available for rollback, and record which Keycloak version and Windows build each host runs.

Keycloak upgrading guide

Why Linux or containers are often the better Keycloak host

Choose Windows when Windows is already the standard for your operations. A Windows service makes sense when your team already patches, monitors, backs up and audits Windows Server every day, holds the skills to troubleshoot it, and has tooling for service accounts and Group Policy. The trade-off is that you own the service model: the Procrun wrapper, the service account, the system-wide KC_ variables and the restart behavior all become your responsibility, and you will assemble your own standard for rollouts and rollback. If your organization accepts that work, a Windows host can run Keycloak well. Confirm the current support statements for Windows hosts in the Keycloak documentation before you commit, because the project's primary deployment paths are not built around Windows.

Linux hosts and containers match the paths the Keycloak documentation describes most fully: the optimized container image, the Operator installed through Operator Lifecycle Manager, and Kubernetes or OpenShift clusters. These paths give you versioned image tags, declarative configuration, standard health checks and a repeatable way to roll one node at a time during an upgrade. The Operator documentation also recommends manual approval for operator updates, which pairs well with a release process you already run for other workloads. Platform teams that already operate clusters usually find that Keycloak fits their existing pipelines with less custom work than a Windows service requires.

Compare the two options against your own operating model, not against a general ranking. Ask who will patch the host, how a Keycloak release gets tested and promoted, how you will roll back a failed upgrade, and whether the team that gets paged at night knows Windows service recovery or container orchestration. Write those answers down and map each one to the work it creates on each host type. Then check the Keycloak upgrade and high availability guides against your chosen design, since clustering and database requirements apply regardless of the host.

Limits to confirm before you commit to Windows

A Windows host for Keycloak is workable only if several things hold at once: the release, the Java runtime, the database, the service wrapper and the high availability design all have to fit together. Confirm each limit in your own environment before you write the Windows build into a plan.

Windows Server and Java support

Confirm that the Windows Server version you run and the Java runtime you plan to install are both supported for the exact Keycloak release you intend to deploy. Support matrices change between releases, so check the release notes for the version you pick rather than the version you already run. Record the Java version in your change ticket, because a runtime upgrade can break the service even when Keycloak itself has not changed.

Current release
26.8.1
Upgrading guide

Procrun behavior through restarts

The Procrun service wrapper controls how Keycloak starts, stops and recovers after a reboot or a failed process. Test a planned reboot, an unplanned process crash and a Windows Update restart in a non-production environment, and confirm the service returns to a healthy state without manual steps. Confirm who has rights to start and stop the service, and how the service account is handled when the password rotates.

Database driver and supported version

Keycloak's supported production databases include PostgreSQL 14 to 18, and the dev-file database is for development only. Confirm that your Windows-hosted instance can reach the database over the network with a supported driver, and that the database version is inside the supported range for your release. Check where the database runs, because a database on the same Windows host adds backup and patching work that a separate database service does not.

Database guide

High availability designs on Windows

The documented high availability designs require a synchronously replicated database and a clustering approach the Keycloak project tests. Confirm whether your Windows hosts, network, load balancer and database platform can meet those designs, including node discovery, failover and availability zone placement. If the only Windows option is a single node, record that as a single point of failure and agree on the recovery time with the business owner before go-live.

High availability overview

Red Hat build support terms

If you plan to use the Red Hat build of Keycloak rather than the community release, confirm which Red Hat support terms, supported platforms and subscription entitlements apply to a Windows host. Support coverage for a given operating system is not implied by the product name, so ask Red Hat in writing which Windows configurations it covers and which it excludes. Also confirm the version the subscription covers, since the product page and the community release can differ.

Red Hat build page

Moving to a newer release

Each Keycloak minor release can change defaults and add enforced behavior, so a Windows deployment needs a repeatable upgrade path, not a one-time install. Confirm how you will stop the service, back up the database, replace the distribution, apply the configuration build and restart, and how you will roll back if the migration fails. Ask who tests the upgrade against your own realms and clients before it reaches production.

Questions buyers ask about Windows service deployments

What drives the cost of a Keycloak Windows service build?

Cost follows the number of decisions and environments to set up, more than the install itself. The main drivers are how standardized the Windows Server hosts already are, which supported database you connect to and who owns it, how TLS certificates are issued and renewed, how the reverse proxy and hostnames are configured, and how upgrades are tested and approved. Each of these can be one-time work (build, configuration, documentation) or recurring work (certificate renewal, patching, each Keycloak release). Ask any provider to split the quote into build and recurring items, and to state who performs each task, your team or theirs.

How long does a Keycloak Windows service deployment take?

Duration depends on scope, so no fixed figure applies to every estate. The timeline is shaped by the number of environments (development, test and production), how quickly the database and certificates are provided, whether a change window is needed, and how many realms, clients and identity providers must be configured and tested. A single production node with a ready database and certificates moves much faster than a multi-node estate that needs proxy changes and approval cycles. Ask for a timeline that lists each dependency and the party responsible for it, so delays are visible early.

What must our internal team provide for a Windows service build?

Your team supplies the environment and the approvals that no outside party can grant. Typically this means Windows Server administrators who can prepare the hosts and the service account, a database owner who provisions a supported production database and its credentials, a certificate process that issues the TLS certificate and trust chain, and a named contact who can book a change window for production. Someone must also own the hostname and DNS records that users will sign in through. Agree these responsibilities in writing at the start, because missing inputs are the most common cause of schedule slips.

Can our team deploy Keycloak as a Windows service without a partner?

Yes, a team with Windows Server and identity experience can do this alone, especially for a small, low-risk estate with one or two nodes, a supported database and standard certificates. The Keycloak documentation covers the installation, the production configuration and the database setup, and it is the main reference for the work. Plan for time to test the configuration, document how the service is run and recover from failure, and rehearse an upgrade before you need one. Consider a partner when the estate is large, the hosts are inconsistent, or the team has no one who can own the service after go-live.

What does a fixed-scope Keycloak Windows service engagement cover?

A fixed-scope engagement covers the work listed in an agreed written scope, with deliverables and timelines confirmed before work begins. For a Windows service build, that scope typically names the Windows hosts, the Keycloak release to install, the database and TLS configuration, the reverse proxy and hostname settings, the service account setup, the production configuration changes, the testing performed, and the documentation handed over. Anything outside that list, such as additional realms or identity providers, would be quoted separately. DeployOpen does not publish a price list, so a quote follows from the written scope.

Why does a Windows-hosted Keycloak need an upgrade plan from day one?

Keycloak ships new releases on a regular cadence, and each upgrade can change the database schema and default behavior. The project plans four minor releases a year, and its 26.8 upgrade notes include changes such as enforced SMTP StartTLS and mandatory signature validation for some backchannel logout tokens. On a Windows service, the upgrade procedure, the rollback path and the database backup must be written down and tested before production changes. Read the upgrading guide for each target release and schedule the work as recurring operations, not a one-time task.

How DeployOpen scopes and delivers a Keycloak Windows service

DeployOpen plans, builds, documents and supports self-hosted Keycloak inside your own Windows Server environment. We start from a written scope that states which Windows hosts, service accounts, database and upstream identity sources are included, so you know what is delivered before work begins.

How we scope

  • Written scope lists the Windows Server hosts, Keycloak version and database that the service will run on.
  • Scope names the service account model, the KC_ system variables and the hostname and TLS settings to be configured.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.

How we build

  • We install Keycloak with the windows-service tooling and configure Procrun-based service startup, restart and logging.
  • We apply configuration changes through a tested runbook, with the service stopped and restarted in a defined order.
  • We test sign-in, admin console access, health endpoints and the database connection on each target host before handover.

How we hand over

  • You receive a build record covering the installed version, service settings, system variables and database connection details, with secrets held outside the documents.
  • We provide an operations runbook for patching, configuration changes, service restarts and recovery from a failed start.
  • We document where Linux, containers or Kubernetes would be a better host, so future platform decisions have a written basis.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers for Windows-hosted Keycloak.
  • Upgrades follow the Keycloak release cadence, with a staging run that checks database migration and service startup first.
  • Retesting after configuration or version changes confirms that sign-in, token issuance and admin access still behave as documented.

Sources and further reading

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.