Keycloak as an authentication server for a Docker registry

Keycloak can issue the tokens that control who pushes and pulls images on a self-hosted Distribution registry. This page covers the setup, the settings that must match, and the decisions to make before rollout.

On this page

Keycloak as an authentication server for a Docker registry: when teams need it

If you run a self-hosted Distribution registry and want one identity system to control who can push and pull images, Keycloak can act as the token server for the registry using the Docker v2 auth protocol. The feature is disabled by default, so it has to be enabled deliberately before the registry will hand authentication to Keycloak. This page covers the decision to use Keycloak for registry access, the realm and token settings that connect the two systems, and the operational checks that follow. It does not cover general Keycloak installation, client design for other applications, or the features of the registry itself beyond its authentication configuration.

Keycloak fits when your organization already uses it, or plans to, as the workforce identity system for other tools, and you want registry access tied to the same users, groups and sign-in policies (such as MFA) instead of a separate password file or a static credential shared among build systems. The registry delegates each request to Keycloak, which issues a short-lived token scoped to the repository actions the user or service account is allowed to perform. Other approaches are simpler where image access is small and self-contained, such as the registry's built-in htpasswd authentication, or where your platform already brokers registry access through a cloud or Kubernetes identity system. Confirm which approach your CI runners, Kubernetes nodes and developer workstations can actually use before choosing, because each client must support the token flow that Keycloak presents.

Before you commit, confirm three points with your team: which realm will hold registry users and clients (the guide advises a realm other than master for the Compose setup), whether your build systems can use service accounts with the token flow, and who owns the realm's signing key, since the registry must trust the realm's public key through its root certificate bundle. Check the current feature and configuration details in the Keycloak distribution registry guide and the Keycloak feature documentation for your target release before you plan the rollout.

How a Docker login becomes a registry token

The flow starts when a Docker client asks the registry for a resource without credentials. The registry answers with a 401 challenge that points the client to Keycloak's Docker v2 token endpoint under /realms/<realm>/protocol/docker-v2/auth. After the user signs in, Keycloak issues a token signed with the realm key, and the client presents it back to the registry. The registry checks that token against the realm public key in the rootcertbundle, so verify that the bundle matches the realm you configured.

Docker login and pull flow between client, registry and Keycloak, with trust zones marked.

Set up Keycloak as the registry's token server

This sequence takes a Keycloak instance and a self-hosted Distribution registry from separate components to a working token flow, where Keycloak issues the tokens that the registry checks on every push and pull. Each step ends with a check so the team can confirm the setup before moving on.

  1. Confirm versions, hostnames and trust boundaries

    The platform team records the Keycloak version, the Distribution registry version, and the public hostnames for both services before any configuration changes. Keycloak should be reachable over TLS at its own hostname, and the registry should have its own hostname that clients use for docker login, docker push and docker pull. Confirm that the Keycloak admin console is not exposed on the same public path as the token endpoint, following the production guidance for admin access. Done when the team has a written record of both hostnames and versions and both services resolve and present valid certificates from the client network.

  2. Create a dedicated realm outside master

    An administrator creates a new realm for registry access and does not use the master realm. The master realm holds Keycloak's own administrative accounts, so keeping registry users and clients out of it limits the blast radius of a registry misconfiguration. Name the realm for its purpose so that later audits can trace which tokens it issues. Done when the realm appears in the realm list, has its own login page at its realm path, and contains no users yet.

  3. Create the registry client and its scopes

    Inside the new realm, the administrator creates a client that represents the registry service and sets the client identifier to the service name the registry will declare in its config. Add users or groups that should receive push or pull access, and define the repository scopes the team needs, such as pull and push permissions on named repositories. Keep scopes narrow so that a token for one project cannot write to another. Done when a test user can be listed under the realm and the client shows the scopes the team intends to grant.

  4. Enable the docker-v2 authentication feature

    Docker authentication in Keycloak is disabled by default, so the administrator enables the docker-v2 feature on the Keycloak server through its startup configuration. Restart Keycloak using the chosen deployment method and confirm the feature is active before continuing. The check is that the token endpoint at the docker-v2 auth path of the realm responds to an unauthenticated request with a challenge rather than a 404 response. Record the exact feature flag and the Keycloak version in the change record, because feature state can change between releases.

  5. Configure the registry's auth token settings

    The platform team edits the registry configuration to declare token authentication. The auth.token block needs the realm, the service name that matches the Keycloak client, and the issuer value that matches the issuer Keycloak places in the tokens it signs. Use the realm URL form from the Keycloak registry guide and copy the issuer string exactly, including scheme and path, since a mismatch will reject every token. Done when the registry starts without configuration errors and its version or health endpoint responds.

  6. Point rootcertbundle at the realm's public key

    The registry verifies token signatures with the realm's public key, so the team downloads the realm certificate from Keycloak's realm keys information and saves it as a PEM bundle in the path set by rootcertbundle. Confirm the key ID in the bundle matches the active signing key in the realm, because rotating the realm key later requires updating this file. Restart the registry and check its logs for a clean load of the bundle. Done when the registry starts and logs no certificate parsing errors.

  7. Test login, push and pull in order

    Run docker login against the registry hostname with the test user, then push a small test image to a repository inside the scope granted to that user, and pull it back from a second clean host or a cleared local cache. Test one denied case as well, by pushing to a repository the user does not have rights to, and confirm the registry refuses it. Each of the three positive tests and the negative test should produce an expected result before the setup is accepted. Keep the test output with the change record.

