OpenBao OIDC login with Keycloak

Set up OpenBao UI and CLI sign-in through a self-managed Keycloak realm, with the confidential client, redirect URIs, discovery URL and group-to-policy mapping planned before go-live.

On this page

How OpenBao OIDC login with Keycloak works

Operators who want people to sign in to OpenBao with the corporate identity provider, instead of handing out shared tokens or local passwords, need one decision settled first: the supported method is the OIDC auth method, with a Keycloak confidential client using the authorization code flow. Client authentication must be enabled on the Keycloak client so OpenBao can exchange the code with a client secret. A user opens the OpenBao UI or runs bao login -method=oidc, is redirected to Keycloak, signs in there, and returns to OpenBao through a callback. OpenBao then issues its own token, scoped by the policies mapped to the user's identity. The OpenBao guide for this setup is the best next read for the exact client settings: OpenBao Keycloak OIDC provider guide.

Two callbacks matter at this stage. The UI callback is /ui/vault/auth/oidc/oidc/callback, and the CLI callback is which the CLI uses to receive the response on the operator's own machine. The OpenBao mount also has to be configured with oidc_discovery_url, pointing at the Keycloak realm base URL (<KEYCLOAK_URL>/realms/<REALM-NAME>), because OpenBao appends /.well-known/openid-configuration to find the provider's metadata. If jwks_url` is set instead, the mount can only verify JWTs and cannot be used for interactive OIDC login, so confirm the mount type and settings before testing with a person's account.

Plan the redirect URI list before the first login attempt. The guide notes that most role errors come from allowed_redirect_uris not listing every redirect URI OpenBao may send, so each UI and CLI callback, including the Keycloak client's own valid redirect settings, should be enumerated and reviewed in both systems. Confirm the exact URLs against your OpenBao address, your Keycloak hostname and any reverse proxy or port changes in your environment, since a mismatch in scheme, host or path is the usual cause of failed sign-ins. Test the UI path and the CLI path separately, with a user who holds only the expected group, so a policy mapping error does not look like a redirect error.

What you need before configuring OpenBao and Keycloak

OpenBao OIDC login depends on three systems agreeing on addresses, trust and ownership before any role is written. The cards below cover what must exist and be settled first, so that redirect and discovery settings can be set once and reviewed cleanly.

A running OpenBao cluster

Confirm that the OpenBao cluster you will configure is reachable at a stable UI and API address, and that the people who will sign in can reach that address from their workstations. The OIDC redirect URIs depend on this address, so a change later means editing the Keycloak client again. Confirm the OpenBao version against the current release notes before you start, because the auth method documentation and behavior can change between minor lines.

OpenBao releases

A Keycloak realm with a known base URL

Identify the Keycloak realm that will hold your users and groups, and record its base URL in the form used for realm discovery. OpenBao appends the well-known configuration path to this base, so the realm name and host must be exact. Confirm the Keycloak release against the current release notes, since minor releases follow a planned cadence and some changes are opt-in.

Keycloak release updates

Administrator access to both systems

You need administrative rights in OpenBao to enable the JWT/OIDC auth method, write roles and policies, and in Keycloak to create a client, define groups and configure client scopes. Agree in advance who owns each side and who approves changes, because the client secret and group names are shared between teams. Record which accounts hold these rights so that access reviews can cover them later.

TLS trust between OpenBao and Keycloak

OpenBao must fetch the Keycloak discovery document and signing keys over HTTPS, and it must trust the certificate chain that Keycloak presents. Confirm that the CA bundle is available to the OpenBao nodes, including any private CA used by your organization, and test the discovery URL from every OpenBao node, not only from one workstation. Failures here often look like generic login errors, so check connectivity before debugging roles.

Keycloak database and high availability settled

Decide the production database and high availability design before you point OpenBao at Keycloak. Keycloak's supported production databases include PostgreSQL 14 to 18, and the development file database is not for production. Both supported high availability designs need a synchronously replicated database, and a change of database later affects the realm your OpenBao clients depend on. Record the chosen design and its failover behavior so that discovery and token issuance remain predictable.

Keycloak database guide

Group naming and ownership plan

Before you write any mapping, list the Keycloak groups that should map to OpenBao policies and agree on their exact names. Keycloak group membership reaches OpenBao only through the claims and roles you configure, so an unplanned rename breaks access silently. Decide which team owns each group, how new members are added, and who reviews membership, so that policy mapping follows a documented source of truth.

Configuring the Keycloak client and OpenBao OIDC mount

This sequence produces a confidential Keycloak client that OpenBao can use for authorization code login, an enabled OIDC auth mount pointed at the realm, and a role whose redirect list covers the UI and CLI callbacks.

  1. Create the Keycloak client with client authentication

    In the Keycloak admin console, the realm administrator creates a client for OpenBao in the realm that will hold your workforce users. Turn on client authentication so the client is confidential, and enable the standard authorization code flow. Keep the client secret in a location your team controls, since OpenBao needs it when the mount is configured. Done means the client appears in the realm with client authentication on, and the credentials tab shows a client secret you can copy into the OpenBao configuration step.

  2. Register the three OpenBao redirect URIs

    Add the redirect URIs that OpenBao uses to finish a login. OpenBao's Keycloak guide calls for URIs under /v1/auth/oidc/* on your OpenBao address, the UI callback at /ui/vault/auth/oidc/oidc/callback, and the CLI callback at Replace the host with your own OpenBao address and confirm each path against the guide before you save. Done means the client's valid redirect URI list contains all three entries, and each one matches the address your users actually open.

  3. Enable the OIDC auth method in OpenBao

    A platform administrator with a root or sufficiently privileged token enables the OIDC auth method at its default path, or at a path your team has chosen for the realm. Record the mount path, because the UI callback and the CLI login command both depend on it. Done means the auth method list shows the OIDC mount as enabled and the CLI command bao auth list returns it.

  4. Set the realm base URL as the discovery URL

    Configure the OIDC mount with oidc_discovery_url set to the Keycloak realm base URL, in the form https://<KEYCLOAK_URL>/realms/<REALM-NAME>. OpenBao appends the well-known configuration path itself, so do not add it. Set the client ID and client secret from step one at the same time. Avoid setting jwks_url in this mount, because the guide states that a mount configured that way can only verify JWTs and cannot run OIDC login. Done means the config read returns the discovery URL you set and no jwks_url value.

  5. Create a role with every redirect URI

    Create an OIDC role on the mount that defines the user claim, the scopes, and the allowed_redirect_uris list. Include the same three redirect URIs registered in Keycloak, including the UI callback and the localhost CLI callback. The guide notes that most role errors come from this list missing a URI, so compare it character by character with the Keycloak client. Done means reading the role back shows all three URIs, and the two lists match exactly.

  6. Verify login through the UI and the CLI

    Sign in to the OpenBao UI, choose the OIDC method, and complete the Keycloak prompt. Then run bao login -method=oidc from a workstation with the CLI, which opens a browser and returns to localhost on port 8250. Done means the UI session opens with the expected policies and the CLI prints a token with a matching identity. If the redirect fails, check the role's allowed_redirect_uris and the Keycloak valid redirect list first.

How Keycloak groups and claims map to OpenBao policies

This table lists the mapping decisions you make between Keycloak and OpenBao, from the identity claim through group matching to policy review. Read each row as a choice to settle before the OIDC role is written, because a mismatch at any step leaves a user signed in with the wrong access or with none. The main takeaway is that OpenBao policies are only as precise as the groups Keycloak puts in the token.

DecisionWhat to setWhy it matters
User identity claimChoose the token claim OpenBao uses as the entity name, and confirm it is present and stable for every user who signs inA claim that changes, such as a display name, creates duplicate identities and breaks policy assignment for existing users
Groups claim in the tokenAdd a groups mapper to the Keycloak client so the ID token or userinfo response carries group membership, then confirm the claim arrives in OpenBaoIf the groups claim is missing, OpenBao cannot match roles to group membership and the user receives only default policies
Group namingUse full group paths or a consistent naming scheme in Keycloak, and record the exact string OpenBao will matchNested or renamed groups change the value in the token, so a role that matched yesterday may silently stop matching
Mapping groups to rolesCreate one OIDC role per access tier and set bound claims or group membership rules so only matching users can use itBroad or unbound roles let any authenticated Keycloak user obtain a token, so each role needs an explicit restriction
Role to policy assignmentAttach the OpenBao policies that each role grants, keeping least privilege per team rather than one shared admin policyPolicy scope is the main control on what a signed-in user can read or change inside OpenBao
Redirect URIs in allowed_redirect_urisList every redirect URI the role may use, including the UI callback and the CLI callback on localhostThe guide notes that missing entries are a common source of role errors, so the role must cover each login path
Token lifetime and re-loginDecide how long tokens remain valid and whether group changes in Keycloak take effect at next sign-inGroup removal in Keycloak does not revoke a token already issued, so access can outlast a role change until the token expires
Review of policy assignmentAssign an owner for the group-to-role-to-policy map and review it on a fixed schedule with Keycloak group ownersMappings drift as teams change, and an unreviewed map is the most likely source of excess access over time

Where the trust boundary sits in the login flow

A reviewer placing the trust boundary needs to know that the user never hands a password to OpenBao. The browser or CLI starts an OIDC authorization code flow with the OpenBao oidc auth mount, which redirects the user to the Keycloak realm. Keycloak authenticates the user, including any MFA or federated directory it is configured to use, and sends the browser back to one of the three redirect URIs OpenBao generates: the /v1/auth/oidc/* endpoints, the UI callback at /ui/vault/auth/oidc/oidc/callback, or the CLI callback on localhost:8250. OpenBao then exchanges the returned authorization code with Keycloak using the confidential client secret, validates the ID token against the realm's published keys, and evaluates the role's claim and group mappings. The trust decision therefore sits in Keycloak for identity and in OpenBao for authorization.

The secrets that matter in this flow are the Keycloak client secret, held by OpenBao's auth mount configuration, and the OpenBao token it issues, which is stored by the UI or the CLI on the user's machine. The client secret never leaves the OpenBao side and should be treated like any other credential that OpenBao protects. The token does leave the network boundary in the sense that a browser or workstation holds it, so the policies attached to the token define the blast radius if the device is compromised. Reviewers should confirm the token time-to-live and the policies bound to each Keycloak group, and check whether the CLI callback on the workstation's loopback interface is reachable only from that workstation in their environment.

Redirect URIs are part of the boundary too. Keycloak will only send the browser to URIs the client registers, so a missing entry is both a functional error and a control: the guide's advice to list every possible redirect URI is what keeps the browser from being sent to an unregistered address. Before go-live, confirm with the Keycloak administrator which URIs are registered on the client, which realm discovery URL OpenBao uses, and whether TLS terminates at a proxy that changes the host name OpenBao sees. Those three checks show where the boundaries really are in the deployed environment, and they should be recorded in the design review.

The OpenBao to Keycloak login flow runs through the browser and crosses one trust boundary

The flow starts when a user opens the OpenBao UI or runs the CLI, and OpenBao redirects the browser to Keycloak for the authorization code flow. The browser returns the code to the OpenBao callback, where OpenBao exchanges it server to server with the confidential client and then applies role and policy mapping. Check that the client secret stays inside the internal network and that every redirect URI the UI and CLI use is listed in the role's allowed redirect URIs.

Authorization code login from the UI and CLI through Keycloak into OpenBao.

Hardening the Keycloak to OpenBao connection

The OpenBao OIDC login is only as strict as the Keycloak client and realm behind it. The cards below cover the parts of that connection most worth reviewing before users depend on it: redirect URIs, the client secret, transport security, realm administration and group-to-policy mappings.

Keep redirect URIs minimal but complete

OpenBao generates three redirect URIs: one under /v1/auth/oidc/* for the API, the UI callback at /ui/vault/auth/oidc/oidc/callback and the CLI callback at Register each one the OpenBao role needs and nothing broader, such as wildcard patterns that match paths you did not intend. The guide notes that most role errors come from allowed_redirect_uris missing a valid URI, so check the list against the exact URLs your users will hit. Review the list whenever the OpenBao address changes.

Keycloak OIDC guide

Store and rotate the client secret

The Keycloak client uses client authentication with the authorization code flow, so the client secret is a credential that OpenBao must hold. Store it in the OpenBao configuration path or a secure secret source your team controls, never in a shared document or repository. Define a rotation procedure that updates the Keycloak client and the OpenBao mount together, and test a login immediately after rotation. Restrict who can read the client configuration in both systems.

Enforce TLS on both endpoints

Two connections carry the login: the browser and CLI to OpenBao, and OpenBao's server-side calls to the Keycloak discovery URL and token endpoints. Serve OpenBao and Keycloak over HTTPS with certificates your clients trust, and confirm that the oidc_discovery_url uses https. Where Keycloak runs on a private certificate authority, make sure OpenBao trusts that chain. A failed certificate check often looks like a generic login failure, so test the discovery URL from the OpenBao host directly.

Restrict realm administration

Anyone who can change the Keycloak realm, clients, protocol mappers or group membership can change what OpenBao grants. Limit realm administrator roles to a small named group, separate them from day-to-day user administration, and log administrative changes. Follow the Keycloak production configuration guidance and the server administration guide for the admin console settings your environment needs. Confirm these controls with your own Keycloak team before go-live, since the exact settings depend on your deployment.

Keycloak production guide

Review groups mapped to powerful policies

Group claims flow from Keycloak through roles into OpenBao policies, so a single group can grant access to root-adjacent or broad secret paths. List every Keycloak group that maps to a role, then trace each role to its policies and paths. Remove stale groups, avoid mapping administrative policies to broad groups, and test each mapping with a user who should be denied. Repeat this review after every change to group membership or policy content.

Monitor the identity provider

Login failures, token errors and unexpected group changes are early signs of a misconfigured or abused connection. Enable the Keycloak metrics endpoint as described in the Keycloak observability guide, and collect OpenBao audit logs for every login attempt. Set alerts on spikes in failed logins and on changes to clients or group mappings. Confirm which metrics your Keycloak version exposes, because the available names and settings depend on the release you run.

Keycloak metrics guide

Redirect URI and discovery errors and how to fix them

This table pairs each redirect URI or discovery error the OpenBao Keycloak guide troubleshoots with its likely cause and the fix. Read it when a login attempt fails at the Keycloak redirect or when the OIDC mount reports a discovery problem. Most failures come from one missing entry in the client or mount configuration.

Error or symptomLikely causeFix
Redirect fails for the UI callbackallowed_redirect_uris on the OpenBao OIDC role does not list the UI callback /ui/vault/auth/oidc/oidc/callbackAdd the UI callback to allowed_redirect_uris on the role, then retry the UI login
CLI login fails with a redirect mismatchThe CLI localhost callback is missing from allowed_redirect_urisAdd the CLI callback to the role, and confirm the Keycloak client also accepts it as a valid redirect URI
Redirect URI rejected for an /v1/auth/oidc/* callbackThe role lists only some callback paths, so a required /v1/auth/oidc/* URI is absentList every redirect URI OpenBao generates for the role, not just the one shown in the browser error
Login works for JWTs but OIDC login is refusedoidc_discovery_url was replaced by jwks_url, which lets the mount verify JWTs but not run an OIDC loginSet oidc_discovery_url to the Keycloak realm URL and remove jwks_url from the mount so it can serve interactive login
Discovery request fails or returns the wrong documentoidc_discovery_url points at the Keycloak server root without the /realms/<REALM-NAME> pathSet oidc_discovery_url to https://<KEYCLOAK_URL>/realms/<REALM-NAME>, so OpenBao can append /.well-known/openid-configuration
Discovery succeeds but the Keycloak client rejects the requestThe Keycloak client is public or lacks client authentication, so it does not match the confidential flow the guide usesEnable client authentication on the client and copy its secret into the OpenBao mount configuration

How to test OIDC login before users depend on it

Test the login path end to end before anyone signs in through it for real work. Run five cases against a staging OpenBao and a Keycloak realm that matches production: UI login through the OIDC callback, CLI login from a workstation, a user who belongs to the mapped Keycloak group and receives the expected policy, a user outside that group who must be denied, and a token renewal check. For the CLI case, confirm that the local callback on completes on a machine where the browser runs, since a blocked port or a remote shell will fail here first. For the denial case, the user should get no token at all, not a token with an empty policy set. Record the policies returned by bao token lookup` for each test user so the results can be compared later.

