Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-root run #98

Open
casperdcl opened this issue Oct 8, 2024 · 4 comments
Open

non-root run #98

casperdcl opened this issue Oct 8, 2024 · 4 comments

Comments

@casperdcl
Copy link
Contributor

casperdcl commented Oct 8, 2024

potentially worth documenting how to run as non-root users (related: caddyserver/caddy-docker#104)?

I had to do:

FROM wemakeservices/caddy-gen:latest
ARG CADDY_UID=1000
ARG CADDY_GID=1000
RUN chown -R $CADDY_UID:$CADDY_GID /etc/caddy /config/caddy /code/docker-gen/templates/Caddyfile.tmpl
RUN chmod a+x /usr/bin/forego
USER $CADDY_UID:$CADDY_GID

which allows building using e.g. --arg CADDY_GID=$(getent group docker | cut -d: -f3) --arg CADDY_UID=$(id -u)

@sobolevn
Copy link
Member

sobolevn commented Oct 8, 2024

I think that we can try adding this to the base image 🤔

@casperdcl
Copy link
Contributor Author

casperdcl commented Oct 8, 2024

apart from chmod a+x /usr/bin/forego, this won't really affect the base image... the CADDY_UID, CADDY_GID must be overridden by the user.

Alternatively, I suppose the "correct" way is to have:

casperdcl added a commit to SyneRBI/PETRIC-backend that referenced this issue Oct 19, 2024
casperdcl added a commit to SyneRBI/PETRIC-backend that referenced this issue Oct 20, 2024
@polarathene
Copy link

polarathene commented Feb 24, 2025

You should prefer to run as non-root via rootless containers instead, or when supported via --user should you need rootful containers and the convenience of running as your host user (--user in this way has the same caveat as described below).

If you're choosing to run a rootful container as non-root for security reasons, and some exploit did permit a container escape... should that host user have permission to use the CLI to docker daemon without credentials (as is often a convenience done), you would be avoiding the non-root security benefit since the attacker could become root and own the system anyway 🤷‍♂ (similar to access to the docker socket in the container)

The non-root in container practice is meant to avoid that by not sharing an ID with the host that has such privilege.

@sobolevn
Copy link
Member

PR is welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants