RealmDeployDocs
GuidesSingle sign-on for apps

Keycloak SSO for HashiCorp Vault

Sign in to the Vault UI and CLI with Keycloak through Vault's OIDC auth method, and give Keycloak groups Vault policies with external groups.

Vault signs users in with Keycloak through its JWT/OIDC auth method, mounted as oidc. The same setup serves the Vault UI and vault login -method=oidc on the command line. Vault keeps the client secret on its server and uses PKCE for the code exchange.

Checked against Vault 2.x docs (Vault 2.2.2) and Keycloak 26.8 on 25 November 2026.

Replace auth.example.com with your RealmDeploy hostname and acme with your realm. The examples use https://vault.example.com:8200 for Vault.

In Keycloak

Create the client

Open Clients, choose Create client, and use these values:

SettingValue
Client typeOpenID Connect
Client IDvault
Client authenticationOn
Authentication flowStandard flow only
Root URLhttps://vault.example.com:8200
Home URLhttps://vault.example.com:8200/ui/
Valid redirect URIshttps://vault.example.com:8200/ui/vault/auth/oidc/oidc/callback and http://localhost:8250/oidc/callback
Valid post logout redirect URIsLeave empty
Web originsLeave empty

The first redirect URI is for the Vault UI, the second for the CLI, which listens on port 8250 of the user's machine. Choose Save, then copy the secret from the Credentials tab.

Add a groups claim

  1. On the vault client, open the Client scopes tab and choose vault-dedicated.
  2. Choose Configure a new mapper and pick Group Membership.
  3. Fill it in and choose Save:
FieldValue
Namegroups
Token Claim Namegroups
Full group pathOff
Add to ID tokenOn
Add to userinfoOn

Create the groups under Groups, for example vault-admins, and add users to them.

In Vault

Run these as a Vault operator with a token that may manage auth methods.

Enable the auth method. It mounts at auth/oidc:

vault auth enable oidc

Point it at your realm:

vault write auth/oidc/config \
  oidc_discovery_url="https://auth.example.com/realms/acme" \
  oidc_client_id="vault" \
  oidc_client_secret="CLIENT_SECRET_FROM_KEYCLOAK" \
  default_role="default"

Create the role that logins use:

vault write auth/oidc/role/default \
  role_type="oidc" \
  user_claim="sub" \
  groups_claim="groups" \
  oidc_scopes="profile,email" \
  allowed_redirect_uris="https://vault.example.com:8200/ui/vault/auth/oidc/oidc/callback" \
  allowed_redirect_uris="http://localhost:8250/oidc/callback" \
  token_policies="default" \
  token_ttl="1h"
SettingMeaning
oidc_discovery_urlThe realm's issuer, without /.well-known/openid-configuration. Vault reads the discovery document under it and checks iss and aud.
oidc_client_id, oidc_client_secretThe client ID and the secret from the Credentials tab.
default_roleThe role used when the user does not name one.
user_claimThe claim that names the user's entity alias in Vault. sub is the Keycloak user ID and never changes.
groups_claimThe claim with the user's groups. Vault turns each one into a group alias.
oidc_scopesScopes on top of openid, which Vault always adds.
allowed_redirect_urisMust match Valid redirect URIs in Keycloak exactly. Repeat the key once per URI.
token_policies, token_ttlWhat every Keycloak user gets, and how long the Vault token lives. Group policies come on top.

bound_audiences is not needed for OIDC roles: Vault expects the client ID as the audience, which is what Keycloak puts in the ID token.

Groups and roles

To give a Keycloak group Vault policies, create an external group in Vault and link it to the Keycloak group name with a group alias. The alias name must match the value in the groups claim.

vault write identity/group name="vault-admins" type="external" policies="admin"

GROUP_ID=$(vault read -field=id identity/group/name/vault-admins)
OIDC_ACCESSOR=$(vault auth list -format=json | jq -r '."oidc/".accessor')

vault write identity/group-alias name="vault-admins" \
  mount_accessor="$OIDC_ACCESSOR" \
  canonical_id="$GROUP_ID"

Here admin is a Vault policy you wrote. When a member of the Keycloak group vault-admins signs in, Vault adds the user to the external group, and their token gets default from the role plus admin from the group. Vault updates the membership at each login.

To let only one group sign in at all, bind the role to the claim. Vault's docs suggest writing a role with a map value as one JSON object:

vault write auth/oidc/role/admins - <<EOF
{
  "role_type": "oidc",
  "user_claim": "sub",
  "groups_claim": "groups",
  "bound_claims": { "groups": ["vault-admins"] },
  "allowed_redirect_uris": [
    "https://vault.example.com:8200/ui/vault/auth/oidc/oidc/callback",
    "http://localhost:8250/oidc/callback"
  ],
  "token_policies": "default",
  "token_ttl": "1h"
}
EOF

Users then sign in with the role name admins.

Test it

  1. UI. Open https://vault.example.com:8200/ui/, select the OIDC method, leave the role empty to use default, and sign in. Vault sends you to the Keycloak page.

  2. CLI. Run:

    export VAULT_ADDR="https://vault.example.com:8200"
    vault login -method=oidc role=default

    The CLI starts a listener on localhost:8250 and opens the browser. After the Keycloak login it prints a token.

  3. Check the policies: vault token lookup lists default under policies and, for members of vault-admins, admin under identity_policies.

  4. To see the claims Vault receives, open the vault client in Keycloak, go to Client scopes → Evaluate, pick the user and look at Generated ID token. Paste it into the JWT decoder.

Common errors

ErrorCauseFix
Invalid parameter: redirect_uri on the Keycloak pageThe redirect URI Vault sent is not in Valid redirect URIs, or not in allowed_redirect_uris.List the same URIs on both sides, with the same scheme, host, port and no trailing slash. Check with the redirect URI matcher.
The login does not start, and the Vault server log shows unauthorized redirect_uriThe URI is missing from the role's allowed_redirect_uris.Write the role again with both URIs.
missing role or role "default" could not be foundNo role was given and default_role is not set, or it names a role that does not exist.Create the role, set default_role, or pass role= when you log in.
User signs in but has only defaultThe group alias name does not match the claim, often because Full group path is on and the claim says /vault-admins.Turn off Full group path, or name the alias with the leading slash.
CLI waits and nothing opensThe browser could not open, or port 8250 is taken.Open the printed URL by hand. For another port, use port=8400 and add http://localhost:8400/oidc/callback on both sides.
invalid_clientWrong oidc_client_secret, or Client authentication is off.Write the config again with the secret from the Credentials tab. Look up other codes in the OAuth error lookup.

For more detail, set verbose_oidc_logging=true on the role and run Vault with debug logging. It writes the received claims to the server log, so turn it off again afterwards.

FAQ

Does Vault use Keycloak's realm roles?

Not out of the box. Vault reads the claim you set in groups_claim. Groups are the simplest. To use realm roles, add a User Realm Role mapper with Add to ID token on and point groups_claim at its claim name.

Can I use Vault namespaces?

Yes, in Vault Enterprise. namespace_in_state is on by default for new configs, so the redirect URIs stay the same in every namespace and need no namespace query parameter.

Can machines log in with Keycloak tokens too?

Yes, with a separate role of type jwt that checks a token the machine already has. Mount it at another path, for example vault auth enable jwt. For jwt roles, bound_audiences is required and must match the token's aud; in Keycloak that usually means an Audience mapper.

Sources

On this page