The renewal check matters because login can succeed while the session fails within the token lifetime. Log in, confirm the token is renewable, renew it with bao token renew, and then check that a policy-restricted read still works after renewal. Also remove the test user from the Keycloak group and confirm that a fresh login is refused, since a group change should take effect at the next login, not silently persist. Keep these five cases as a runnable script or checklist so they can be repeated.

Repeat the full set before every OpenBao upgrade and every Keycloak upgrade, because each one can change the login path. Keycloak documents four minor releases a year, with breaking changes in minor releases being opt-in, so confirm which options your realm depends on before you move. Check the OpenBao release notes for the version you are moving to, and rerun the redirect URI tests after any change to the Keycloak client or the OpenBao hostname. Ask the team that owns each platform to confirm their upgrade calendar, so the test window is booked before the change is scheduled.

Questions buyers ask about OpenBao Keycloak login

How much effort does OpenBao OIDC login with Keycloak take to set up?

Effort depends on how many Keycloak realms, clients and group structures are involved, how many OpenBao mounts need login, and whether the UI and CLI both have to work from day one. The core steps are a confidential Keycloak client, three redirect URIs that OpenBao generates, an OIDC role in OpenBao, and group-to-policy mapping. The largest variable is usually the group model, because it determines how many roles and policies must be designed and reviewed. No supplied source gives a duration, so ask any provider for an effort estimate tied to a written scope that lists the realms, groups and environments in play.

