Security Realm and Authorization Basics in Jenkins

Security Realm and Authorization Basics in Jenkins

A complete, plain-English guide to the two questions every Jenkins server must answer about every visitor: who are you, and what are you allowed to do? Learn how realms, users, groups, permissions, and strategies fit together, and how to set them up safely.

Picture a large office building. At the front desk, a guard checks your badge and confirms who you are. That is one job. Once you are inside, a different set of rules decides which floors your badge opens: the accountant may enter the finance office, the engineer may enter the lab, and only the facilities manager may enter the boiler room. That is a second, separate job. A building that checks badges but lets everyone into every room is not secure. A building that has careful room rules but never checks who is at the door is not secure either.

Jenkins works in exactly the same way. It holds the source code of your company, the passwords to your servers, and the power to deploy software to production. It must therefore answer two separate questions for every person and every script that talks to it. The first question, who are you?, is answered by the security realm. The second question, what may you do?, is answered by the authorization strategy. This guide explains both from zero, shows the choices you have, and helps you build a setup that is safe without being painful to use.

1What Are a Security Realm and an Authorization Strategy?

We start with the simplest picture: two jobs, two settings, and how they differ.

Jenkins is a tool that automates building, testing, and delivering software. It is usually reached through a web page, and also through scripts and other tools. Whoever connects must be identified, and their actions must be limited to what they are permitted to do. Jenkins handles this with two settings that live side by side on the security configuration page.

A security realm is the part of Jenkins that handles authentication, which means proving identity. It decides where user names and passwords come from, and how a person proves they are who they claim to be. It can be Jenkins’ own list of users, or a company directory, or a single sign-on service.

An authorization strategy is the part of Jenkins that handles authorization, which means granting rights. Once Jenkins knows who someone is, the strategy decides which actions they may perform: view a job, start a build, change a setting, or manage the whole server.

Everyday analogy

At an airport, the passport check confirms that you are who you say you are. That is the security realm. The boarding pass then decides which plane you may board and which lounge you may enter. That is the authorization strategy. A passport alone does not let you on every plane, and a boarding pass is useless if nobody checks whose it is.

flowchart LR
  A["A person or script contacts Jenkins"] --> B["Security realm checks who you are"]
  B --> C["Authorization strategy checks what you may do"]
  C --> D["Allowed so the page or action proceeds"]
  C --> E["Denied so an error page is shown"]
    
Figure 1. Every request passes through two checks: identity first, then permission.

Two settings, chosen separately

Setting 1

Security realm

Answers “who are you?”. Examples: Jenkins’ own user database, a company directory, or a single sign-on provider.

Setting 2

Authorization strategy

Answers “what may you do?”. Examples: any logged-in user can do anything, a permission grid, or named roles.

Key point

They are independent

You can combine almost any realm with almost any strategy. Changing one does not force a change to the other.

Key point

Both must be right

A strong login with loose permissions, or tight permissions with an open login, both leave the front door open.

i
Note

In recent Jenkins versions, these settings are found under the Security area of the Manage Jenkins page. Older versions called it “Configure Global Security”. Screen names and layouts change between versions, so confirm the labels on your own server.

2Why These Settings Exist

To see why security matters so much in Jenkins, imagine a Jenkins server with no protection at all.

What an open Jenkins can do

A Jenkins server is not just a dashboard. It stores credentials for cloud accounts, Git servers, and production machines. It can run any command on its agents, and can deploy software to real customers. Anyone who can change a job can make it run any command they like. So, an unprotected Jenkins is much like handing strangers a set of keys to the company’s servers along with an instruction manual.

How the defaults changed

Jenkins began in 2011 as a fork of an older project called Hudson, in an era when build servers often sat on a private network and were trusted by everyone who could reach them. Over the years, build servers became a prime target for attackers, because of the secrets and power they hold. With Jenkins 2.0, released in 2016, the setup process began to enable security by default. A new installation asks you to unlock it with an initial password, and then to create a first administrator account.

2 questions
who are you, and what may you do
2 settings
security realm and authorization strategy
Secure by default
new installations start with security on, since Jenkins 2.0

The problem these settings solve

  • Unknown visitors. Without authentication, nobody knows who changed a job or started a deployment.
  • Too much power. Without authorization, every user can do everything, including things they should never touch.
  • Team boundaries. Without fine-grained rules, one team can read or change another team’s jobs and secrets.
  • Accountability. Without named accounts, auditors cannot say who did what, and when.
  • Departures. When someone leaves the company, their access must end in one place, not twenty.
Everyday analogy

A hospital does not let every visitor wander into the pharmacy. It checks who visitors are, gives them passes for certain wards, and keeps the drug cupboard for trained staff. Nobody thinks this is rude. It is how a place with valuable and dangerous things stays safe.

Know who is knocking. Decide what they may touch.

3Words You Need First

A handful of terms come up in every discussion of Jenkins security. Learn them once here.

Word 1

User

A person or a script that has an identity in Jenkins, usually a login name.

Word 2

Group

A named collection of users, such as “developers” or “release-managers”. Groups come from the security realm.

Word 3

Authentication

Proving who you are, for example with a password, a token, or a single sign-on login.

Word 4

Authorization

Deciding what an identified person may do.

Word 5

Permission

A single right, such as “view a job”, “start a build”, or “administer Jenkins”.

Word 6

Role

A named bundle of permissions, such as “developer”, that can be given to users or groups.

Word 7

Anonymous

A visitor who has not logged in. Jenkins gives such visitors a special identity called anonymous.

Word 8

Authenticated

Any visitor who has logged in successfully, whoever they are. Jenkins gives them a special identity that stands for all logged-in users.

A few more Jenkins words

The controller is the main Jenkins server, and it is the place where security is enforced. An agent is a worker machine that runs builds. A job is a saved description of work, and a folder is a container for jobs. An administrator is a user with the highest permission, often called Administer, who can change any setting. A session is the period after login during which Jenkins remembers you, usually through a small cookie in your browser.

i
Tip

Whenever the words feel muddy, ask which question is being answered. “Who is this?” belongs to authentication and the security realm. “May they do this?” belongs to authorization and the strategy.

4How Authentication Differs from Authorization

These two words are often confused. Getting them straight is the foundation for everything else.

PointAuthenticationAuthorization
Question answeredWho are you?What may you do?
HappensFirst, at login or on each token useAfter identity is known, on every action
Jenkins settingSecurity realmAuthorization strategy
Evidence usedPassword, token, single sign-on assertionUser name, group memberships, and permission rules
Failure looks likeLogin rejected, or redirect to a login pageAccess denied message after logging in
Typical ownerIdentity or directory teamJenkins administrators and team leads
Everyday analogy

A bank teller checks your identity card, which is authentication. The teller then checks whether your account allows the withdrawal you asked for, which is authorization. Being who you say you are does not mean you may take any amount from any account.

The order matters

Authorization can only work after authentication. Jenkins must know who you are, and which groups you belong to, before it can decide what you may do. If the security realm is wrong, for example if it cannot tell which groups you are in, the strategy has nothing to work with, and you may be denied even though the permission rules are correct.

What happens on each request

1

The request arrives

A browser, a script, or another tool asks Jenkins for a page or an action.

2

Jenkins works out who is asking

It checks the session cookie or the credentials sent with the request. With none, the requester is treated as anonymous.

3

The realm supplies groups

Jenkins asks the security realm for the groups the user belongs to, so that rules written for groups can apply.

4

The strategy checks permission

For the action requested, the strategy looks at the user, the groups, and the item concerned, and answers allowed or denied.

5

Jenkins responds

An allowed request proceeds. A denied request produces an error page, or a redirect to the login page for anonymous visitors.

!
Watch out

“I can log in but cannot see my job” is an authorization problem, not a login problem. “I cannot log in at all” is an authentication problem. Diagnosing which one you have halves the time to fix it.

5The Security Realm Options

Jenkins can take its identity information from several places. Here are the usual choices.

RealmWhere identities liveGood forWatch for
Jenkins’ own user databaseInside Jenkins itselfSmall teams, labs, and learningNo groups, separate passwords to manage, no central shutdown when someone leaves
LDAPA company directory serverOrganisations with an existing directoryCorrect connection and search settings, and group lookup rules
Active DirectoryA Microsoft directory serviceWindows-based organisationsPlugin settings and domain details
Single sign-on with SAML or OpenID ConnectAn identity provider outside JenkinsCompanies with a central login and multi-factor checksGroup claims, session lengths, and what happens when the provider is down
Code-hosting loginThe login of a Git hosting serviceTeams whose people already live in that serviceMapping organisations and teams to Jenkins rights
Servlet container or Unix accountsThe web server or the operating systemSpecial setupsHarder to manage and less common today
Everyday analogy

You can keep your own private guest list at the door of a small party. A large company keeps a shared staff register that every building uses. A festival accepts wristbands issued by a central ticket office. All three check identity, but the more central the register, the easier it is to add and remove people in one place.

Choosing a realm

  • One person or a lab. Jenkins’ own database is simplest, with sign-up turned off.
  • A team with a company directory. Use the directory, so that people use their normal passwords and leave the system when they leave the company.
  • A company with central single sign-on. Use it, so that multi-factor checks, password rules, and account removal apply to Jenkins too.
  • Anything that needs groups. Choose a realm that supplies groups, since group-based rules are far easier to maintain than lists of individual names.
i
Note

Most external realms are provided by plugins. Plugins are updated separately from Jenkins, and their settings screens change. Always read the current documentation for the plugin you install.

6Jenkins’ Own User Database

This is the simplest realm, and the one that every new installation meets first. It is worth understanding well, including its limits.

What it is

With this realm, Jenkins keeps its own list of users, each with a login name, a password, and some profile details. The passwords are stored in a hashed form, which means Jenkins keeps a scrambled version that cannot be turned back into the original password. The user records live in Jenkins’ data folder on the controller.

How a new installation starts

1

Unlock with an initial password

On first start, Jenkins writes a one-time administrator password to a file on the server and to the log. Only someone with access to the server can read it. This proves that you control the machine.

2

Install plugins

The setup wizard offers a suggested set of plugins, or lets you choose your own.

3

Create the first administrator

You choose a name and a strong password for the account that will manage Jenkins from then on.

4

Set the address

You confirm the web address by which people will reach Jenkins.

Everyday analogy

When you move into a new house, the builder hands you one master key. With it, you cut keys for the family and decide who gets which one. The initial password is the builder’s key, and the first administrator account is your own key, from which all other access is issued.

The sign-up switch

This realm has an option to allow users to sign up. When it is on, anyone who can reach the login page can create an account for themselves. That may be fine on a private lab, but it is dangerous in combination with a loose authorization strategy. If the strategy says that any logged-in user can do anything, then anyone who signs up instantly becomes a full administrator. Sign-up should almost always be turned off on any Jenkins that holds real secrets.

Strengths

  • Nothing else to install or connect.
  • Simple to understand.
  • Good for labs, demonstrations, and first steps.

Limits

  • No group support, so rules must name individuals.
  • Passwords are managed separately from the company’s other systems.
  • Removing a leaver is a manual step that is easy to forget.
  • No built-in multi-factor sign-in.
!
Watch out

The initial administrator password file is meant to be used once. After setup, protect the server so that ordinary users cannot read Jenkins’ data folder, and never share the first administrator account among several people.

7External Realms: Directories and Single Sign-On

Most companies do not want a separate password list for every tool. External realms let Jenkins borrow identities from a central system.

Directory realms

A directory is a central database of people and groups that many company systems share. Two common examples are LDAP directories and Microsoft’s directory service. When Jenkins uses a directory realm, it does not store passwords itself. When a person logs in, Jenkins asks the directory server to check the password, and asks it which groups the person belongs to. To make this work, an administrator gives Jenkins the address of the directory, an account it may use to search, and rules for finding users and groups.

Single sign-on realms

