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

Ubuntu-22: Update entrypoint to run as non-root on macOS #93

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Ubuntu-22/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ It can be run like this:
```
docker run -it \
-v "${HOME}":"${HOME}" -e EDK2_DOCKER_USER_HOME="${HOME}" \
-e EDK2_DOCKER_USER="$(whoami)" -e EDK2_DOCKER_UID="$(id -u)" \
-e EDK2_DOCKER_GID="$(id -g)" \
ghcr.io/tianocore/containers/ubuntu-22-dev:latest /bin/bash
```

To enter the container as 'root', prepend the command to run with `su`, for example
```
docker run -it \
-v "${HOME}":"${HOME}" -e EDK2_DOCKER_USER_HOME="${HOME}" \
-e EDK2_DOCKER_USER="$(whoami)" -e EDK2_DOCKER_UID="$(id -u)" \
-e EDK2_DOCKER_GID="$(id -g)" \
ghcr.io/tianocore/containers/ubuntu-22-dev:latest su /bin/bash
```

Expand Down
10 changes: 10 additions & 0 deletions Ubuntu-22/ubuntu22_dev_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,20 @@ EDK2_DOCKER_USER=${EDK2_DOCKER_USER:-edk2}
# - Get the uid and gid from the user's home directory.
user_uid=$(stat -c "%u" "${EDK2_DOCKER_USER_HOME}")
user_gid=$(stat -c "%g" "${EDK2_DOCKER_USER_HOME}")

if [ ${user_uid} -eq 0 ] && [ -n "${EDK2_DOCKER_UID}" ]; then
user_uid=${EDK2_DOCKER_UID}
fi

if [ ${user_gid} -eq 0 ] && [ -n "${EDK2_DOCKER_GID}" ]; then
user_gid=${EDK2_DOCKER_GID}
fi

#
# - Add the group. We'll take a shortcut here and always name it the same as
# the username. The name is cosmetic, though. The important thing is that the
# gid matches.
groupdel $(getent group "${user_gid}" | awk -F ':' '{print $1}') || true
groupadd "${EDK2_DOCKER_USER}" -f -o -g "${user_gid}"
#
# - Add the user.
Expand Down
Loading