Jenkins Authentication and Authorization: Security Realms, Matrix and Role-Based Access, LDAP, SSO and OIDC
Two Separate Questions
| Question | Jenkins setting | Examples |
| Who are you? (authentication) | Security Realm | Jenkins database, LDAP, Active Directory, OIDC, SAML, GitHub OAuth |
| What may you do? (authorization) | Authorization Strategy | Matrix, Project-based matrix, Role-based, Logged-in users can do anything |
Both are in Manage Jenkins → Security. Change them carefully and keep a second browser window logged in as admin until you confirm the new setup works.
Never use these in production: Anyone can do anything and Logged-in users can do anything give every user full control, including running scripts on the controller. Use matrix or role-based security.
Security Realm Options
| Realm | When to use |
| Jenkins' own user database | Small labs. Users are created and kept inside Jenkins |
| LDAP / Active Directory | Company directory. Users and groups come from the directory |
| OpenID Connect (OIDC) plugin | Single sign-on with Keycloak, Okta, Azure AD / Entra ID, Google |
| SAML plugin | Enterprise SSO using SAML identity providers |
| GitHub Authentication plugin | Developers sign in with GitHub, teams map to groups |
LDAP Example With JCasC
yaml
jenkins:
securityRealm:
ldap:
configurations:
- server: "ldaps://ldap.example.com:636"
rootDN: "dc=example,dc=com"
userSearchBase: "ou=people"
userSearch: "uid={0}"
groupSearchBase: "ou=groups"
managerDN: "cn=jenkins,ou=service,dc=example,dc=com"
managerPasswordSecret: "${LDAP_PASSWORD}"
disableMailAddressResolver: false
groupIdStrategy: "caseInsensitive"
userIdStrategy: "caseInsensitive"
- Always use LDAPS (TLS) or StartTLS
- Use a read-only service account to search the directory
- Use group names, not individual users, in permissions
OIDC Single Sign-On
yaml
jenkins:
securityRealm:
oic:
clientId: "jenkins"
clientSecret: "${OIDC_CLIENT_SECRET}"
wellKnownOpenIDConfigurationUrl: "https://sso.example.com/realms/corp/.well-known/openid-configuration"
userNameField: "preferred_username"
groupsFieldName: "groups"
scopes: "openid email profile"
logoutFromOpenidProvider: true
escapeHatchEnabled: true # a local admin can still log in if SSO is down
escapeHatchUsername: "breakglass"
escapeHatchSecret: "${BREAKGLASS_PASSWORD}"
Keep a break-glass account: If the SSO provider is down you can still log in. Protect that account with a long random password stored in a vault.
Matrix Authorization
The matrix lists permissions as columns and users or groups as rows. Tick what each may do.
| Permission group | Examples | Typical holder |
| Overall | Administer, Read, SystemRead | Admin group (Administer), everyone (Read) |
| Agent | Configure, Connect, Create, Delete | Platform team |
| Job | Read, Build, Configure, Create, Delete, Cancel, Workspace | Read/Build for developers; Configure for owners |
| Run | Delete, Update | Owners |
| Credentials | View, Create, Update, Delete, ManageDomains | Project owners, security team |
| SCM, View | Tag, Configure/Create views | Teams |
yaml
jenkins:
authorizationStrategy:
globalMatrix:
entries:
- group:
name: "jenkins-admins"
permissions: ["Overall/Administer"]
- group:
name: "authenticated"
permissions: ["Overall/Read", "Job/Read"]
- group:
name: "developers"
permissions: ["Job/Build", "Job/Cancel", "Job/Workspace", "Run/Replay"]
Project-Based Matrix: Per-Job Permissions
- The Project-based Matrix Authorization Strategy lets each job or folder add its own matrix
- Permissions inherit from parents, you can add more but not remove inherited ones (unless you stop inheritance)
- Good for a few teams sharing one controller
Role-Based Strategy
The Role-based Authorization Strategy plugin works like role-based access in other tools: define roles, then assign users or groups to roles.
| Role type | Applies to | Pattern example |
| Global roles | Whole Jenkins | admin, readonly, developer |
| Item (project) roles | Jobs whose full name matches a regular expression | team-a/.* gives Team A rights only in its jobs |
| Agent roles | Nodes matching a pattern | linux-prod-.* |
yaml
jenkins:
authorizationStrategy:
roleBased:
roles:
global:
- name: "admin"
permissions: ["Overall/Administer"]
entries: [{group: "jenkins-admins"}]
- name: "readonly"
permissions: ["Overall/Read"]
entries: [{group: "authenticated"}]
items:
- name: "team-a"
pattern: "team-a/.*"
permissions: ["Job/Build", "Job/Configure", "Job/Read", "Job/Cancel", "Credentials/View"]
entries: [{group: "team-a"}]
Folders for Multi-Team Jenkins
- Create one folder per team (Folders plugin). Put jobs and folder-level credentials inside
- Give each team item roles or folder permissions only for its folder
- Use folder-level shared libraries for team-specific code in the sandbox
API Tokens and Service Accounts
- For scripts and tools, create an API token: user menu → Security → API Token. Use
user:token with Basic authentication
- Tokens act with the user's permissions, so use a dedicated service account with minimal rights, not a person's account
- Revoke tokens when the integration is retired. Rotate regularly
bash
# Trigger a build with an API token (CSRF crumb not needed for token auth)
curl -sS -X POST -u ci-bot:$JENKINS_TOKEN "https://jenkins.example.com/job/team-a/job/shop/buildWithParameters?BRANCH=main"
Least-Privilege Model
| Group | Permissions |
| Admins (2 to 4 people) | Administer; used rarely, with MFA through SSO |
| Platform team | Manage agents, plugins (through change control), view all jobs |
| Team developers | Read, Build, Cancel, Workspace in their folder; Configure for team leads |
| Release managers | Approve production input steps (see submitter in input) |
| Auditors | Read-only, plus audit logs |
| Service accounts | Exactly the jobs and actions the integration needs |
Practice Tasks
- Switch a lab Jenkins to project-based matrix security, keeping an admin session open
- Create two folders and give two groups access only to their own folder
- Configure LDAP or OIDC against a lab Keycloak
- Create a service account with only Job/Build in one folder and trigger it with an API token
- Verify that a developer cannot see another team's credentials
Conclusion
Authentication (security realm) proves who a user is; authorization (strategy) decides what they can do. Use LDAP or OIDC single sign-on, matrix or role-based permissions on groups, folders per team, a break-glass admin and service accounts with tokens and minimal rights.
Quick Summary: realm vs strategy; LDAP/OIDC YAML; matrix permissions; role-based global/item/agent; folders; API tokens + service accounts; least-privilege groups.