With single sign-on, Jenkins does not see the password at all. It hands the person over to a separate identity provider, which does the login, possibly including a second check such as a code from a phone. The provider then sends Jenkins a signed message that says who the person is and, often, which groups they belong to. Two common protocols for this are called SAML and OpenID Connect.

sequenceDiagram
  participant U as User Browser
  participant J as Jenkins
  participant I as Identity Provider
  U->>J: Open a Jenkins page
  J-->>U: Redirect to the identity provider
  U->>I: Sign in with the company account
  I-->>U: Signed proof of identity and groups
  U->>J: Present the signed proof
  J->>J: Create a session and map groups to permissions
  J-->>U: Show the page
    
Figure 2. A single sign-on login. Jenkins never sees the password.
Everyday analogy

A conference has one registration desk in the lobby. After you show your passport there, you receive a wristband that every session room accepts. The rooms never check your passport themselves. They only check that the wristband is genuine. The identity provider is the registration desk, and the signed proof is the wristband.

Why organisations prefer them

Benefit

One place to remove access

When someone leaves, disabling their central account cuts off Jenkins too.

Benefit

Stronger login

Multi-factor checks, password rules, and lockouts of the central system apply automatically.

Benefit

Groups for free

Team memberships are managed in the directory, and Jenkins simply reads them.

Benefit

Fewer passwords

People use one login, so they are less likely to reuse weak passwords or write them down.

Things to plan for

  • Group names must match. Jenkins rules refer to groups by name, and the name the provider sends must be spelled exactly the same way.
  • Provider outages. If the identity provider or directory is down, people cannot log in. Plan how administrators will regain access, and keep tested recovery steps.
  • Session lifetimes. Decide how long a login lasts, balancing safety against annoyance.
  • Scripts still need identities. Non-browser tools cannot use a browser login. They use tokens, described in Chapter 13.
  • Test with a second browser. Before you save a change to the realm, keep your current administrator session open, and test the new login in a private window, so you cannot lock yourself out.
!
Watch out

Switching the security realm on a live server is one of the easiest ways to lock everyone out, including yourself. Note the current settings, keep an administrator session open while you test, and make sure someone can still get to the server itself in case a rollback is needed.

8Authorization Strategies at a Glance

Once Jenkins knows who someone is, the strategy decides what they may do. Here is the whole menu, from loosest to most detailed.

StrategyWhat it doesGood forDanger level
Anyone can do anythingNo checks at all, even for anonymous visitorsNothing that matters, apart from an isolated experimentExtreme
Legacy modeOld behaviour kept for compatibilityNothing newHigh, and deprecated
Logged-in users can do anythingAny authenticated user is a full administrator. Optional read-only access for anonymous visitorsA small, fully trusted group on a private networkHigh if the realm lets people sign up, or the group is large
Matrix-based securityA grid of users and groups against permissionsSmall and medium setups with a few clear rulesLow when kept tidy
Project-based matrixThe same grid, plus extra grids on individual jobs and foldersTeams that need their own rules on their own jobsLow, but rules multiply
Role-based strategyNamed roles bundling permissions, assigned to users and groups, with job patternsLarger setups with many teamsLow, and easiest to keep clean at scale
Everyday analogy

The strategies are like ways of managing keys in a building. “Anyone can do anything” is an unlocked building. “Logged-in users can do anything” is a building where every employee holds a master key. A matrix is a key chart pinned on the wall. Roles are job badges: “cleaner”, “engineer”, “manager”, each opening the doors that job needs.

The first three are rarely enough

The first three strategies treat everyone alike. They may be fine for a personal server, but as soon as you have two teams, one of which should not touch the other’s jobs or secrets, they fail. Real access control begins with the matrix and role strategies, which let you say different things about different people.

!
Watch out

“Logged-in users can do anything” is a popular default because it is simple, and a common cause of trouble. Any account, including a contractor’s, a test account, or an old one that was never removed, gets full administrator power. Treat it as a temporary state during setup, not as a destination.

i
Note

Matrix and role-based strategies are provided by plugins. Depending on how your Jenkins was installed, you may need to install them before they appear in the list.

9Matrix-Based and Project-Based Matrix Security

The permission matrix is the classic Jenkins answer to “who may do what”. It is a grid you can read at a glance.

The grid

In matrix-based security, down the side are users and groups, and across the top are permissions. You tick a box where a person or group should have a permission. A person’s rights are everything ticked for them, plus everything ticked for every group they belong to, plus everything ticked for the special “authenticated” and “anonymous” identities that apply to them.

WhoOverall ReadJob ReadJob BuildJob ConfigureOverall Administer
anonymousNoNoNoNoNo
authenticatedYesYesNoNoNo
developers (group)YesYesYesNoNo
release-managers (group)YesYesYesYesNo
jenkins-admins (group)YesYesYesYesYes
Everyday analogy

A school keeps a chart on the staff room wall: rows for staff groups, columns for rooms, and a tick where a group may enter. Teachers tick for classrooms, the caretaker ticks for the boiler room, and the head ticks for everything. Anyone can read the chart and find out who may go where.

Rights add up, never subtract

A key feature of the matrix is that permissions only add. If a group has a permission, and you are a member of that group, you have it. There is no way to say “everyone in the developers group except Sam”. If Sam is in the group, Sam has the rights of the group. To treat Sam differently, you must remove Sam from the group, or create a different group. Keep this in mind when designing groups.

Project-based matrix: rules per job

The project-based variant keeps the global grid, and adds a second grid to each job and folder. This lets a team have extra permissions on its own jobs only. For example, the payments team can be given “configure” rights on the payments folder, but nothing on the search folder. Jobs and folders can also inherit rules from the folder above, which reduces repetition.

Strengths of the matrix

  • Easy to read and to explain to others.
  • Built from a small number of ideas.
  • Project-based rules give teams their own space.

Limits of the matrix

  • The grid grows large when there are many groups and permissions.
  • Per-job rules are scattered across many pages, making audits harder.
  • No way to subtract a permission.
i
Tip

Always put groups in the matrix, not individual names. When people change teams, you update the group in the directory, and the Jenkins matrix does not need to change at all.

