Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't add a user with a high UID in docker Alpine

I'm trying to create a new user with UID 1340816314 inside an Alpine Linux Docker container in order to have a user with an UID matching a specific user on the host.

The problem is that I'm facing adduser: number 1340816314 is not in 0..256000 range even if I redefine the value of UID_MAX inside /etc/login.defs by following adduser man page. I don't think by the way that it has any impact as the adduser command in Alpine is from BusyBox.

Here is the log of what I try to do:

$ docker run -it --rm alpine:3.4 sh
/ # adduser -D -g '' -u 1340816314 user
adduser: number 1340816314 is not in 0..256000 range
/ # echo "UID_MAX 1340816314" > /etc/login.defs
/ # adduser -D -g '' -u 1340816314 user
adduser: number 1340816314 is not in 0..256000 range
/ # echo "UID_MAX 1340816315" > /etc/login.defs
/ # adduser -D -g '' -u 1340816314 user
adduser: number 1340816314 is not in 0..256000 range

Do you know how to add a user with a large UID in Alpine Linux inside a Docker container?

like image 951
Anthony O. Avatar asked Jan 23 '17 13:01

Anthony O.


People also ask

How do I add a user when I'm using alpine as a base image?

Alpine uses the command adduser and addgroup for creating users and groups (rather than useradd and usergroup ). Or alternatively, you can replace the whole snippet above using this: USER 405 which is the guest user within Alpine Linux.

What is UID in Docker?

Understanding how user names, group names, user IDs (uid), and group IDs (gid) map between the processes running in the container and the host system is important for building a secure system.


1 Answers

There is a more elegant solution to the high UID/GID in Alpine.

The package shadow contains the useradd and groupadd utilities which in turn supports higher values. Not sure which is the upper bound of those utils and if the whole 2^32 space is supported, but I've tested with values over 600 million and it works.

For example the commands to achieve this would look something like this:

UID=666000666
GID=999000999
apk add shadow
/usr/sbin/groupadd -g ${GID} my_group
/usr/sbin/useradd -s /bin/sh -g ${GID} -u ${UID} my_user

Note that I'm passing the shell variable to useradd as by default it tries to use /bin/bash which is not installed.

like image 97
Sebastian Cruz Avatar answered Sep 24 '22 06:09

Sebastian Cruz