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:
| Setting | Value |
|---|---|
| Client type | OpenID Connect |
| Client ID | vault |
| Client authentication | On |
| Authentication flow | Standard flow only |
| Root URL | https://vault.example.com:8200 |
| Home URL | https://vault.example.com:8200/ui/ |
| Valid redirect URIs | https://vault.example.com:8200/ui/vault/auth/oidc/oidc/callback and http://localhost:8250/oidc/callback |
| Valid post logout redirect URIs | Leave empty |
| Web origins | Leave 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
- On the
vaultclient, open the Client scopes tab and choosevault-dedicated. - Choose Configure a new mapper and pick Group Membership.
- Fill it in and choose Save:
| Field | Value |
|---|---|
| Name | groups |
| Token Claim Name | groups |
| Full group path | Off |
| Add to ID token | On |
| Add to userinfo | On |
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 oidcPoint 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"| Setting | Meaning |
|---|---|
oidc_discovery_url | The 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_secret | The client ID and the secret from the Credentials tab. |
default_role | The role used when the user does not name one. |
user_claim | The claim that names the user's entity alias in Vault. sub is the Keycloak user ID and never changes. |
groups_claim | The claim with the user's groups. Vault turns each one into a group alias. |
oidc_scopes | Scopes on top of openid, which Vault always adds. |
allowed_redirect_uris | Must match Valid redirect URIs in Keycloak exactly. Repeat the key once per URI. |
token_policies, token_ttl | What 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"
}
EOFUsers then sign in with the role name admins.
Test it
-
UI. Open
https://vault.example.com:8200/ui/, select the OIDC method, leave the role empty to usedefault, and sign in. Vault sends you to the Keycloak page. -
CLI. Run:
export VAULT_ADDR="https://vault.example.com:8200" vault login -method=oidc role=defaultThe CLI starts a listener on
localhost:8250and opens the browser. After the Keycloak login it prints a token. -
Check the policies:
vault token lookuplistsdefaultunderpoliciesand, for members ofvault-admins,adminunderidentity_policies. -
To see the claims Vault receives, open the
vaultclient in Keycloak, go to Client scopes → Evaluate, pick the user and look at Generated ID token. Paste it into the JWT decoder.
Common errors
| Error | Cause | Fix |
|---|---|---|
Invalid parameter: redirect_uri on the Keycloak page | The 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_uri | The 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 found | No 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 default | The 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 opens | The 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_client | Wrong 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
- Vault, Use JWT/OIDC authentication: https://developer.hashicorp.com/vault/docs/auth/jwt
- Vault, Use Keycloak for OIDC authentication: https://developer.hashicorp.com/vault/docs/auth/jwt/oidc-providers/keycloak
- Vault, JWT/OIDC auth method API: https://developer.hashicorp.com/vault/api-docs/auth/jwt
- Vault, Identity group and group alias API: https://developer.hashicorp.com/vault/api-docs/secret/identity/group and https://developer.hashicorp.com/vault/api-docs/secret/identity/group-alias
- Vault tutorial, OIDC auth method with external groups: https://developer.hashicorp.com/vault/tutorials/auth-methods/oidc-auth
- Vault 2.2.2 release: https://github.com/hashicorp/vault/releases/tag/v2.2.2
- Keycloak Server Administration Guide, client settings and protocol mappers: https://www.keycloak.org/docs/latest/server_admin/
Keycloak SSO for Argo CD
Sign in to Argo CD with Keycloak over OpenID Connect, send Keycloak groups in a groups claim, and map them to Argo CD roles in argocd-rbac-cm.
Keycloak SSO for Kubernetes
Let kubectl users sign in to a Kubernetes cluster with Keycloak, map Keycloak groups to RBAC, and see what EKS and AKS let you configure.