Secure the Jenkins controller from unauthorized access by disabling anonymous read, choosing the right authentication scheme, implementing role-based access control, and mastering Script Security and the Groovy Sandbox.

In episode 10 we discussed how to store build artifacts and manage workspaces across agents. But there is one question we have not answered: who should be allowed to enter your Jenkins and what may they do?
Jenkins is often left running with very permissive default settings, including anonymous read access. In that state, anyone who knows your Jenkins address — including strangers on the internet — can read the job list, open configurations, and even see workspace contents containing source code and secrets. Imagine an office with the door wide open and every document on the desk readable without permission; that is the picture of an unsecured controller.
In this episode we will close those gaps one by one: disable anonymous access, choose an authentication scheme, implement Role-Based Authorization Strategy (RBAC), and then secure Groovy script execution with Script Security and the Groovy Sandbox. This topic must be mastered before your Jenkins touches a production network.
Before diving into the settings, remember two concepts that are often mixed up:
Note
Strong authentication without strict authorization is like having the lobby door locked while every room inside is wide open. Both must be configured together.
The most fundamental step lives in Manage Jenkins > Security. Check the Disable anonymous read access option so visitors without a login cannot see anything.
Next, set the authorization strategy. For a lab or experiments, choose Logged-in users can do anything — all authenticated users have full access. This is indeed safer than the default, but too broad for production; we will level up to RBAC in the next section.
Warning
Never choose Anyone can do anything in any environment, including a lab. That option opens the entire controller — including the ability to run jobs and read secrets — to everyone without a login.
Jenkins provides several ways to verify user identity. The best choice depends on the scale of your organization:
| Scheme | Advantages | When to Choose |
|---|---|---|
| Integrated User Database | No external server, quick to set up | Small teams, labs, proof of concept |
| LDAP / Active Directory | Company-centralized users & password policy | Companies with an AD domain |
| SAML / OAuth 2.0 | Single Sign-On to GitHub, GitLab, or an enterprise IdP | Organizations already using SSO |
All these schemes are chosen in Manage Jenkins > Security > Global Security under the Security Realm section. In episode 12 we will discuss one OAuth 2.0 derivative, OIDC, for passwordless cloud authentication.
After authentication, implement the Role-Based Authorization Strategy via the Role-based Authorization Strategy plugin. This plugin separates access rights into three scopes:
Overall/Administer, Overall/Read, Overall/Configure.my-app-*.How to activate: install the plugin, then in Manage Jenkins > Security > Global Security choose Role-Based Strategy as the authorization, and click Save. Next, the Manage and Assign Roles menu appears to define roles. An example of common role mapping in a development team:
| Role | Global | Item (Project) |
|---|---|---|
| Admin | Overall/Administer | All items |
| Developer | Overall/Read, Job/Read | Read, Build, Workspace, Configure |
| Tester | Overall/Read | Read, Build, Workspace |
With this pattern, a Tester can run builds and read their results but cannot change job configuration, while a Developer without Overall/Administer can still work on their project. Each user or group is then assigned to a specific role through the Assign Roles page.
Tip
Start with the smallest rights someone needs to do their job, then add as needs grow. This least privilege principle limits the impact if someone's account is compromised.
Jenkins pipelines run in the Groovy Sandbox by default. The sandbox restricts code so it cannot call dangerous methods outside the allowed area. If a pipeline tries to call a disallowed method, execution stops and Jenkins asks an admin to approve that script. An example of code that triggers the approval process:
stage('Cek Kapasitas Agent') {
steps {
script {
def node = hudson.model.Hudson.instance.getNode('linux-runner')
println "Total executors: " + node.getNumExecutors()
}
}
}The call hudson.model.Hudson.instance is a static method considered sensitive, so the pipeline stops with an error and shows a message like:
Scripts not permitted to use: staticMethod hudson.model.Hudson getInstance
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException:
Scripts not permitted to use: staticMethod hudson.model.Hudson getInstanceThe admin then opens Manage Jenkins > In-process Script Approval and chooses Approve or Deny for the rejected method signature. After approval, subsequent pipelines can call that method without hindrance.
Warning
Script approval is global and permanent until manually revoked. Do not approve methods carelessly just to get builds to pass — every approval expands the attack surface if there is an untrusted Jenkinsfile or shared library.
Cross-Site Request Forgery (CSRF) forces a victim to send requests without realizing it. Since Jenkins 2.0, CSRF protection is active by default: every POST request must include a per-session crumb token. When interacting via the API, you must fetch a crumb first and then send it via the Jenkins-Crumb header:
curl -s -u admin:API_TOKEN \
-c /tmp/crumb.jar \
https://jenkins.example.com/crumbIssuer/api/json
curl -s -u admin:API_TOKEN \
-b /tmp/crumb.jar \
-H "Jenkins-Crumb: <hasil-crumb>" \
-X POST \
https://jenkins.example.com/job/my-app/buildTip
For API automation that mimics browser interaction, always fetch the crumb first from the crumbIssuer endpoint. Some plugins and clients already handle this crumb automatically, but manual curl scripts do not.
In episode 11 you have learned to secure the Jenkins controller from the inside out: disabling anonymous read access, choosing an authentication scheme suited to team size, implementing RBAC with the Role-Based Authorization Strategy to separate the Admin, Developer, and Tester roles, understanding how Script Security and the Groovy Sandbox work along with the script approval process, and recognizing CSRF protection, which is active by default.
Security does not stop at controller settings. One point that still often leaks is static cloud credentials — for example an AWS Access Key stored permanently in Jenkins Credentials.
In episode 12 we will discuss Passwordless Cloud Authentication Using OIDC — replacing static credentials with short-lived tokens so authentication to AWS, GCP, and Azure becomes more secure and password-free. See you there!