Registry token settings and when each choice fits

The realm is the namespace that holds the registry's users, clients and signing keys, so it is the first decision to make. The Keycloak distribution registry guide advises using a realm other than master for the Compose setup. The master realm holds the Keycloak administrator accounts, so tokens issued from it would share a trust boundary with the people who run the identity server. A dedicated realm lets you give registry users and service accounts their own signing key, login policy and delegated administration. The realm name also appears in the token endpoint path, so a wrong name sends Docker clients to an address that does not issue registry tokens.

  • Blast radius: A compromised registry client or user stays inside a realm that carries no server administration rights.
  • Separate keys: Each realm signs its own tokens, so the realm choice also decides which certificate the registry must trust.
  • Login policy: Brute force, password and MFA settings can be tuned for registry users without touching the administrator realm.
  • Stable naming: Pick a name you will not need to change, because it appears in the endpoint path and in the registry configuration.
  • Single realm per registry: Keep one realm for the registry unless you have a reason to share it with other services.

Check that the realm in the endpoint path, the registry's realm setting and the certificate you deploy all refer to the same realm.

Why the master realm is a poor home for registry identities

The master realm holds the administrative identities that manage the whole Keycloak server, so it should not also hold the users and service clients that pull and push images. The Keycloak distribution registry guide advises a realm other than master for the Compose setup, and the reason is separation. Administrators who can create realms, change clients and read signing configuration should be a small group with strong controls. Registry users are a much larger and more changing population, often including CI pipelines and developer accounts. Mixing them means every registry account sits next to administrative power, and a compromised CI credential is one step closer to the server's control plane.

Blast radius is the second argument. A registry client in the wrong realm can be misconfigured in ways that grant tokens to the wrong scopes, and a mistake in the master realm affects the administrative surface of the entire Keycloak instance. In a separate realm, a broken token mapper, a permissive redirect setting or a bad client scope affects only the registry and the users who depend on it. Before go-live, confirm which clients, roles and identity providers exist in the realm you choose, and test that a registry user cannot reach any administrative endpoint from the same token.

Signing key scope is the third. The registry trusts the realm's public key through the rootcertbundle setting, and the tokens it accepts are signed by keys belonging to that realm. A dedicated realm lets you plan key rotation, algorithm choice and certificate handling for the registry without affecting administrative sign-in or other applications. Confirm with your security team how keys are rotated in that realm, how the registry picks up a new certificate bundle, and how you will revoke trust quickly if a key is exposed. Record these answers as part of the registry runbook before the first push.

Security considerations for registry token issuance

Keycloak decides who can push and pull images, so the token endpoint, the signing key and the admin surface all sit on the registry's access path. The cards below cover the controls that keep that path trustworthy, from transport and network separation to key protection, scope design, token lifetimes and monitoring.