10Role-Based Authorization

When the grid gets too big, roles keep it tidy. A role is a named bundle of permissions that you can hand out like a job title.

The role-based strategy, provided by the Role Strategy plugin, introduces three kinds of roles.

Kind 1

Global roles

Apply across the whole Jenkins. Examples: administrator, viewer, or developer who may build any job.

Kind 2

Item roles

Apply to jobs and folders whose names match a pattern. Example: everything that starts with “payments-” gives the payments team extra rights.

Kind 3

Agent roles

Apply to build agents whose names match a pattern, so that teams can manage only their own machines.

Step

Assignment

You then assign users or groups to roles. A person may hold several roles, and rights add up.

flowchart TD
  A["Users and groups from the security realm"] --> B["Global roles such as admin and viewer"]
  A --> C["Item roles matched to folders or job name patterns"]
  A --> D["Agent roles matched to agent names"]
  B --> E["Permission check on every request"]
  C --> E
  D --> E
    
Figure 3. How users and groups reach permissions through roles.
Everyday analogy

A hospital does not write permissions for each nurse by name. It defines roles such as “ward nurse”, “pharmacist”, and “surgeon”, each with the doors and cabinets that role needs, and assigns people to them. When a nurse is promoted, the hospital changes their role, not a hundred door settings.

Why roles scale better

  • Meaningful names. “team-payments-developer” tells a reader what the role is for, while a row of ticks does not.
  • Patterns for jobs. One pattern covers all present and future jobs of a team, without editing each one.
  • One place to audit. All rules are on one management screen, not scattered across job pages.
  • Reuse. The same role can be assigned to many groups.

Things to watch

  • Pattern mistakes. A pattern that is too broad gives a team access to jobs that are not theirs, and one that is too narrow leaves their new jobs invisible.
  • Naming discipline. Patterns rely on jobs being named consistently, or on being placed in folders. Folders are usually the more reliable boundary.
  • Plugin dependence. The strategy is a plugin, so keep it updated and read its release notes.
  • Additive rights. As in the matrix, rights add up and never subtract.
i
Tip

Organise jobs into one folder per team and write item roles for the folder. It is easier to remember and audit “everything in the payments folder” than a set of name patterns.

11The Permissions Catalogue

Permissions are the atoms of authorization. Here are the ones you will meet most often, grouped by what they protect.

PermissionWhat it allowsWho usually needs it
Overall AdministerDo everything, including managing plugins, security, and running scripts on the serverA very small group of administrators
Overall ReadOpen Jenkins and see the basic pagesEvery legitimate user
Overall SystemRead, in newer versionsSee system configuration without changing itAuditors and support staff
Job ReadSee a job and its buildsTeam members and stakeholders
Job DiscoverLearn that a job exists, and be sent to log inRarely used, mostly for anonymous redirection
Job BuildStart a buildDevelopers and release staff
Job CancelStop a running buildDevelopers and release staff
Job ConfigureChange the definition of a jobTeam leads and pipeline owners
Job Create and Job DeleteAdd and remove jobsTeam leads
Job WorkspaceRead files in a job’s workspaceDevelopers debugging builds, with care
Run Delete and Run UpdateDelete builds and edit build descriptionsTeam leads
View permissionsSee, create, or change dashboard viewsTeam leads
Agent permissionsConnect, configure, or delete build agents, and build on themPlatform engineers
Credentials permissionsView, create, update, and use stored secretsOwners of the secrets, and job authors who use them
Everyday analogy

Think of a library’s rules. Reading a book, borrowing it, reserving a room, adding a new book to the collection, and closing the whole library are five very different powers, and no library gives all of them to every visitor.

Permissions that are more dangerous than they look

  • Job Configure. Anyone who can change a job can make it run any command on the build agents, and can often reach the credentials that the job uses. It is nearly as powerful as it sounds.
  • Job Workspace. Workspaces can contain secrets that builds wrote to disk.
  • Credentials Use. The right to use a credential in a job is more powerful than the right to view its entry.
  • Overall Administer. This includes the ability to run scripts on the controller, which amounts to full control of the machine.
!
Watch out

The list of permissions grows with each plugin you install, and names change between versions. Review the list of permissions on your own server, and look at what each new plugin adds before granting it broadly.

12Anonymous and Authenticated: The Special Identities

Two special identities appear in every Jenkins rule set. Understanding them prevents some of the most common mistakes.

Special

Anonymous

Stands for any visitor who has not logged in. Whatever you grant to anonymous is available to anyone who can reach the server’s address.

Special

Authenticated

Stands for every logged-in user, whoever they are. It is a convenient group that always contains everyone with a valid login.

Anonymous read access

Some strategies offer a tick box for allowing anonymous users to read. It lets people see the dashboard and job results without logging in. That may suit a public open source project. For an internal Jenkins, it exposes build logs, job names, and settings to anyone on the network, and logs sometimes contain sensitive information. The safe default for an internal server is no anonymous access at all.

Everyday analogy

A shop’s front window shows the goods to everyone in the street, whether or not they come in. That is anonymous read access. The stockroom, the till, and the safe are behind the counter for staff only. Decide deliberately what goes in the window.

Authenticated as a building block

Because “authenticated” includes everyone with a login, it is handy for granting basic rights, such as Overall Read, to all employees. But be careful. If the realm is an open directory, or allows sign-up, “authenticated” may include far more people than you intend. Anything you grant to “authenticated” is granted to every account the realm accepts.

ChoiceEffectRisk
Grant Read to anonymousAnyone who can reach Jenkins sees the dashboardLeaks job names, logs, and settings
Grant Read to authenticatedEvery logged-in user sees the dashboardFine when the realm is closed to strangers
Grant Build to authenticatedEvery logged-in user can start buildsCosts, unintended deployments
Grant Administer to authenticatedEvery logged-in user is an administratorTotal loss of control if sign-up is open or the directory is large
i
Tip

Open a private browser window, without logging in, and look at your Jenkins from the outside. What you can see there is exactly what anonymous visitors see. It takes thirty seconds and can be a surprising experience.

