Jenkins Hardening Checklist: CSRF, HTTPS, Agent Security, Plugin Updates, Audit Logs and Safe Defaults

CI CD Pipelines with Jenkins 35 min min read Updated: Nov 17, 2026 Advanced
Jenkins Hardening Checklist: CSRF, HTTPS, Agent Security, Plugin Updates, Audit Logs and Safe Defaults
Advanced Topic 3 of 3

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

AreaDo this
NetworkPut Jenkins behind a reverse proxy with HTTPS; allow access only from the company network or VPN
AuthenticationUse SSO (OIDC or SAML) with multi-factor authentication
AuthorizationMatrix or role-based; no anonymous or open access
Built-in nodeSet executors to 0: no builds run on the controller
AgentsUse ephemeral agents; limit what they can reach
CSRFKeep Prevent Cross Site Request Forgery exploits enabled
PluginsInstall few; update regularly; remove unused; watch security advisories
SecretsUse credentials store or Vault; no secrets in jobs, logs or Git
ScriptsKeep the sandbox on; review approvals; restrict the Script Console
AuditLog who changed what; keep logs outside Jenkins
BackupsBack up JENKINS_HOME and test restores
UpdatesFollow the LTS line and apply security fixes quickly

HTTPS With a Reverse Proxy

nginx server { listen 443 ssl http2; server_name jenkins.example.com; ssl_certificate /etc/ssl/certs/jenkins.crt; ssl_certificate_key /etc/ssl/private/jenkins.key; ssl_protocols TLSv1.2 TLSv1.3; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_http_version 1.1; proxy_request_buffering off; # large artifact uploads proxy_read_timeout 90s; } } server { listen 80; server_name jenkins.example.com; return 301 https://$host$request_uri; }
  • 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.1 when 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
ini # /etc/default/jenkins or systemd override JENKINS_ARGS="--httpListenAddress=127.0.0.1 --httpPort=8080"

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)
SettingRecommended
Built-in node executors0
TCP port for inbound agentsDisabled if you use WebSocket or SSH agents
Agent protocolsOnly current, secure ones (Inbound TCP agent protocol/4 over TLS if used)
CLI over remotingDisabled; 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:

bash CRUMB=$(curl -s -u user:password 'https://jenkins.example.com/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)') curl -X POST -H "$CRUMB" -u user:password https://jenkins.example.com/job/demo/build
Use tokens: Switch scripts to API tokens and you will not need crumbs or a stored password.

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)
text # plugins.txt: pin the versions you tested (name:version) git:5.7.0 workflow-aggregator:600.vb_57cd credentials-binding:687.v619cb_15e923f configuration-as-code:1950.v0 # install with: jenkins-plugin-cli --plugin-file plugins.txt

Reduce Powerful Features

RiskAction
Script Console (/script)Admin only. Log its use. Never expose it to many users
Freestyle jobs with shell by anyoneLimit Job/Configure to owners; use pipelines from SCM and code review
Replay of pipelinesGive Run/Replay only to trusted developers
Anonymous read accessDisable
Old .war or Java versionsUpgrade. Jenkins LTS needs Java 21 or newer today
Public internet exposureUse 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

  1. Check plugin updates and advisories; apply fixes
  2. List users and groups with Administer; remove those who left
  3. Review credentials: unused ones deleted, old ones rotated
  4. Look at audit logs for odd events
  5. Review agents: still ephemeral, still patched
  6. Confirm backups restore

Practice Tasks

  1. Place a lab Jenkins behind an nginx HTTPS proxy and fix the reverse proxy warning
  2. Set built-in node executors to 0 and run builds on an agent
  3. Run a build with an API token instead of a password
  4. Create plugins.txt and rebuild a Jenkins Docker image with pinned plugins
  5. 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.

Quick Summary: HTTPS proxy; SSO + matrix; executors 0; agent security; CSRF crumb vs tokens; plugin hygiene + pinning; limit Script Console/Replay; Audit Trail; backups; monthly review.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators