Why Jenkins Needs Hardening
Jenkins can run commands on many machines and holds the keys to your code and servers. That makes it a high-value target. Most attacks use exposed servers, weak permissions, outdated plugins and leaked credentials, not magic. A few steady habits close most doors.
The Checklist
| Area | Do this |
|---|---|
| Network | Put Jenkins behind a reverse proxy with HTTPS; allow access only from the company network or VPN |
| Authentication | Use SSO (OIDC or SAML) with multi-factor authentication |
| Authorization | Matrix or role-based; no anonymous or open access |
| Built-in node | Set executors to 0: no builds run on the controller |
| Agents | Use ephemeral agents; limit what they can reach |
| CSRF | Keep Prevent Cross Site Request Forgery exploits enabled |
| Plugins | Install few; update regularly; remove unused; watch security advisories |
| Secrets | Use credentials store or Vault; no secrets in jobs, logs or Git |
| Scripts | Keep the sandbox on; review approvals; restrict the Script Console |
| Audit | Log who changed what; keep logs outside Jenkins |
| Backups | Back up JENKINS_HOME and test restores |
| Updates | Follow the LTS line and apply security fixes quickly |
HTTPS With a Reverse Proxy
- Set Jenkins URL (Manage Jenkins → System) to the
https://address to avoid the reverse proxy broken warning - Start Jenkins listening only on
127.0.0.1when the proxy is on the same host:--httpListenAddress=127.0.0.1 - Use certificates from your company CA or Let's Encrypt and renew automatically
Controller and Agents
- Manage Jenkins → Nodes → Built-In Node → Number of executors = 0. Builds then run only on agents, so a malicious build cannot read
JENKINS_HOME - Keep Agent → Controller Access Control enabled (it is on by default in current Jenkins). Do not turn it off
- Use separate agents for production deploys, with their own credentials and labels
- Prefer ephemeral (one build then destroyed) containers or VMs. No leftovers for the next job to find
- Firewall: agents reach the controller; the controller does not need to reach the internet more than plugins require
- For inbound agents, restrict the TCP agent port (or use WebSocket through HTTPS and disable the fixed port)
| Setting | Recommended |
|---|---|
| Built-in node executors | 0 |
| TCP port for inbound agents | Disabled if you use WebSocket or SSH agents |
| Agent protocols | Only current, secure ones (Inbound TCP agent protocol/4 over TLS if used) |
| CLI over remoting | Disabled; use HTTP/SSH CLI with tokens if needed |
CSRF and the Crumb
CSRF protection stops a malicious web page from making your browser send commands to Jenkins. Keep it enabled. Scripts using API tokens are not affected. Scripts using passwords may need a crumb:
Plugin Hygiene
- Subscribe to the Jenkins security advisories mailing list or RSS feed, and check Manage Jenkins → Plugins → Updates weekly
- The Plugin Manager shows warnings for plugins with known vulnerabilities
- Remove plugins no one uses. Each plugin is attack surface and a future upgrade problem
- Prefer actively maintained plugins; avoid ones marked as deprecated or up for adoption for critical work
- Test updates on a staging Jenkins with the same plugin list, then apply to production (JCasC plus a plugin list file makes this easy)
Reduce Powerful Features
| Risk | Action |
|---|---|
Script Console (/script) | Admin only. Log its use. Never expose it to many users |
| Freestyle jobs with shell by anyone | Limit Job/Configure to owners; use pipelines from SCM and code review |
| Replay of pipelines | Give Run/Replay only to trusted developers |
| Anonymous read access | Disable |
Old .war or Java versions | Upgrade. Jenkins LTS needs Java 21 or newer today |
| Public internet exposure | Use VPN, IP allow-list or an identity-aware proxy |
Audit and Monitoring
- Install the Audit Trail plugin: logs logins, job changes and builds to a file or syslog
- Forward logs to a central system (ELK, Loki, Splunk) that admins on Jenkins cannot edit
- Alert on: repeated login failures, new admin users, new credentials, new plugins, Script Console use
- Keep Job Configuration History to see who changed a job and when
Backups and Recovery
- Back up
JENKINS_HOME(config, jobs, secrets, plugins list) on a schedule. Keep the encryption key files (secrets/) with the backup in a protected place - Test restoring to a new machine every quarter
- With JCasC and Git, you can rebuild the whole controller from code
Monthly Security Review
- Check plugin updates and advisories; apply fixes
- List users and groups with Administer; remove those who left
- Review credentials: unused ones deleted, old ones rotated
- Look at audit logs for odd events
- Review agents: still ephemeral, still patched
- Confirm backups restore
Practice Tasks
- Place a lab Jenkins behind an nginx HTTPS proxy and fix the reverse proxy warning
- Set built-in node executors to 0 and run builds on an agent
- Run a build with an API token instead of a password
- Create
plugins.txtand rebuild a Jenkins Docker image with pinned plugins - Install the Audit Trail plugin and review a log line for a configuration change
Conclusion
Hardening Jenkins is a set of steady habits: HTTPS and a private network, SSO with matrix permissions, zero executors on the controller, ephemeral agents, CSRF on, few and updated plugins, a limited Script Console, audit logging and tested backups.