TLS on all communication

Keycloak's production guidance calls for TLS on every connection, so the Docker client, the registry, the token endpoint and the realm certificate path should all be encrypted. Docker clients reach the token endpoint directly during login, so a plaintext hop lets credentials and issued tokens be intercepted. Check that the reverse proxy in front of Keycloak terminates TLS with certificates your clients trust, and that the registry URL and the token realm URL use the same trusted chain.

Keycloak production guide

Separate admin and public hostnames

Keep the admin console and the Administration REST API on a different hostname or context path from the public frontend, including the docker-v2 token endpoint that registry clients call. Route only the paths registry clients need through the public proxy, and restrict admin paths to management networks. Confirm with a test request from outside your admin network that admin paths do not answer on the public name.

Keycloak production guide

Protecting the realm signing key

The registry trusts tokens only if they verify against the realm's public key, so the private key that signs them is the most sensitive asset in this setup. Restrict who can export or rotate realm keys, keep admin accounts for the realm limited, and record key changes in your audit trail. After any rotation, update the rootcertbundle file on every registry instance and confirm that old tokens are rejected where you expect.

Least-privilege scopes for push and pull

Registry tokens carry repository scopes such as pull or push on a named repository, so define client roles and user groups that grant only the actions each team needs. Give CI pipelines push rights to their own repositories rather than shared namespaces, and give most users pull rights only. Test a denied push and a denied pull for each group before go-live, because a broad scope is hard to notice once it is granted.

Token lifetime choices

Choose registry token lifetimes that balance interactive convenience against exposure if a token leaks. Short lifetimes limit how long a stolen token works, while very short lifetimes force frequent re-authentication for long pushes. Document the lifetime you chose, confirm it in the realm token settings, and ask whether revocation of an issued registry token is possible before it expires, since your incident response depends on that answer.

Monitoring token issuance with metrics

Start Keycloak with metrics enabled so that Prometheus-format data is exposed at /metrics on the management interface, and limit that endpoint to your monitoring network. Track token request volume and failure rates for the registry client, and alert on sudden spikes in failed logins, which can indicate credential guessing. Confirm which metrics your version exposes before building dashboards.

Keycloak metrics guide

Operating the registry and Keycloak together

What happens to pulls and pushes when Keycloak is down?

Docker clients cannot get a registry token while Keycloak is unavailable, so new pulls and pushes fail at token issuance rather than at the registry itself. Clients that already hold a valid token can keep working until it expires, and the registry's own availability is separate from Keycloak's. Plan for Keycloak's availability to match the registry's, and check the lifetime of the tokens you issue so you know how long a short outage stays invisible to users. Confirm the exact failure behavior in your Docker client versions and in your reverse proxy before you publish a service level for the registry.

How does Keycloak key rotation affect the rootcertbundle?

The registry checks token signatures against the public key in the file set as rootcertbundle, so a realm key change that is not reflected in that file causes token validation to fail. Before rotating a realm signing key, add the new certificate or key material to the bundle, roll the registry so it trusts both keys, and only then retire the old key in Keycloak. Automate the copy from the realm's key endpoint if you rotate often, and test the sequence in a non-production realm first. Confirm the current key-management behavior in the Keycloak server administration guide for your version.

How do Keycloak upgrades interact with registry configuration?

A Keycloak upgrade can change realm defaults, token behavior and feature flags, so the registry's auth.token settings and the Docker v2 feature need a check after each upgrade. Read the upgrading guide for every minor release you cross, because the project's release process says breaking changes in a minor release are opt-in. Keep the registry's auth configuration in version control next to the Keycloak realm export, upgrade a staging copy first, and push a test image through the full login and pull path before moving production. The Keycloak upgrades group covers the database migration side of this work.

Does manual approval for operator updates apply on Kubernetes?

Yes, if you run Keycloak through the Keycloak Operator, manual approval mode is the setting the Operator documentation strongly recommends to avoid unintended automatic upgrades. Operator Lifecycle Manager controls this approval when the Operator is installed that way, so the approval step gates Keycloak version changes as well as Operator changes. If you install the Operator with kubectl or the experimental Helm chart, you need a different change-control process because the automatic approval path does not apply. Confirm the approval setting in your own cluster, since the registry token configuration must still be checked after every approved upgrade.

How should we test registry and Keycloak changes before production?

Build a staging stack that matches production in Keycloak version, realm configuration, TLS chain and registry version, then run every change there first. A useful test set covers a successful push and pull with a user in the intended realm, a denied pull for a user without the right role, a token request after a signing key change, and a pull after a Keycloak restart. Keep the realm definition in a version-controlled export so the staging and production realms stay comparable. Use a non-master realm for the registry in both environments, as the registry guide advises for the Compose setup, so test users and clients never touch the admin realm.

What should we ask a partner to cover in day-two operations?

Ask for a written scope that names the runbooks, the change process for realm and registry settings, the monitoring and alerts, and the procedure for key rotation and upgrades. Confirm whether the partner tests each change in staging, how they record configuration changes, and who approves a production change. DeployOpen plans, implements, upgrades, documents and supports self-hosted open-source platforms in your own infrastructure, and most engagements are fixed-scope with agreed deliverables. Ongoing support and upgrades are available as retainers, and a quote follows from the written scope.

Limits to confirm before you commit

The Docker registry integration with Keycloak is narrower than general Keycloak sign-in, and several settings sit outside the defaults. The cards below cover the switches, versions and configuration points to confirm against the Keycloak guide before you commit a design.

Docker authentication is off by default

Keycloak ships with Docker v2 authentication disabled by default, so the registry token endpoint does not exist until you turn the feature on. Confirm which feature flag your Keycloak version expects for the docker-v2 setting in the features guide before you write the server configuration. Test a push and a pull with a real account after enabling it, because a missing flag tends to fail quietly at the first login rather than at startup.

Keycloak features guide

Registry version and auth settings

The registry must accept token authentication, and its auth.token block needs the realm, service and issuer values that match your Keycloak realm. Check the registry version you run against the Keycloak guide, since option names and token handling can change between releases. Record the exact values in version control so a reviewer can compare them with the guide during a security review.

Distribution registry guide

The docker:v1 option is separate

Keycloak also supports a docker:v1 feature, and it is disabled by default as well. It is a separate option from the docker-v2 path, so enabling one does not give you the other. Decide which protocol your registry clients need, enable only that one, and confirm the choice in the features guide before rollout.

Features and flags

Compose setup is the documented path

The registry guide's walkthrough uses a Docker Compose setup, and it advises a realm other than master for that layout. Other deployments, such as Kubernetes, a virtual machine or a registry behind a shared proxy, need their own validation of the realm certificate bundle (rootcertbundle), hostnames and token lifetimes. Plan a test environment that mirrors your production network path before you copy the Compose pattern.

Retest at every Keycloak upgrade

Keycloak plans four minor releases a year, so the authentication setup for the registry will be exposed to upgrades regularly. Each upgrade can change feature defaults, realm key handling or the way tokens are validated. Keep a repeatable test that pushes and pulls an image with a non-admin user, and run it after every Keycloak and registry upgrade before the change reaches production.

What buyers ask about Keycloak registry authentication

What drives the cost of setting up Keycloak as a Docker registry auth server?

The main cost drivers are the scope of the registry and Keycloak environments, the number of realms and clients, and how much testing the rollout needs. A single registry with one realm, one client and a Compose stack is a small, bounded job. Each additional realm, client, registry instance, identity source or site adds design, configuration and verification work. Testing needs also move the number: token flows for pushes and pulls, certificate rotation and failure paths take time to verify. Ask any partner for a quote built from a written scope that lists each registry, realm, client and environment, plus the test cases they will run. Ongoing support and upgrades are separate costs that recur. DeployOpen does not publish a price list, and a quote follows from the agreed scope.

How long does it take to implement Keycloak registry authentication?

