You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having a named, non-root user and group in the base image would make non-root use-cases easier. It seems like a pretty common practice to say "USER nobody:nobody" in a Dockerfile.
Indeed, especially when people do not configure user namespace remapping.
What I do for the moment is copying over /etc/shadow, /etc/group and /etc/passwd from another image where I remove every user expect root and nobody + disable login shells for everyone.
FROM alpine:latest AS builder
RUN sed -i -r "/^(root|nobody)/!d" /etc/passwd /etc/shadow /etc/group \
&& sed -i -r 's#^(.*):[^:]*$#\1:/sbin/nologin#' /etc/passwd
FROM gcr.io/distroless/java:11
COPY --from=builder /etc/passwd /etc/shadow /etc/group /etc/
USER nobody
An important fact should be that user nobody should have a predictable user id, such as the typical 1000.
I hit this with SSH, which was not running `distroless` but convinced me
that this is not a case of universal "just use numbers" as a solution :)
So I built my own templates to use `USER nobody:nobody`. Switching that
from Alpine to distroless broke. That's what motivated this. If we can
get people to switch, it's a net positive for the world, so we should
reduce friction in any way possible.
Hmm... although /bin/bash doesn't exist and Distroless has been adding /bin/bash for root as well, that's a good point. It's easy to change it to /sbin/nologin (which doesn't exist either).
Sorry @hazcod, I didn't really get it, but if you were asking how your Dockerfile would look like with the new images with nobody, you no longer need a multi-stage build or COPY in regarding #332 (comment). You would probably just do
@chanseokoh I mean having a USER nobody:nobody in gcr.io/distroless/java itself, so people will no longer have to specify it manually. (and thus forget)
Every file copied into the container using COPY will also automatically inherit the user ownership.
I see no reason why they would want to do things as root anyway.
@hazcod ah, I was sure I was missing something. I had written some thoughts on this: #306 (comment). Personally I think we are fine with running as root.
Activity
hazcod commentedon Mar 25, 2019
Indeed, especially when people do not configure user namespace remapping.
What I do for the moment is copying over
/etc/shadow,/etc/groupand/etc/passwdfrom another image where I remove every user expect root and nobody + disable login shells for everyone.An important fact should be that user
nobodyshould have a predictable user id, such as the typical 1000.chanseokoh commentedon Mar 25, 2019
Just for those who haven't realized: you can use a number and not put anything into
/etc/passwdor/etc/group.USER 65534:65534The Linux kernel just sees these numbers. The names are purely cosmetic that various tools map for human consumption.
thockin commentedon Mar 25, 2019
chanseokoh commentedon Mar 25, 2019
@thockin I'm personally curious. What's the app that's causing an issue to you? Does the app not accept numbers?
thockin commentedon Mar 25, 2019
chanseokoh commentedon Mar 25, 2019
#335 merged. The new images will be auto-published soon. Thanks @thockin!
hazcod commentedon Mar 25, 2019
Do note that /bin/bash was added as a shell instead of /sbin/nologin, and not uid 1000.
chanseokoh commentedon Mar 25, 2019
Hmm... although
/bin/bashdoesn't exist and Distroless has been adding/bin/bashfor root as well, that's a good point. It's easy to change it to/sbin/nologin(which doesn't exist either).But I think using 65534 for
nobodyis common.chanseokoh commentedon Mar 25, 2019
Filed #337.
hazcod commentedon Mar 25, 2019
Thanks! Can we add a USER directive aswel, or will that interfere with the COPY?
chanseokoh commentedon Mar 25, 2019
Sorry @hazcod, I didn't really get it, but if you were asking how your
Dockerfilewould look like with the new images withnobody, you no longer need a multi-stage build orCOPYin regarding #332 (comment). You would probably just doand that's it.
hazcod commentedon Mar 25, 2019
@chanseokoh I mean having a
USER nobody:nobodyingcr.io/distroless/javaitself, so people will no longer have to specify it manually. (and thus forget)Every file copied into the container using
COPYwill also automatically inherit the user ownership.I see no reason why they would want to do things as root anyway.
chanseokoh commentedon Mar 25, 2019
@hazcod ah, I was sure I was missing something. I had written some thoughts on this: #306 (comment). Personally I think we are fine with running as root.