Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add rootless Docker images for enhanced security and Kubernetes/OpenShift compatibility
Purpose
This PR adds rootless variants of the Caddy Docker images that run as a non-root user (UID 1001), making them suitable for security-constrained environments like Kubernetes and OpenShift, while remaining a drop-in replacement for the alpine images.
Why rootless?
Security best practices: Running containers as root is discouraged in production environments. Non-root containers provide defense-in-depth by limiting the impact of potential container breakouts or exploits.
Kubernetes/OpenShift requirements: Many Kubernetes clusters enforce Pod Security Standards that prohibit root containers. OpenShift, in particular, assigns arbitrary UIDs to containers by default and requires images to support this pattern.
Port restrictions: Non-root users cannot bind to privileged ports (< 1024). Using ports 80 and 443 in Kubernetes is problematic anyway since:
What's included
New image variants:
caddy:rootless- Rootless runtime image (ports 8080, 8443, 2019)caddy:rootless-builder- Rootless builder image for custom Caddy builds with xcaddyKey features:
Implementation details:
The rootless templates are based on the standard alpine templates with these modifications:
setcapcapability (not needed for non-privileged ports)adduser -D -u 1001 -g 0chown 1001:0) and group permissions (chmod g+w) on all Caddy directoriessedto replace:80with:{$CADDY_HTTP_PORT:8080}CADDY_HTTP_PORT=8080andCADDY_HTTPS_PORT=8443environment variablesUSER 1001directive to run as non-rootTesting
Built and tested locally - serves the welcome page on port 8080 as expected. The image runs without root privileges and properly serves static content.