The timeline depends mainly on the infrastructure that already exists. A team with a running Keycloak, a registry on hand and a Compose setup can move faster than one that must first deploy Keycloak, provision TLS certificates, set up a database and wire up a Kubernetes or multi-site layout. Identity source decisions, such as whether users come from Keycloak directly or from an upstream directory, also shape the schedule. Ask for a timeline tied to named milestones in the written scope: environment readiness, Keycloak realm and client setup, registry configuration, test pushes and pulls, and cutover. Avoid any timeline that does not state its assumptions about existing systems.

What does our team need to provide before the work starts?

Plan to provide the items the registry and Keycloak depend on. Typically this includes:

  • The public hostnames for Keycloak and the registry, and the DNS records that point to them
  • TLS certificates for both hostnames, or a certificate authority your team uses to issue them
  • Access to the cluster, virtual machines or Compose host where the services run
  • Details of the identity sources, such as existing users, LDAP or Active Directory, or an upstream identity provider
  • Decisions on realm naming, client ownership and who may push and pull to each repository

Confirm the exact list with your own platform and security teams, because network rules, certificate issuers and change windows differ by organization.

Can our own team set up Keycloak registry authentication without a partner?

Yes, for a single Compose setup, a capable team can follow the Keycloak distribution registry guide, enable the docker-v2 authentication feature, configure the token settings and install the realm certificate bundle. The feature is disabled by default, so the team must turn it on deliberately. A multi-site or clustered registry is harder. It adds certificate distribution across sites, database and high availability choices, token behavior under failover, and more places where configuration can drift. Teams that lack Keycloak or registry operations experience often benefit from a partner for design and testing. Assess your team's experience with both products, and decide which parts you want to keep in-house.

What changes for our team after go-live?

After go-live, the team takes on routine operation of both systems. That includes Keycloak upgrades, since the project plans four minor releases a year and says breaking changes in a minor release are opt-in, and the registry version and its settings. Certificates need renewal and the realm certificate bundle must stay aligned with the realm's keys when those change. Client and user changes in Keycloak, and changes to who can push or pull, become ongoing administration tasks. Monitoring should cover token issuance and registry errors. Ask a partner whether they offer a retainer for upgrades, certificate work and periodic testing, and confirm which of these your team will own.

Does DeployOpen issue audit reports or certifications for our Keycloak registry setup?

No. DeployOpen does not issue audit reports, attestations or certifications. Independent auditors and certification bodies perform those assessments. DeployOpen can prepare the systems, configuration and evidence that an assessment will examine, such as documented authentication settings, access control for pushes and pulls, realm separation and test results. Your auditor decides what evidence it needs, so confirm those requirements with them before the work starts. Ask any partner to state clearly which parts of the work produce evidence and which parts are the auditor's responsibility.

How DeployOpen scopes and delivers Keycloak registry authentication

DeployOpen treats Keycloak as an authentication server for a self-hosted Distribution registry as a scoped, documented piece of infrastructure inside your own environment. We begin with the registry, realm and client decisions, then build, test and hand over the token flow, certificate handling and operating runbook for your team.

How we scope

  • Engagements are fixed-scope, with the registry, realm, token settings and access rules agreed in writing before work starts.
  • We confirm which push and pull actions each team, service account and CI job needs, and map them to registry access scopes.
  • We record which Keycloak version, database and hostnames the registry integration will run against, so the scope matches your environment.

How we build

  • We enable the Docker v2 authentication feature in Keycloak and confirm the token endpoint is reachable from registry and client networks.
  • We configure a dedicated realm outside master, with registry-specific clients, and set the auth.token realm, service and issuer values.
  • We wire the realm public key into the registry trust bundle and test pushes and pulls for each role in the agreed scope, including denied cases.

How we hand over

  • You receive configuration documentation covering realm, clients, token settings, certificate bundle location and the steps to rotate the realm key.
  • We deliver a test record showing authenticated and unauthorized push and pull results, so your team can repeat the checks after changes.
  • Handover includes a runbook for adding users, changing registry access and recovering from a broken trust bundle or expired certificate.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers, covering Keycloak version changes and registry updates.
  • Before each Keycloak upgrade, we review the release notes against the registry integration and retest token issuance and registry access.
  • Confirm with DeployOpen during scoping which support level, response arrangements and upgrade checks your retainer includes.

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.