Plugin hygiene and attack surface
Six plugins at the top of the tree, 75 installed, and how to keep them current.
cd ~/lab && curl -fsSLO https://secopslog.com/lab-files/ci-jenkins/plugins.tar.gz && tar -xzf plugins.tar.gz, which creates ~/lab/plugins/. SHA-256: 7190c549f78ef3d027558085159d582096ebdd13f7c4628765a09211f8382f54Open the Jenkins security advisories and scroll for a while. Most entries are about plugins, and many affect plugins nobody on the team remembers installing, with fixes that wait until someone gets around to clicking "update". Each plugin is code running inside your controller with full access to it. This lesson measures how much code that is on a small server, and how to keep it current without clicking around in production.
How many plugins do you really run?
Seventy-five plugins are installed. The second line lists the ones that nothing else depends on, the top of the tree: six. Everything else came along as a dependency, including things no one here asked for by name. why answers the question to ask before removing anything: git-client is here because git needs it. Before you add a plugin, look at what it brings with it, as you're adding that whole subtree to your attack surface.
Finding updates without touching the server
The plugin manager CLI, inside the image, compares your list with the update center. It doesn't change anything. This script wraps it for a scheduled job:
#!/usr/bin/env bash# Compares controller/plugins.txt with the update center, inside the controller image. Changes nothing.# The CLI caches update-center data, and the image already holds a copy from when it was built,# so the cache is cleared first: the check must ask the update center, not repeat old answers.# It exits non-zero when it can't check, so a scheduled job can't report "0 updates" when it couldn't look.# UC=URL points it at another update center (the lab uses that to show a failure).set -euo pipefaillatest=$(docker compose exec -T ${UC:+-e JENKINS_UC="$UC"} controller sh -c \'rm -rf ~/.cache/jenkins-plugin-management-cli && jenkins-plugin-cli --plugin-file /usr/share/jenkins/ref/plugins.txt --no-download --available-updates --output txt')[ -n "$latest" ] || { echo "no answer from the update center" >&2; exit 1; }echo "checked: $(grep -c . <<<"$latest")"echo "newer than the pin: $(sort controller/plugins.txt | diff - <(sort <<<"$latest") | awk '/^>/{n++} END{print n+0}')"
The first number is how many plugins were checked, and the second is how many have a newer release than the pin. A number above zero is a to-do list, not an emergency. A check that can't reach the update center must fail, not report zero updates. Point the script at an address where nothing listens:
Error getting update center json, and the script exits 1. That took a fix. The plugin CLI keeps a cache of update-center data, and building the image fills it. When the first version of this script ran shortly after a rebuild, it answered from that cache and reported checked: 75, newer than the pin: 0 with no update center reachable at all. So the script deletes the cache before each check. Test your own checks the same way, against an address where nothing listens.
Security warnings come from the same CLI:
Warnings come from the same update-center data, so the same cache applies. Here the check above had just refreshed it. --view-security-warnings prints any published advisory for the plugins in your list, and Done with nothing above it means none today. Run both on a schedule, as a job, and fail or notify if warnings appear. Remember this is point-in-time output, so yours will differ.
Jenkins itself has the same information once it has fetched the update center data:
To apply an update, the workflow is the one from the install lesson. Change the versions in controller/plugins.txt, rebuild the image, test on a throwaway instance, commit, and roll out. When you move to a new Jenkins LTS, check the plugin list against it before you change FROM: jenkins-plugin-cli --jenkins-version resolves the list for a given core version.
Rolling back is less simple than it looks. The official image copies its plugins into JENKINS_HOME/plugins on the volume. It upgrades a plugin there when the image has a newer version, but it never downgrades one, and it leaves alone any plugin someone updated through the UI. So an older image on the same volume keeps the newer plugins. A rollback means the previous image plus a restore of JENKINS_HOME from before the upgrade, which is another reason to back up first.
A pin that can't resolve
A wrong version fails while you're building the image, which is the cheapest place for it to fail. Compare that with finding the problem during a production restart.
| Habit | Why |
|---|---|
| Pin every plugin, including dependencies | Builds repeat, and each change shows up in review |
| Check for updates and warnings on a schedule | Advisories are public, so attackers read them too |
| Patch security warnings first, the rest in batches | Keeps upgrades small and regular |
| Remove what nothing uses | A plugin you don't have can't have a CVE |
Restrict Overall/Administer, so nobody installs plugins from the UI | A plugin added through the UI stays on the volume, outside the image and outside review |
Hands-on
In a fresh lab, run ./jk.sh '/pluginManager/api/json?depth=1&tree=plugins[shortName,version,hasUpdate,dependencies[shortName]]' and use jq to find the plugin with the most dependents. If you could remove pipeline-utility-steps from plugins.txt, would anything else in the list depend on it? Check with the why pattern. Finish with ./down.sh.
What you should see: commons-lang3-api and workflow-step-api are tied at 21 dependents each, followed by structs with 16, all libraries no one installs by name. Nothing in the list depends on pipeline-utility-steps, so it's a top-level plugin you could remove from plugins.txt once no Jenkinsfile uses its steps. The dependency list can't tell you about Jenkinsfiles, so search your repos for its steps, such as readJSON, too.
Remember
Six at the top turned into 75 on the server, so count the subtree before adding anything. Check for updates and warnings as a scheduled job that fails when it can't check, and change plugins only by editing plugins.txt and rebuilding the image.
plugins.txt. What is the right order of work?jenkins-plugin-cli catch a pin to a version that doesn't exist?unresolvable dependencies, which is the cheapest moment to find out.