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

userlist / uid #9

Open
toastie89 opened this issue Feb 28, 2023 · 3 comments
Open

userlist / uid #9

toastie89 opened this issue Feb 28, 2023 · 3 comments
Assignees

Comments

@toastie89
Copy link

Adding the username, password and sudo as argument is simple and very convenient.

Still, for more complicated setups, I would wish to define users and passwords as a list.
Further, in my case, predefined UIDs are important to ensure access to shared volumes.

Would you accept a PR to run this script (link) when /etc/users.list exists and go for the existing solution, with the arguments, in case the file is missing?

@danchitnis
Copy link
Owner

It is a good idea, but all containers must be zero-config for all users. The additional config can be added if someone wants more functionality. It looks only need to add this test:

test -f /etc/users.list || exit 0

Can you attach an example for user.list?

@danchitnis danchitnis self-assigned this Feb 28, 2023
@toastie89
Copy link
Author

The users.list has the following format: id username password-hash list-of-supplemental-groups
E.g.: 1005 johndoe $1$6kLbPAuX$Wzw7rZNFedew3RLRCiXJb0 sudo

The following part would need to be added to your entrypoint script:

test -f /etc/users.list && {

while read id username hash groups; do
        # Skip, if user already exists
        grep ^$username /etc/passwd && continue
        # Create group
        addgroup --gid $id $username
        # Create user
        useradd -m -u $id -s /bin/bash -g $username $username
        # Set password
        echo "$username:$hash" | /usr/sbin/chpasswd -e
        # Add supplemental groups
        if [ $groups ]; then
                usermod -aG $groups $username
        fi
done < /etc/users.list
}

test -f /etc/users.list || {
# your user creation code
}

@danchitnis
Copy link
Owner

Sound good. Feel free to do a PR, and I will test it.

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