Keycloak SSO for Jenkins
Sign in to Jenkins with Keycloak through the OpenId Connect Authentication plugin, map groups to Matrix or Role-based permissions, and use JCasC.
Jenkins signs users in with Keycloak through the OpenId Connect Authentication plugin (oic-auth). The Jenkins server exchanges the authorization code with Keycloak, so the client is confidential and has a secret. Groups come from a claim in the ID token, and Jenkins grants rights to them with Matrix-based security or the Role-based Authorization Strategy.
Checked against the OpenId Connect Authentication plugin 4.737.vb_3d1a_0e7cf0b_ (it needs Jenkins 2.539 or newer) 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://jenkins.example.com for Jenkins.
In Keycloak
Create the client
Open Clients, choose Create client, and use these values:
| Setting | Value |
|---|---|
| Client type | OpenID Connect |
| Client ID | jenkins |
| Client authentication | On |
| Authentication flow | Standard flow only |
| PKCE method | S256 |
| Root URL | https://jenkins.example.com |
| Home URL | https://jenkins.example.com |
| Valid redirect URIs | https://jenkins.example.com/securityRealm/finishLogin |
| Valid post logout redirect URIs | https://jenkins.example.com/OicLogout |
| Web origins | Leave empty. Jenkins talks to Keycloak from its server, not from the browser. |
Choose Save, then copy the secret from the Credentials tab.
Add a groups claim
The plugin reads groups from the ID token or the userinfo response.
- On the
jenkinsclient, open the Client scopes tab and choosejenkins-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 access token | Off |
| Add to userinfo | On |
Then create the groups under Groups, for example jenkins-admins and jenkins-developers, and add users to them.
In Jenkins
First set Jenkins URL under Manage Jenkins → System to https://jenkins.example.com/. The plugin builds the redirect URI from it.
Install OpenId Connect Authentication from Manage Jenkins → Plugins → Available plugins. Then open Manage Jenkins → Security and, under Security Realm, choose Login with OpenID Connect.
| Field | Value |
|---|---|
| Client id | jenkins |
| Client secret | The secret from the Credentials tab |
| Configuration mode | Discovery via well-known endpoint |
| Well-known configuration endpoint | https://auth.example.com/realms/acme/.well-known/openid-configuration |
| Override scopes (under the mode's advanced options) | openid profile email |
Under Advanced configuration → User fields:
| Field | Value |
|---|---|
| User name field name | preferred_username |
| Full name field name | name |
| Email field name | email |
| Groups field name | groups |
Further down in Advanced configuration:
| Field | Value |
|---|---|
| Logout from OpenID Provider | On |
| Post logout redirect URL | https://jenkins.example.com/OicLogout |
| Properties | Add Enable Proof Key for Code Exchange (PKCE) |
Without Override scopes, the plugin asks for every scope listed in the discovery document. openid profile email is enough: the groups claim comes from the client's own mapper whatever the scope.
Set the authorization strategy in the same page (see Groups and roles) and choose Save.
Once you save, every sign-in goes through Keycloak. If the configuration is wrong, nobody can sign in. Before you save, consider adding the Escape Hatch property, which keeps one local username and password that bypasses OpenID Connect. Keep its secret somewhere safe.
How logout works. With Logout from OpenID Provider on, signing out of Jenkins sends the browser to Keycloak's end-session endpoint with id_token_hint and the post_logout_redirect_uri you set. Keycloak ends the session and returns the user to /OicLogout, which must be listed in Valid post logout redirect URIs. No call goes from Keycloak to Jenkins, so no outgoing connection is needed.
The same settings in JCasC
The plugin documents its Configuration as Code fields. With the Configuration as Code plugin installed:
jenkins:
securityRealm:
oic:
serverConfiguration:
wellKnown:
wellKnownOpenIDConfigurationUrl: "https://auth.example.com/realms/acme/.well-known/openid-configuration"
scopesOverride: "openid profile email"
clientId: "jenkins"
clientSecret: "${JENKINS_OIDC_CLIENT_SECRET}"
userNameField: "preferred_username"
fullNameFieldName: "name"
emailFieldName: "email"
groupsFieldName: "groups"
logoutFromOpenidProvider: true
postLogoutRedirectUrl: "https://jenkins.example.com/OicLogout"
properties:
- "pkce"
authorizationStrategy:
globalMatrix:
entries:
- group:
name: "jenkins-admins"
permissions:
- "Overall/Administer"
- group:
name: "authenticated"
permissions:
- "Overall/Read"
- "Job/Read"
- "Job/Build"
unclassified:
location:
url: "https://jenkins.example.com/"${JENKINS_OIDC_CLIENT_SECRET} is read from the environment of the Jenkins process, so the secret stays out of the file.
Groups and roles
The plugin turns each value of the groups claim into a Jenkins group of the same name. Jenkins does not list them anywhere; you type the names in the authorization strategy, with the same case and spaces as in Keycloak. The built-in authenticated group covers every signed-in user.
Matrix-based security (Matrix Authorization Strategy plugin):
- In Manage Jenkins → Security → Authorization, choose Matrix-based security.
- Choose Add group, enter
jenkins-adminsand tick Overall/Administer. - For Authenticated Users, tick Overall/Read and the job permissions everyone should have.
- Choose Save.
Role-Based Strategy (Role-based Authorization Strategy plugin):
- In Manage Jenkins → Security → Authorization, choose Role-Based Strategy and save.
- Open Manage Jenkins → Role Management → Manage Roles and create a global role, for example
developerwith Overall/Read and Job/Build. - Create a second global role with Overall/Administer, for example
administrator. - On Assign Roles, add the group
jenkins-developersand tickdeveloper, then addjenkins-adminsand tickadministrator.
Realm roles work too. Keycloak's built-in roles scope puts them in the access token under realm_access.roles, not in the ID token. Add a User Realm Role mapper to jenkins-dedicated with Token Claim Name roles and Add to ID token on, then set Groups field name to roles. The field takes a JMESPath expression, so realm_access.roles also works when that claim is in the ID token or userinfo.
Test it
- Open
https://jenkins.example.comin a private window. Jenkins sends you to Keycloak. - Sign in as a user in
jenkins-developers. - Open
https://jenkins.example.com/whoAmI/(the case matters). Authorities lists the groups Jenkins received. If your groups are missing, the plugin did not find the claim. - To see the claims Keycloak sends, open the
jenkinsclient in Keycloak, go to Client scopes → Evaluate, pick the user and look at Generated ID token. Paste a token into the JWT decoder to read it. - Sign out. You pass through Keycloak's logout and land on Jenkins' logout page. Signing in again asks for the password.
Common errors
| Error | Cause | Fix |
|---|---|---|
Invalid parameter: redirect_uri on the Keycloak page | The redirect URI Jenkins sent is not in Valid redirect URIs, often http:// or the wrong host because Jenkins URL is not set. | Set Jenkins URL and list https://jenkins.example.com/securityRealm/finishLogin exactly. Compare both with the redirect URI matcher. |
Could not retrieve well-known config when saving | Jenkins cannot reach the discovery URL, or the URL is wrong. | Open the URL from the Jenkins server, for example with curl. Check it with the OIDC discovery viewer. |
Token request failed after Keycloak login | Wrong client secret, or Client authentication is off. | Copy the secret again from the Credentials tab. Look up the returned code in the OAuth error lookup. |
No field 'preferred_username' was supplied | The claim is not in the ID token or userinfo, usually because the profile scope was not requested. | Keep profile in Override scopes. |
| Users sign in but have no rights | The groups claim is missing, or Full group path is on, so Jenkins sees /jenkins-admins. | Check /whoAmI/. Turn Full group path off, or enter the names with the leading slash. |
Invalid redirect uri on logout | /OicLogout is not in Valid post logout redirect URIs. | Add https://jenkins.example.com/OicLogout to the client. |
| Login fails with a PKCE error | PKCE method is S256 in Keycloak but the PKCE property is not added in Jenkins. | Add Enable Proof Key for Code Exchange (PKCE) under Properties, or clear PKCE method. |
FAQ
How do scripts and agents call Jenkins now?
With an API token, not a password. Jenkins never sees the user's Keycloak password, so basic authentication with it does not work. Each user creates a token on their Jenkins account page.
Should I use the Keycloak Authentication plugin instead?
There is a separate Keycloak Authentication plugin for Jenkins, and it is not marked deprecated. This guide uses the OpenId Connect Authentication plugin because it works from Keycloak's standard discovery document and documents every field, including JCasC.
Do I need to ask you to open a connection?
No. Jenkins calls Keycloak's discovery and token endpoints, which are public on your hostname, and logout runs through the browser. Keycloak itself never calls Jenkins.
Sources
- OpenId Connect Authentication plugin, README and quickstart: https://github.com/jenkinsci/oic-auth-plugin
- OpenId Connect Authentication plugin, configuration reference and JCasC: https://github.com/jenkinsci/oic-auth-plugin/blob/master/docs/configuration/README.md
- OpenId Connect Authentication plugin, groups from the identity provider: https://github.com/jenkinsci/oic-auth-plugin/blob/master/docs/howto/GROUPS_FROM_IDP.md
- OpenId Connect Authentication plugin releases: https://plugins.jenkins.io/oic-auth/releases/
- Matrix Authorization Strategy plugin: https://github.com/jenkinsci/matrix-auth-plugin
- Role-based Authorization Strategy plugin: https://github.com/jenkinsci/role-strategy-plugin
- Jenkins, Managing security: https://www.jenkins.io/doc/book/security/managing-security/
- Jenkins, Configuration as Code: https://www.jenkins.io/doc/book/managing/casc/
- Configuration as Code plugin, demo
jenkins.yaml(theunclassified.location.urlsetting): https://github.com/jenkinsci/configuration-as-code-plugin/blob/master/demos/jenkins/jenkins.yaml - Matrix Authorization Strategy plugin, JCasC example (
globalMatrixentries): https://github.com/jenkinsci/matrix-auth-plugin/tree/main/src/test/resources/org/jenkinsci/plugins/matrixauth/integrations/casc - Keycloak Authentication plugin: https://plugins.jenkins.io/keycloak/
- Keycloak Server Administration Guide, client settings (PKCE method), protocol mappers and RP-initiated logout: https://www.keycloak.org/docs/latest/server_admin/
Keycloak SSO for AWS IAM Identity Center
Use Keycloak as the external SAML 2.0 identity provider of AWS IAM Identity Center, with an email NameID, and create the matching users in Identity Center.
Keycloak SSO for SonarQube
Sign in to SonarQube Server or Community Build with Keycloak over SAML, with login, name, email and group attributes for just-in-time group sync.