13API Tokens, Scripts, and Request Forgery Protection

People are not the only ones who talk to Jenkins. Scripts and other tools do too. They need identities as well.

API tokens

An API token is a long random secret that a user can generate in their own profile. A script sends it, together with the user’s name, instead of a password. Tokens have several advantages over passwords for automation. They can be created and revoked individually, so one leaked token does not force a password change. Several tokens can exist for one user, one per script. And they work with any security realm, including single sign-on, where scripts cannot log in through a browser.

Everyday analogy

A hotel guest gets a key card for the room, and can ask for extra cards for family members. If one card is lost, the hotel cancels that card only, and everyone else’s still works. Tokens are extra key cards for your account.

The rights of a token

A token acts with the same rights as the user who created it. It does not have a smaller set of powers. So a token created by an administrator is an administrator’s token. For automation, create a dedicated account for the script, give that account only the permissions it needs, and create the token under that account.

Good habits with tokens

  • One token per script, with a clear name.
  • Dedicated service accounts with minimal permissions.
  • Regular review and revocation of unused tokens.
  • Storing tokens in the Jenkins credentials store, or another secret manager.

Bad habits with tokens

  • Using an administrator’s personal token in a shared script.
  • Pasting tokens into chat, wikis, or source code.
  • Never rotating or deleting them.
  • Leaving tokens behind when people leave the company.

Cross-site request forgery protection

A web attack called cross-site request forgery tricks your browser, while you are logged in to Jenkins, into sending a hidden request to Jenkins from another website. To stop this, Jenkins can require a special one-time value, called a crumb, with each change made through the web interface. This protection is on by default in current Jenkins versions and should stay on. Scripts that call Jenkins over the web sometimes need to fetch a crumb first, or use an API token, which is exempt in the usual setups.

!
Watch out

Turning off request forgery protection to make a script work is like removing a door lock because you keep losing the key. Fix the script instead, by using a token or fetching the crumb, and leave the protection switched on.

14How It Works Internally

This chapter lifts the lid. Seeing the machinery makes many strange behaviours easy to understand.

The authentication object

For every request, Jenkins builds a small record of who is asking. It holds the user’s name, and the list of groups and special identities that apply to them: the groups from the realm, plus “authenticated” for logged-in users, or “anonymous” for others. This record travels with the request wherever it goes inside Jenkins. Even code that runs on behalf of a person, such as a build they started, is associated with an identity, either theirs or the system’s.

The permission check

Whenever Jenkins is about to do something that requires a right, for example showing a job page, it asks the access control list of that item: does this identity have this permission? The list belongs to the authorization strategy. In a global matrix, one list covers everything. In a project-based matrix, each job or folder may have its own list, and Jenkins combines it with the parent’s and the global one. In a role-based strategy, the plugin works out which roles apply to the item and the person, and answers from them. If the answer is no, Jenkins refuses.

Everyday analogy

A door with a card reader does not know you personally. It reads the card, looks up the card’s rights in a list, and opens or stays shut. The list is the access control list, and the card reader is the permission check that Jenkins performs at every door.

Where the pieces are stored

ItemWhere it livesNote
The choice of realm and strategyThe main configuration on the controllerAlso expressible as configuration as code
Users of the built-in databaseUser records in Jenkins’ data folder, with hashed passwordsBack up carefully, and protect from other operating system users
Users and groups of external realmsThe external directory or providerJenkins keeps only a light record of users who have logged in
Matrix and role rulesThe main configuration, or the plugin’s own configurationJob-level rules are stored with each job
API tokensWith the user’s record, in hashed formShown only once at creation

Sessions and caching

After login, Jenkins remembers a person with a session cookie. Group memberships from an external realm are often cached for a while, to avoid asking the directory on every click. This means that a change made in the directory, such as adding someone to a group, may take a little time to show up in Jenkins, and a person may need to log out and in again to see it at once.

i
Note

Details of caching and session handling vary by realm plugin and by Jenkins version. If a permission change does not seem to take effect, logging out and back in, or waiting a few minutes, is a sensible first test before digging deeper.

15Administrator Power and Separation of Duties

The administrator permission is the most powerful in Jenkins. Handling it well is the heart of a safe setup.

What administrator really means

Administrator, or Overall Administer, sounds like “can change settings”. In reality it means much more. An administrator can install plugins, change the security settings, read and change every job, and use the script console, a page that runs any program code on the controller. That code can read every stored credential in a decrypted form, read files on the server, and run commands as the account that Jenkins runs under. So, an administrator on Jenkins is very close to being a full administrator of the server itself.

Everyday analogy

The person who holds the master key to a bank not only opens the vault, but also changes the locks, hires the guards, and reads the security camera footage. Handing out that key is a serious step, and banks give it to very few people and record every use.

Practical rules

Rule 1

Keep the group tiny

A handful of people, with a named backup. If more people need to manage things, give them narrower permissions or roles instead.

Rule 2

Use separate accounts

Administrators should have an everyday account for normal work and a separate administrator account for management tasks.

Rule 3

Never share the account

Each administrator has their own login, so that actions are tied to a person.

Rule 4

Strong login

Prefer single sign-on with multi-factor checks for anyone who can administer Jenkins.

Rule 5

Log administrative acts

Record who changed security settings, installed plugins, or ran scripts, and review the records.

Rule 6

Delegate with roles

Team leads can manage their own folders without being administrators of the whole server.

Splitting the powers

Some setups separate powers further. Newer Jenkins versions add narrower permissions, for example one that lets a person read system configuration without changing it, which suits auditors and support staff. There is also an experimental permission for managing certain settings without full administrator rights. These options can reduce how many people hold the full permission, but they should be tested and understood before use, since the details depend on your version.

Running builds under specific identities

Builds also run as someone. By default, they run with the authority of the system, which may exceed that of the person who started them. Plugins exist that let a job run as a chosen user, so that the build has only that user’s rights. Used well, this limits what a compromised job can do. Used carelessly, it adds confusing layers, so keep it simple, and test it.

