Skip to content

Put a nobody user into /etc/passwd #332

Closed

Description

@thockin

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.

Activity

  1. hazcod commented on Mar 25, 2019

    @hazcod

    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.

  2. chanseokoh commented on Mar 25, 2019

    @chanseokoh
    Member

    Just for those who haven't realized: you can use a number and not put anything into /etc/passwd or /etc/group.

    USER 65534:65534

    The Linux kernel just sees these numbers. The names are purely cosmetic that various tools map for human consumption.

  3. thockin commented on Mar 25, 2019

    @thockin
    ContributorAuthor
  4. chanseokoh commented on Mar 25, 2019

    @chanseokoh
    Member

    @thockin I'm personally curious. What's the app that's causing an issue to you? Does the app not accept numbers?

  5. thockin commented on Mar 25, 2019

    @thockin
    ContributorAuthor
  6. chanseokoh commented on Mar 25, 2019

    @chanseokoh
    Member

    #335 merged. The new images will be auto-published soon. Thanks @thockin!

  7. hazcod commented on Mar 25, 2019

    @hazcod

    Do note that /bin/bash was added as a shell instead of /sbin/nologin, and not uid 1000.

  8. chanseokoh commented on Mar 25, 2019

    @chanseokoh
    Member

    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).

    But I think using 65534 for nobody is common.

  9. chanseokoh commented on Mar 25, 2019

    @chanseokoh
    Member

    Filed #337.

  10. hazcod commented on Mar 25, 2019

    @hazcod

    Thanks! Can we add a USER directive aswel, or will that interfere with the COPY?

  11. chanseokoh commented on Mar 25, 2019

    @chanseokoh
    Member

    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

    FROM gcr.io/distroless/java:11
    USER nobody:nobody

    and that's it.

  12. hazcod commented on Mar 25, 2019

    @hazcod

    @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.

  13. chanseokoh commented on Mar 25, 2019

    @chanseokoh
    Member

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions