What brings the shell back into the image
For my runtime images on openSUSE Tumbleweed I had set myself two goals: no package manager, no shell. The package manager stayed out. The shell came back three times, each time by a different route, and the third time every tenant that synced during that window got stuck.
TL;DR
TL;DR: If you install RPM packages into an empty root, the scriptlets will almost inevitably pull a shell into the image. For the CA bundle there is no way around it, because the file is only created in %post. So I install normally, remove the shell afterwards and fail the build if one is left. Which package provides /bin/sh is better decided by you, otherwise the solver decides. The most expensive mistake was outside the image, though: an Argo CD PostSync hook started the kubectl image with /bin/sh -c. Before you remove a shell, look for every command that starts the image in the rendered manifests, not in the values.
The setup
My root file system is built by a small helper called koh-rootfs. It lives in the tumbleweed-builder image, the successor of wolfi-base, except that this time it is a builder and not a base: it holds zypper, the repositories and the keys, and the finished image holds none of them. The helper installs with zypper --root into an empty directory, with excludedocs and onlyRequires, and the result goes into a FROM scratch image via COPY. In the bash image it looks like this, shortened:
# renovate: datasource=custom.tumbleweed-snapshot depName=aarch64
ARG TW_SNAPSHOT_AARCH64=20261020.…
# renovate: datasource=custom.koh-snapshot depName=aarch64
ARG KOH_SNAPSHOT_AARCH64=20261104.…
FROM registry.ole-hartwig.eu/devops/images/tumbleweed-builder:1@sha256:… AS rootfs
ARG TW_SNAPSHOT_AARCH64
ARG KOH_SNAPSHOT_AARCH64
RUN koh-rootfs /rootfs @userland ca-certificates-mozilla
FROM scratch
COPY --from=rootfs /rootfs/ /
The difference between --installroot and --root is small on the command line and big in effect. With --root, zypper works entirely inside the target, with its repositories and configuration. --installroot also installs into the target, but additionally uses the repositories of the building system. A build could then pass and still install from a source I never chose. So never --installroot: koh-rootfs writes the two repository files, my Tumbleweed snapshot mirror and my own repository, straight into the target and deletes them again after the install. So what gets installed is not written in the image itself. It depends on the two snapshot pins, one for Tumbleweed and one for my repository, per architecture. pinup moves them, and nothing else in the image is pinned. If a pin does not reach the build stage, koh-rootfs silently takes the snapshot the builder brings along.
Two things stay in the image on purpose, even though nothing needs them at runtime: the RPM database and openSUSE-release. The scanner detects the operating system from the os-release file and the installed packages from the RPM database. If either is missing, it finds no operating system and simply reports nothing for the system packages. A clean result would then be no result at all. So the bash image checks this in its own smoke test: if ID="opensuse-tumbleweed" is not in /usr/lib/os-release, the build fails.
The price is space. The small job images grew by 25 to 50 MB, the bash image for example from 32 to 68 MB, 15 MB of that RPM database alone. On top of that comes the @userland group. On Wolfi, busybox brought grep, sed, awk and tar along as applets. Here the GNU tools sit in the image, each as a package of its own.
First: the CA bundle's scriptlet
The file in question is /var/lib/ca-certificates/ca-bundle.pem. In the ca-certificates package it is only listed as %ghost, an announced file without content. It is created by the %post scriptlet, which calls update-ca-certificates -f. For that the package also pulls in p11-kit-tools via Requires(post), and a shell scriptlet needs /bin/sh.
So the shell is in the image before any program has asked for it. The obvious way out, unpacking the packages with rpm2cpio, leads nowhere: without the scriptlet there is no bundle, and TLS connections from the container fail certificate verification. RPM does support embedded Lua scriptlets that run without an external shell. That only helps if a package uses them, and ca-certificates does not.
So I turn the order around. First everything is installed normally, scriptlets included. Then koh-rootfs removes the shell when I ask it to, and for me that is a single switch. The Caddy proxy, for example, is built with koh-rootfs /rootfs --no-shell caddy-koh wget ca-certificates-mozilla, while job images like bash leave the switch out. A final step checks that no shell is left:
for sh in sh bash zsh dash ash busybox; do
if [ -e "$ROOT/usr/bin/$sh" ] || [ -L "$ROOT/usr/bin/$sh" ]; then
echo "shell in image: /usr/bin/$sh" >&2; exit 1
fi
done
There are two ways to remove it, with different consequences. rpm --root "$ROOT" -e --nodeps --noscripts bash-sh bash keeps the RPM database consistent, and the scanner no longer sees bash. If you only delete the files, bash stays in the database, and the scanner keeps reporting vulnerabilities in a shell that is no longer in the image.
koh-rootfs --no-shell takes the first route. It looks up the packages that own the shell paths, adds every busybox package and removes them with rpm -e --nodeps --noscripts --notriggers. The RPM database then names exactly what is really in the image, and that is what the scanner reads. If a shell path is still left, the build fails. Users the tool creates get /usr/sbin/nologin instead of bash in this mode.
This has one more consequence: without a shell in the image, no shell-form smoke test runs either. The pipeline component for my images has had the input smoke-test-shell: injected for that since late October. It copies busybox from the builder into a throwaway stage on top of the image, tests there and discards the stage afterwards. The image ships without a shell.
Second: who provides /bin/sh
In Tumbleweed several packages provide /bin/sh, among them bash-sh, dash-sh, zsh-sh and busybox-sh. If a scriptlet only asks for some shell, the solver has to pick one. If the candidates look equal to it, an internal ordering decides in the end, not intent. On x86_64 I ended up with zsh-sh in the image, a shell I had never asked for.
If you want to see this beforehand, ask the repository, and after the build the RPM database:
zypper --root "$ROOT" search --provides /bin/sh
rpm --root "$ROOT" -q --whatprovides /bin/sh
Since then I name the provider explicitly in the package list wherever it matters: bash-sh. It costs one line and takes a decision away from the solver whose rules I am not watching. In the bash image the smoke test also checks that readlink -f /bin/sh really returns /usr/bin/bash.
The shell is only the most visible case. In the image for my GitOps jobs, git asks for a pager. Without a name, the solver picked busybox-less for it, and that brings busybox along, so a shell came in through the back door again. That is why less is named explicitly in the package list there, with a comment explaining why.
Third: a caller I did not know about
I built the kubectl image without a shell, together with the runtime images. That was the mistake, because it is not a runtime image but a job image. The tenant chart uses it in a hook that empties the edge proxy's Souin cache after a sync. Since mid-October it only does so when the rendered frontend has changed. For that comparison its container starts with command: ["/bin/sh", "-c"].
It is not a Helm hook but one of Argo CD's own, set through the annotation argocd.argoproj.io/hook: PostSync. Argo CD starts it once the sync has been applied, and if the hook job fails, the whole sync fails. That is exactly what happened. The container did not even start, because the runtime could not find /bin/sh, and every tenant that synced afterwards stopped with SyncFailed until the shell was back in the kubectl image. Helm hooks would have had the same effect, by the way: Argo CD maps pre-install and pre-upgrade to PreSync, and post-install and post-upgrade to PostSync.
The hook pods failed with exec: "/bin/sh": stat /bin/sh: no such file or directory. The job ran into BackoffLimitExceeded, and Argo CD reported SyncFailed. The workloads themselves had been applied; only the hook failed. It was fixed the same evening, a good half hour after the first failure: since then the kubectl image is built without --no-shell, with bash-sh named explicitly, and its smoke test runs under /bin/sh, just like the hook.
The annoying part: I had checked the chart beforehand. But only the values, and there was even a comment there that reassured me. It said the hook calls kubectl rollout restart as a bare argv and never starts a shell, so nothing depends on there being none. That was true in August, when the comment was written. In October the check for a changed frontend was added, hard-wired in the template and with /bin/sh -c. The comment in the values stayed.
Finding every caller
Whether an image needs a shell is not up to the image. It is up to everyone who starts it. You can only answer that from the rendered manifests, hooks included. helm template renders hooks by default, and Argo CD shows you the manifests it actually applies:
helm template tenant ./charts/tenant -f values.yaml \
| grep -nE '/bin/(ba|z|da)?sh|sh -c'
argocd app manifests <app> | grep -nE '/bin/(ba|z|da)?sh|sh -c'
Every match is a caller. No match does not yet mean nobody expects a shell, though. If a manifest sets neither command nor args, Kubernetes runs the image's own Entrypoint and Cmd. Those live in the image config:
crane config <image> | jq '.config.Entrypoint, .config.Cmd'
An entrypoint like ["/bin/sh", "-c", "…"] is the same mistake, one level down.
That leaves the question of how to debug an image without a shell. The answer is ephemeral containers. kubectl debug -it <pod> --image=<debug-image> --target=<container> attaches a container with tools to the running pod and shares the target's process namespace. Through /proc/<pid>/root you can also see its file system. The shell comes along for debugging and leaves again, instead of living in the image for good.
And the setuid files
The shell was not the only thing that came along uninvited. shadow and pam bring programs with the setuid or setgid bit, such as passwd and unix_chkpwd. If an image pulls in either package, it fails the check I use to harden images without a package manager. In a container nobody ever logs into, these bits serve no purpose. They are just attack surface.
So I strip them in the build step and check afterwards that nothing is left. File capabilities are the second route to elevated privileges and belong in the same check:
find "$ROOT" -xdev -type f -perm /6000 -exec chmod ug-s {} +
test -z "$(find "$ROOT" -xdev -perm /6000)"
test -z "$(getcap -r "$ROOT" 2>/dev/null)"
In the cluster there is a second layer. With allowPrivilegeEscalation: false, Kubernetes sets no_new_privs for the process, and setuid bits lose their effect even if one slips through. That does not replace the check in the build, but it catches the case the check misses.
Recommendations
- Separate job images from runtime images. A job image may carry a shell and the tools its jobs call. A runtime image carries neither, and each gets its own check rules.
- Remove the shell after the install, not before. The scriptlets need it, your container does not. Fail the build if one is still in the image afterwards.
- Pin providers where several are possible. Above all for
/bin/sh, and verify the result withrpm -q --whatprovides. - Look for callers in the rendered manifests. With
helm templateorargocd app manifests, hooks and init containers included. The image'sEntrypointandCmdcount too. - Check for setuid, setgid and capabilities.
find -perm /6000andgetcap -rhave to come back empty. In the cluster,allowPrivilegeEscalation: falseadds a safety net. - Debug with ephemeral containers.
kubectl debugbrings the shell along when you really need it.
Conclusion
A minimal image is not something the build tool produces. It is a contract with everyone who starts the image. For the runtime images that contract held. I carried it over to the kubectl image without first asking who actually calls it. So the question before the next removal is not whether the image runs without a shell. It is who starts it, and with what.
I check what your images really need before you remove it.
Shell, package manager, setuid files and every command that starts the image, in hooks and init containers too.
About the author

Kai Ole Hartwig
Programming since 2002 – self-taught, set up my own business with KO-Web in 2012. Over 100 projects, with a focus on security, performance, automation and quality. Today freelance: DevSecOps consulting, training and software development.
Newsletter
The week, in one email.
The new advisories and posts, once a week and briefly put in context. You will get a confirmation email first, and opens and clicks are only counted anonymously.
Almost there – please confirm your subscription via the link in the email I have just sent you.