!
Watch out

Do not use the administrator account for everyday tasks such as browsing job results or starting builds. Every session with administrator power is a session where a mistaken click, a hijacked browser, or a stolen cookie could do very great harm.

16Security Considerations Beyond Permissions

Good login and permission settings are necessary, but not sufficient. These surrounding habits keep the whole setup strong.

AreaWhy it mattersWhat to do
Encrypted connectionsPasswords, tokens, and session cookies travel over the networkServe Jenkins only over HTTPS, usually through a reverse proxy, and redirect plain connections
UpdatesJenkins and its plugins publish security advisories oftenApply updates promptly, and subscribe to the advisories
Builds on the controllerBuild code running on the controller can reach Jenkins’ secretsSet the controller to zero build executors, and run builds on agents
Network exposureThe fewer people who can reach the login page, the fewer who can attack itRestrict access by network rules, VPN, or a gateway
PluginsEvery plugin adds code and permissionsInstall only what you need, and remove unused plugins
Agent connectionsAgents connect to the controller and receive work and secretsUse authenticated, encrypted agent connections, and keep agents patched
BackupsConfiguration and user data hold sensitive materialEncrypt backups, restrict access, and test restores
Recovery planA misconfiguration can lock everyone outDocument how administrators regain access, and who can do it
Everyday analogy

A house with an excellent front door lock still needs windows that close, a fence, and a plan for what to do if the key is lost. The login and permission settings are the front door. The rest of this chapter is the windows, the fence, and the spare key plan.

Reaching Jenkins safely

Most companies place Jenkins behind a reverse proxy or a gateway that handles encrypted connections, and often adds extra login checks or network limits. Others keep Jenkins reachable only from the company network or through a VPN. If Jenkins must be reachable from the internet, for example to receive webhooks from a code-hosting service, expose only the narrow paths that need it, and keep the login page out of public reach.

The lock-out problem

It is easy to change security settings in a way that stops everyone from logging in, including the administrator. A documented recovery path exists, which involves someone with access to the server temporarily switching security off in the configuration file and restarting. This is a last resort, requires access to the machine, and must be reversed at once. Because it can reset protections, restrict access to the server and to Jenkins’ data folder to the smallest possible group. It is much better to avoid the problem by testing changes carefully and keeping an administrator session open while you do.

i
Tip

Store your security settings as configuration in version control, using the configuration-as-code approach. Changes are then reviewed like any other code, mistakes can be rolled back, and a rebuilt server comes up with the same protections.

Strong locks on the front door are wasted if the windows are open.

17Monitoring, Auditing, and Troubleshooting

When a person cannot get in, or when you need to know who did what, here is where to look.

What Jenkins and its plugins can show you

  • The system log. Shows login failures, realm connection problems, and security warnings.
  • Audit plugins. Record who changed jobs, settings, and security rules, and when.
  • The users page. Lists known users and their last activity.
  • The permission and role screens. Show who holds which rights.
  • The web server or proxy logs. Show every request, including from tools and scripts, with addresses and outcomes.
  • The identity provider or directory logs. Show login attempts on the central side.
flowchart TD
  A["A user cannot log in or is denied"] --> B{"Can the user log in at all"}
  B -->|No| C{"Is the security realm reachable such as the directory or identity provider"}
  C -->|No| D["Fix the connection, certificates, or outage"]
  C -->|Yes| E["Check the user name format, password, account status, and realm settings"]
  B -->|Yes| F{"Is there an access denied message"}
  F -->|Yes| G["Check the groups the user belongs to and the permissions granted to them"]
  F -->|No| H["Check overall read, item level rules, folder inheritance, and cached group data"]
    
Figure 4. A decision path for login and access problems.

Common symptoms and causes

SymptomLikely causeWhat to do
Nobody can log in after a changeRealm settings wrong, or the realm is unreachableUse the documented recovery path, then correct the settings
A user logs in but sees an empty dashboardMissing Overall Read or Job Read for their groupsGrant read rights to the right group, and check inheritance
Rule for a group has no effectGroup name spelled differently in the provider and in JenkinsCompare the exact names sent by the realm
Change in the directory does not appearGroup data cached, or the session is oldLog out and in, or wait for the cache to expire
A user has more rights than expectedRights are added from several groups, roles, or authenticatedList all groups and roles the user has, and remove the source of the extra right
A script gets access deniedToken owner lacks permission, or the wrong user name is usedCheck the account that owns the token and its rights
Web request rejected as forbidden after loginMissing request forgery crumb in a non-browser toolUse an API token, or fetch a crumb first
Anonymous visitors can see jobsRead granted to anonymous, or a loose strategyRemove the grant, and test in a private window

Signals worth reviewing regularly

Once a quarter, review the list of administrators, the members of powerful groups and roles, the service accounts and their tokens, and the users who have not logged in for months. Check that anonymous access is what you intend. Compare the current security settings with the version in your records. Small drift, such as a temporary permission that was never removed, is the usual way a tidy setup decays.

i
Tip

When you debug an access problem, always test as the affected user, or with a similar test account, and not as an administrator. An administrator sees everything, and so cannot see the problem.

18Choosing a Setup, Patterns, and Anti-patterns

Patterns are choices that keep a Jenkins safe and easy to run. Anti-patterns are habits that slowly turn it into an open door.

A simple way to choose

flowchart TD
  A["Choosing an authorization strategy"] --> B{"Is it a personal or lab Jenkins with one trusted user"}
  B -->|Yes| C["Logged in users can do anything with no anonymous access and sign up off"]
  B -->|No| D{"Do teams need separate access to their own jobs"}
  D -->|No| E["Matrix based security with groups"]
  D -->|Yes| F{"Do you need pattern based rules across many teams"}
  F -->|Yes| G["Role based strategy with folders per team"]
  F -->|No| H["Project based matrix with folders"]
    
Figure 5. A quick decision path for picking an authorization strategy.

Patterns that help

Pattern

Central login

Use the company directory or single sign-on, so accounts and groups are managed in one place.

Pattern

Groups, not people

