Skip to content

Commit

Permalink
Merge pull request #5 from abims-sbr/supp_groups
Browse files Browse the repository at this point in the history
Add supplementary groups for `RUN_USER`
  • Loading branch information
abretaud authored May 22, 2023
2 parents 0b99f23 + 820ff01 commit 85da447
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ UID: the uid of the user
GID: the gid of the user
RUN_USER: the username of the user
RUN_GROUP: the group of the user
OTHER_GID: list of supplementary gid (comma separated) which the user is also a member of
OTHER_RUN_GROUP: list of supplementary group (comma separated) which the user is also a member of. The order must match the order used for OTHER_GID.
```
14 changes: 13 additions & 1 deletion scripts/pre-launch.d/08script_user
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@ if [ -n "$GID" ]; then
getent group $RUN_GROUP &> /dev/null || groupadd $GIDoption $RUN_GROUP
fi

if [ -n "$OTHER_GID" ]; then
IFS=',' read -ra OTHER_GID_ARRAY <<< "$OTHER_GID"
IFS=',' read -ra OTHER_RUN_GROUP_ARRAY <<< "$OTHER_RUN_GROUP"
length=${#OTHER_GID_ARRAY[@]}
groups="--groups "
for (( i=0; i<$length; i++ )); do
getent group ${OTHER_RUN_GROUP_ARRAY[i]} &> /dev/null || groupadd --gid ${OTHER_GID_ARRAY[i]} ${OTHER_RUN_GROUP_ARRAY[i]}
groups+="${OTHER_GID_ARRAY[i]},"
done
otherGIDoption=${groups::-1}
fi

if [ -n "$UID" ]; then
UIDoption="--uid $UID"
id -u $RUN_USER &> /dev/null || useradd -d /tmp/$RUN_USER --create-home --no-user-group $UIDoption $GIDoption $RUN_USER
id -u $RUN_USER &> /dev/null || useradd -d /tmp/$RUN_USER --create-home --no-user-group $UIDoption $GIDoption $otherGIDoption $RUN_USER
fi

0 comments on commit 85da447

Please sign in to comment.