Can our internal team set up OpenBao login with Keycloak without outside help?

Yes, if the team already runs Keycloak and OpenBao and has someone comfortable with OIDC claims and OpenBao policies. The guide covers the client settings, the discovery URL and the role configuration in enough detail for a capable engineer to follow. Teams without recent Keycloak administration experience, or without an owner for OpenBao policies, usually take longer and are more likely to hit redirect or group-mapping errors. Outside help is most useful for the design decisions and for a review before production, not for typing the configuration.

What do we need from our Keycloak and OpenBao owners during the work?

Plan for named people in both roles before the work starts. The Keycloak owner needs to create or approve the confidential client, confirm the realm name and discovery URL, and agree how groups are published in the token. The OpenBao owner needs to approve the OIDC auth mount, the roles, the default and group policies, and the login paths for UI and CLI. Both owners also need access to test accounts and a non-production environment. Ask any provider to list these dependencies in the written scope so that approvals do not stall the schedule.

How does realm complexity change the time and cost of the work?

Complexity grows with the number of realms, the number of group levels, the count of OpenBao policies each group needs, and whether several Keycloak clients or environments must be wired up. A single realm with a flat group list is a small job. Multiple realms, nested groups, identity brokering to another provider, or several OpenBao namespaces add design and test work. Keycloak's own guidance on its high availability and database setup also affects the work if the identity service is being deployed or changed at the same time. Ask for the quote to break out each realm, client and group set as separate line items.

