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

Run in docker as ~~non-root user~~ arbitrary UID? #180

Open
llwt opened this issue May 3, 2019 · 3 comments
Open

Run in docker as ~~non-root user~~ arbitrary UID? #180

llwt opened this issue May 3, 2019 · 3 comments

Comments

@llwt
Copy link

llwt commented May 3, 2019

Is there any way to get the dockerfile built running as a user other than root? We're looking to deploy this into our internal openshift cluster where we cannot run as the root user, and instead have a random UID assigned at container startup.

@llwt
Copy link
Author

llwt commented May 7, 2019

Workaround for anyone else that runs into this:

Dockerfile

FROM smarketshq/marge-bot:latest

COPY ./uid_entrypoint /bin/

# NOTE: in latest margebot image, /etc/passwd doesn't exist
RUN chmod u+x /bin/uid_entrypoint \
  && touch /etc/passwd \
  && chmod g=u /etc/passwd

ENTRYPOINT [ "uid_entrypoint", "/bin/marge.app" ]
USER 1001

uid_entrypoint

#!/bin/sh

if ! whoami &> /dev/null; then
  echo "user doesn't exist, attempting to create..."

  if [ -w /etc/passwd ]; then
    PASSWD_UPDATE="${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin"
    echo "updating passwd with: ${PASSWD_UPDATE}"
    echo "${PASSWD_UPDATE}" >> /etc/passwd
  else
    echo "/etc/passwd not writable, could not update..."
    exit 1
  fi
fi

exec "$@"

oscp docs on the matter

@llwt llwt changed the title Run in docker as non-root user? Run in docker as ~~non-root user~~ arbitrary UID? May 7, 2019
@snim2
Copy link
Contributor

snim2 commented May 29, 2019

I'm not sure whether it's useful to you, but I run marge-bot as a non-root user via systemd. Just make sure that you have User and Group set in the Service section of the service definition:

[Service]
User=marge-bot
Group=marge-bot
...

and follow a scheme a bit like this one.

@snim2
Copy link
Contributor

snim2 commented Mar 15, 2021

I won't delete the comment above, but I realise it's not actually related to this issue at all! Mea culpa.

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

2 participants