Write rules for groups. People join and leave groups in the directory, and Jenkins follows.

Pattern

Folder per team

Give every team a folder, and grant rights on the folder, so boundaries are visible and durable.

Pattern

Least privilege

Grant the smallest set of permissions that lets each role do its job, and add more only on request.

Pattern

Service accounts for scripts

Dedicated accounts with narrow rights and named tokens, never personal administrator tokens.

Pattern

Security as code

Keep the security configuration in version control, reviewed and reproducible.

Anti-patterns to avoid

ANTI-PATTERN 01 Avoid
Context

A team uses Jenkins’ own user database with sign-up allowed, and the strategy “logged-in users can do anything”, because it was quick to set up.

What goes wrong

Anyone who can reach the login page creates an account and becomes a full administrator. They can read stored credentials, run commands on agents, and change jobs. The first sign of trouble is often an unexpected deployment or a leaked key.

Better decision

Turn sign-up off, use a central login, and move to a matrix or role-based strategy with a small administrator group.

ANTI-PATTERN 02 Avoid
Context

Twenty engineers are all administrators, “so nobody is blocked”.

What goes wrong

Twenty accounts each hold the power to read every secret and run any command. One phished password, or one stolen laptop, compromises everything. Changes to settings become untraceable among many hands.

Better decision

Keep administrators to a small group. Give team leads folder-level rights through roles, and give developers the rights their work needs.

ANTI-PATTERN 03 Avoid
Context

Rules in the matrix name individual users, and new people are added by copying an existing row.

What goes wrong

The list drifts. People who changed teams keep their old rights, leavers stay in the matrix, and nobody can explain why a person has a right.

Better decision

Use groups from the directory, and review membership there. Jenkins rules then stay short and stable.

ANTI-PATTERN 04 Avoid
Context

A shared script uses an administrator’s personal API token, created years ago.

What goes wrong

The token has full power and no owner. When the person leaves, nobody knows what depends on it. If it leaks, an attacker has permanent administrator access.

Better decision

Create a dedicated service account with only the permissions the script needs, a named token, and a rotation date.

19Advantages, Trade-offs, Best Practices, and Common Mistakes

A balanced view of the Jenkins security model, and the habits that keep it working for you.

Advantages

  • Clear separation of identity and permission.
  • Many realms, so Jenkins fits most company setups.
  • Choice of strategies, from simple to fine-grained.
  • Group and folder support for team boundaries.
  • API tokens for safe automation.
  • Request forgery protection built in.

Disadvantages and trade-offs

  • Much of the model depends on plugins, with their own updates.
  • Rights only add up, so groups must be designed carefully.
  • Administrator power is very broad.
  • Lock-outs are possible after a bad change.
  • Permissions multiply with each plugin installed.
  • Security is only as strong as its weakest setting.

Best practices in one place

  1. Turn security on, and keep it on. Never run a real Jenkins with anyone able to do anything.
  2. Use a central realm. A directory or single sign-on, with multi-factor checks for administrators.
  3. Turn off sign-up on the built-in database, or avoid that realm for shared servers.
  4. Deny anonymous access unless the server is deliberately public.
  5. Grant rights to groups, and manage membership in the directory.
  6. Keep administrators to a few people, with separate accounts for administrative work.
  7. Use folders and roles or project matrices to give each team its own space.
  8. Use service accounts and named tokens for scripts, and rotate them.
  9. Serve Jenkins over HTTPS, limit who can reach it, and keep it and its plugins updated.
  10. Run no builds on the controller.
  11. Keep security settings as code, review changes, and record who made them.
  12. Review access quarterly, and test as an ordinary user.

The mistakes seen most often

Mistake 1: open sign-up with a loose strategy

Anyone can create an account and instantly holds full power. The fix is to disable sign-up and move to a real authorization strategy.

Mistake 2: forgetting Overall Read

A group has rights on its jobs but cannot even open the dashboard, so the team reports that Jenkins is broken. The fix is to grant the basic read right to authenticated users, or to the group.

Mistake 3: group name mismatch

The identity provider sends “Developers” and the rule says “developers”. No rights are granted, and nobody can tell why. The fix is to copy the exact group name from the provider.

Mistake 4: changing the realm without a safety net

An administrator switches to single sign-on, saves, and finds that the login fails for everybody. The fix is to keep an existing session open, test in a private window, and have a documented recovery plan.

Mistake 5: leavers keep access

People who left the company still have local accounts and tokens. The fix is a central realm, and a regular review of users and tokens.

20Worked Scenario: From an Open Jenkins to Team-Based Access

Let us follow one imaginary company as it tightens a Jenkins that grew without much planning.

The starting point

A company has one Jenkins server shared by four teams: Payments, Search, Mobile, and Platform. It was set up three years ago by one engineer. It uses Jenkins’ own user database with sign-up allowed, and the strategy “logged-in users can do anything”, with anonymous read access switched on so that managers can look at the dashboard. There are about sixty accounts. Nine belong to people who have left the company. Everyone, including an intern and two contractors, is effectively a full administrator. Last month, a contractor’s script accidentally deployed to the wrong environment, and nobody could say who had started it.

1

Take stock and switch off the worst risks

Sign-up is turned off, and anonymous read access is removed. The team checks the dashboard from a private window to confirm that strangers now see only the login page.

2

Move to central single sign-on

They install a single sign-on plugin and connect Jenkins to the company’s identity provider. They keep an administrator session open while testing the login in a private window, and they write down the recovery plan.

3

Agree on groups in the directory

The directory team creates groups such as payments-developers, search-developers, mobile-developers, platform-engineers, and jenkins-admins. The exact group names are copied into the Jenkins configuration.

4

Restructure jobs into folders

Every team gets a folder. Jobs are moved into their team’s folder, and job names are made consistent.

5

Switch to a role-based strategy

They define a viewer role for all authenticated users, a developer role and a team lead role for each team’s folder, and an administrator role for three named people. Rights are assigned to groups only.

6

Clean up scripts and tokens