Why does the login fail with a redirect URI error, and how do we avoid it?

The most common cause is that the Keycloak client's allowed redirect URIs do not list every URI that OpenBao may send. The OpenBao guide says the typical role errors come from this, so the fix is to add the UI callback, the CLI callback on localhost port 8250, and the OpenBao route paths under the OIDC auth mount to the client. Check each environment separately, because a production hostname is not covered by a staging entry. Test both the browser and the CLI flows after every change to the URL or the mount path.

What recurring upkeep follows once OpenBao login with Keycloak is live?

Recurring work includes reviewing group-to-policy mappings when teams change, rotating the client secret on the schedule your policy sets, and checking redirect URIs after hostname or proxy changes. Keycloak releases also need planning. The Keycloak project plans four minor releases a year, and its Operator documentation strongly recommends manual approval mode for operator updates to avoid unintended automatic upgrades. Keep OpenBao and Keycloak on supported versions and retest the login path after each upgrade. A retainer or a scheduled review can cover this work if your team does not want to own it.

Does the setup need to handle sign-in for all users, or only administrators?

Decide this first, because it sets the group model and the policy scope. Administrators usually need broad read and write access to specific mounts, while application teams need narrower access to their own paths. Using Keycloak groups mapped through OpenBao roles lets you grant different policies to different populations without changing the login method. Confirm with your identity and security owners which groups exist, which ones are authoritative, and which ones should never receive root-level policies. Any quote should state the expected user count and the number of distinct policy sets.

