Repository navigation
Description
The Docker image currently runs everything as root. With #401 complete (jlink-trimmed JRE, #993), the remaining obvious hardening gap is dropping root: container scanners flag it (CIS Docker Benchmark 4.1), and the Kubernetes restricted Pod Security Standard rejects root images unless deployments override runAsUser. Non-root was deliberately deferred from the #993 review as out of scope, and it changes long-standing defaults, so filing this to collect feedback before committing to an approach.
Current behavior
dumb-init,run-docker-container.sh, andjavaall run as uid 0.- The default
S3PROXY_ENDPOINT=http://0.0.0.0:80binds a privileged port. - The run script creates
JCLOUDS_FILESYSTEM_BASEDIR(default/data) at startup, which works only because root may create directories under/.
Proposal
- Create a dedicated
s3proxyuser and group with a fixed, documented uid/gid and add a numericUSER <uid>:<gid>(numeric so KubernetesrunAsNonRootvalidates without an explicitrunAsUser). - Change the default endpoint to
http://0.0.0.0:8080,EXPOSE 8080, and use 8443 in the secure-endpoint examples. - Pre-create
/datain the Dockerfile owned by that user, keeping the script'smkdiras a best-effort for custom basedirs.
Breaking changes and workarounds
1. Default port moves from 80 to 8080. Existing docker run --publish x:80 invocations, compose files, Kubernetes Services with containerPort: 80, and health checks must switch to port 8080. Workarounds:
- Update the mapping (
--publish 80:8080preserves the same host-side port), or - Keep the old behavior with
--env S3PROXY_ENDPOINT=http://0.0.0.0:80. Binding port 80 as non-root actually works on Docker ≥ 20.10 and rootless Podman because they setnet.ipv4.ip_unprivileged_port_start=0inside the container. It does not work on Kubernetes with containerd/CRI-O defaults; there you would additionally set that sysctl viasecurityContext.sysctls(allowed as a safe sysctl in recent Kubernetes) or fall back to--user root.
2. /data ownership. Bind mounts (--volume /host/dir:/data) whose host directory is owned by root or another uid will fail with permission errors. Named Docker volumes populated after this change inherit the image ownership and work; volumes created by older versions keep root ownership. Workarounds: chown the host directory to the documented uid, run with --user $(id -u) so the container matches the host owner, use Podman's :U volume flag or --userns=keep-id, or set fsGroup in the Kubernetes pod spec and let the kubelet fix ownership.
3. Derived images. Anything building FROM this image and running apt-get or writing to /opt/s3proxy must insert USER root before those steps (and ideally switch back afterwards). Files COPYed into derived images need to be readable by the s3proxy uid.
4. Mounted keystores and configs. A keystore for S3PROXY_SECURE_ENDPOINT (or any mounted config) must be readable by the non-root uid; previously root could read any mounted file. Workaround: chmod/chown the mounted file, or --user root.
In all cases --user root (or runAsUser: 0) restores the exact old behavior, so nothing is unfixable, but every workaround is action required from existing users, which is why this should land with a prominent release note, likely in a major version.
Alternatives considered
- Keep root as the default and only document
--user. Non-breaking, but running with--usertoday fails anyway because/datacannot be created and port 80 cannot be bound in some runtimes, so the image changes (pre-created/data, higher default port) are needed regardless; at that point the remaining difference is just whetherUSERis the default. - Publish a parallel
-nonroottag (as nginx does withnginx-unprivileged, or distroless with:nonroot). Zero breakage and lets users opt in, at the cost of a second image variant to build, test, and document. Could also serve as a transition period before flipping the default. setcap cap_net_bind_serviceon the java launcher to keep port 80. Rejected: setcap puts the binary in secure-execution mode, which disables the$ORIGINRPATH the JVM uses to locatelibjli, and file capabilities are unreliable across image copy/flatten steps.
Open questions
- Which uid?
ubuntu:24.04+ base images already reserve uid 1000 for the stockubuntuuser, so the choice is roughly: reuseubuntu(uid 1000, convenient for bind mounts matching the common first host user), delete it and creates3proxyas 1000, use a system uid (999), or follow the distroless convention (65532). - Flip the default in the next major release, or start with a
-nonroottag and flip later? - Is 8080 the right default port, or is there a strong reason to prefer another (e.g. 9000 as MinIO users expect)?
Comments welcome, especially from anyone running the image on Kubernetes or building derived images.
Activity
gaul commentedon Jul 25, 2026
@toindev FYI
BASKARUNIBASKARRAJU commentedon Sep 20, 2026
Hi @gaul , I’d be interested in working on this issue as an external contributor.
I’ve gone through the current behavior and the proposed approach, particularly the non-root user,
/dataownership, and the change from port 80 to 8080.I’d be happy to investigate and implement the changes, including updating the Docker image, handling the filesystem permissions, updating the relevant tests/documentation, and verifying the resulting image behavior.
Before I start working on it, could you confirm whether you’d be open to an external contributor taking this up? Also, if you have a preferred direction for the open questions around the UID/GID and whether this should initially be a
-nonrootimage or become the default in the next major release, I’d be happy to follow that direction.Thanks!
gaul commentedon Sep 21, 2026
I am happy to merge a contributor request. However this seems to require breaking user configurations so I want to understand the tradeoffs and how we can minimize the pain. Could you investigate and explain the options beyond the issue description?
BASKARUNIBASKARRAJU commentedon Sep 21, 2026
Thanks @gaul — here's the investigation you asked for. I've gone through the Dockerfile, the container start script, and the Kubernetes manifests to ground this in the current behavior.
Why it runs as root today
It comes down to one root cause: the default endpoint binds a privileged port,
http://0.0.0.0:80. Binding a port below 1024 needs root (orNET_BIND_SERVICE), so the image has noUSERdirective. Two related consequences:mkdir "${JCLOUDS_FILESYSTEM_BASEDIR}"(/data) at runtime, which only works because root can write to/— and it runs even for cloud backends that never use the filesystem.NET_BIND_SERVICEwith a comment pointing at this issue, and the README notes that full Pod Security Standardsrestrictedcompliance still needs a non-root image.Fix the port and pre-create
/data, and non-root falls out.What actually breaks, ranked by blast radius
docker run -p 80:80, k8scontainerPort/Service port, reverse-proxy upstreams, healthchecks. Even the CI smoke test maps host8080 → container 80./dataownership. A non-root uid can'tmkdir /dataor write to a bind-mount/PVC whose contents are root-owned. Existing volumes need a one-timechownor a k8sfsGroup.FROM andrewgaul/s3proxyimages runningapt/apknow needUSER rootbefore andUSER s3proxyafter.Open questions
UID/GID: 1000 collides with host uid 1000 on bind mounts; 999 is arbitrary; 65532 (distroless
nonroot) is the de-facto container convention, collision-unlikely, and pairs naturally withrunAsNonRoot: true/runAsUser: 65532. I'd assign 65532 and document it as a stable contract.Port: 9000 collides with MinIO/PHP-FPM/SonarQube. 8080 is already what the non-Docker docs use (README, SFTP), so it's the consistent pick.
Rollout — the crux of your question:
-nonroottag. Publish:<version>-nonrootalongside the root default; flip the default at a future major.(The "document
--useronly" alternative I'd reject: it leaves the default insecure and, because of the runtimemkdir,--useralone actually breaks the current image.)Recommendation
Option B — flip the default at 5.0, with the migration made as painless as the format allows. A major version is exactly where users expect breaking changes and read release notes, so it charges the cost once, at the cheapest moment. Option A defers the same breakage while doubling maintenance forever and leaves the default image insecure — the very thing this issue is about. The blast radius here is bounded and mechanical (a port number and a
chown), which is easy to document.Concretely I'd ship with B:
/dataowned by 65532 in the Dockerfile and drop the runtimemkdir(this also lets cloud-backend pods keepreadOnlyRootFilesystem: truewithout an emptyDir hack).:8080,EXPOSE 8080 443, addUSER s3proxy(65532).runAsNonRoot: true,runAsUser: 65532,fsGroup: 65532, dropNET_BIND_SERVICE, repoint ports to 8080, remove the issue-Run the Docker image as a non-root user #1121 comments.:8080and assert the process runs as 65532 (guards against regressions).chown -R 65532:65532existing/data(or setfsGroup);USER root/USER s3proxyaroundaptin derived images; keystores readable by 65532. Note--publish 80:8080as an escape hatch for anyone who must keep port 80 externally.No Java changes — the app binds whatever endpoint it's given; the port is purely a packaging default.
If you'd rather avoid any forced change even at a major, I'm happy to do Option A instead — but framed as a time-boxed deprecation (ship
-nonrootnow, announce the default flip at a named major), not an indefinite dual image. Let me know which direction you prefer and I'll open a PR.