Service accounts with narrow rights replace personal tokens. Old tokens are revoked, and each script gets its own named token with an owner and a review date.

7

Record, review, and repeat

An audit plugin is enabled, the security settings go into version control, and the team schedules a quarterly access review.

MeasureBeforeAfter
People with full administrator powerAbout 60, everyone who could log in3, in a named group
Who can create an accountAnyone who could reach the login pageOnly people the company directory accepts
What anonymous visitors seeThe whole dashboard and build logsOnly the login page
Accounts of people who left9 still active0, since login follows the directory
Team boundariesNone, every user could change every jobEach team manages only its own folder
Knowing who did whatGuessworkNamed users and audit records
Everyday analogy

It is like a shared office that used to have one front door, always open, with a single master key copied for everyone. The company installs a reception desk that checks badges against the staff register, gives each department a floor pass, and keeps the master key with three trusted people. Work carries on as before, but only the right people can do it.

i
Tip

The numbers here are made up to show the pattern. Do the change in steps, on a quiet day, and announce it beforehand. Nothing frustrates a team more than finding out about an access change when their build is refused.

21Real-World Usage Patterns

Here is how the security realm and authorization tend to be arranged in real Jenkins installations. These are illustrative patterns in general terms, not claims about the private setups of any particular company.

Jenkins is one of the most widely used automation servers, and organisations of every size face the same two questions of identity and permission. What tends to be common is a habit of using central login, giving teams their own folders, keeping administrators few, and reviewing access regularly. The patterns below show that habit in practice.

Pattern: a personal or lab Jenkins

One developer runs Jenkins on a laptop for learning. It uses the built-in user database with one account, no sign-up, and no anonymous access. The simplest strategy is acceptable, because there is one trusted person.

Pattern: a small company with a directory

A company of fifty connects Jenkins to its directory, and uses a matrix with three groups: administrators, developers, and viewers. The matrix has fewer than a dozen rows, so it is easy to read and audit.

Pattern: a large company with single sign-on and roles

A large organisation uses single sign-on with multi-factor checks, folder-per-team, and a role-based strategy. Team leads manage their own folders. A small platform group holds administrator rights and reviews them every quarter.

Pattern: a public open source project

A project lets anonymous visitors read build results, since they are public anyway. Only a few maintainers can configure jobs, and secrets are kept in scopes that outside contributors’ builds cannot reach.

Pattern: separate servers for separate trust levels

An organisation with strict rules runs one Jenkins for everyday development and a stricter one for production releases, with a much smaller set of users and tighter network rules on the second.

i
Note

Jenkins is often used with Docker, Kubernetes, and cloud platforms, which have identity and permission systems of their own. The best results come when Jenkins access, cloud access, and repository access are all narrow, so a mistake in one layer is caught by another.

22Frequently Asked Questions

Q1What is the difference between a security realm and an authorization strategy?
The security realm answers “who are you?” and handles login. The authorization strategy answers “what may you do?” and decides permissions. They are separate settings, chosen independently.
Q2Which security realm should I choose?
For a shared server, prefer a central one, such as your company directory or single sign-on, so accounts, groups, and multi-factor checks are managed in one place. The built-in database suits labs and personal use.
Q3Why is “logged-in users can do anything” risky?
Because every account that can log in becomes a full administrator. If the realm lets people sign up, or the directory is large, far more people hold that power than you intended.
Q4What is the difference between matrix and role-based security?
A matrix is a grid of users and groups against individual permissions. Role-based security groups permissions into named roles and assigns those roles, with patterns to cover jobs and agents. Roles scale better as the number of teams grows.
Q5Can I take away a permission from one member of a group?
No. Rights only add up. To treat one person differently, move them to a different group, or design groups so that each has only the rights its members should have.
Q6Should anonymous users be allowed to read?
Only if the server is deliberately public. On an internal Jenkins, anonymous read exposes job names, logs, and settings to anyone who can reach the address. Test with a private window to see what visitors see.
Q7How do scripts authenticate with single sign-on?
They use API tokens, which work independently of the browser login. Create a service account with the rights the script needs, generate a named token under it, and store the token securely.
Q8What can an administrator do that others cannot?
An administrator can change security settings, install plugins, and use the script console, which runs code on the controller and can read decrypted credentials. That is close to full control of the server, so keep the group small.
Q9I changed a group in the directory, but Jenkins does not notice. Why?
Group data is often cached, and the person’s session may hold old information. Ask them to log out and back in, or wait for the cache to expire.
Q10What if I lock myself out of Jenkins?
There is a documented recovery path that requires access to the server, where security is temporarily switched off in the configuration and restarted, and then corrected. Because that is powerful, restrict who can do it, and better still, avoid lock-outs by testing changes with a session kept open.
Q11Do API tokens have fewer permissions than the user?
No. A token has the same rights as the user who created it. Use dedicated accounts with minimal permissions for automation, rather than personal or administrator tokens.
Q12Is it safe to turn off request forgery protection?
No. It stops other websites from making your logged-in browser change Jenkins settings. If a script needs to work, use an API token or fetch a crumb, and leave the protection switched on.

23Summary and Key Takeaways

Key Takeaways

  • Two questions, two settings. The security realm answers who you are, and the authorization strategy answers what you may do. Both must be set carefully, and they can be chosen independently.
  • Prefer a central realm. A directory or single sign-on gives you groups, multi-factor checks, and one place to remove a leaver. Turn off open sign-up on the built-in database.
  • Avoid loose strategies. “Anyone can do anything” and “logged-in users can do anything” give full power to too many people. Use a matrix for small setups and roles or folder-level rules for many teams.
  • Write rules for groups, not people. Rights only add up, so design groups carefully, and manage membership in the directory.
  • Keep administrators few. Administrator power includes running code on the controller and reading credentials, so use separate accounts, strong login, and audit records.
  • Treat scripts as users. Give automation dedicated service accounts with narrow rights and named API tokens, and keep request forgery protection on.
  • Test, review, and plan recovery. Test changes with a session kept open, check what anonymous visitors see, review access every quarter, and keep security settings as code with a documented recovery path.