How DeployOpen scopes and delivers this integration

DeployOpen plans, implements, integrates, documents and supports self-hosted open-source platforms inside your own infrastructure. For OpenBao OIDC login with Keycloak, we start with a written scope that names your Keycloak realm, your OpenBao cluster and the groups that map to policies, then build and test the login path before handing it over.

How we scope

  • We confirm your OpenBao version, Keycloak version and the hostnames each service uses before any build starts.
  • We list the realm, confidential client, redirect URIs for the UI and CLI, and the discovery URL in the written scope.
  • We agree which Keycloak groups map to which OpenBao policies, and who approves each mapping, in writing.

How we build

  • We configure the Keycloak client with client authentication enabled and the authorization code flow, then register the OpenBao JWT/OIDC mount.
  • We set allowed redirect URIs to cover every callback OpenBao generates, so the UI and CLI logins do not fail on redirect checks.
  • We test UI login, CLI login, group-to-policy mapping and denial cases against a non-production realm before production cutover.

How we hand over

  • We deliver configuration records, the realm and client settings, role and policy mappings, and a list of tested login paths.
  • We document the redirect URI troubleshooting steps and the common role errors so your operators can diagnose failures themselves.
  • We walk your identity and platform teams through the runbook, covering client secret rotation and changes to Keycloak group membership.

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer when Keycloak or OpenBao releases change the login path.
  • Ask us to confirm the Keycloak and OpenBao versions in your environment before any upgrade, and to retest the login flows afterward.

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.