Unverified Commit b06cc313 authored by Keiven C's avatar Keiven C Committed by GitHub
Browse files

fix: preserve root group access when overriding Docker user (#5009)


Signed-off-by: default avatarKeiven Chang <keivenchang@users.noreply.github.com>
Co-authored-by: default avatarKeiven Chang <keivenchang@users.noreply.github.com>
parent 06c35f2d
...@@ -46,6 +46,7 @@ RUNTIME=nvidia ...@@ -46,6 +46,7 @@ RUNTIME=nvidia
WORKDIR=/workspace WORKDIR=/workspace
NETWORK=host NETWORK=host
USER= USER=
GROUP_ADD_STRING=
get_options() { get_options() {
while :; do while :; do
...@@ -327,6 +328,18 @@ get_options() { ...@@ -327,6 +328,18 @@ get_options() {
USER_STRING="--user ${USER}" USER_STRING="--user ${USER}"
fi fi
# If we override the user, Docker drops supplementary groups from the image.
# Add root group (GID 0) back so group-writable directories owned by root remain writable,
# avoiding expensive `chown -R ...` fixes on large mounted workspaces.
GROUP_ADD_STRING=""
if [[ -n "${USER}" ]]; then
# Extract just the UID part (before any colon)
USER_UID="${USER%%:*}"
if [[ "${USER_UID}" != "root" && "${USER_UID}" != "0" ]]; then
GROUP_ADD_STRING="--group-add 0"
fi
fi
REMAINING_ARGS=("$@") REMAINING_ARGS=("$@")
} }
...@@ -393,6 +406,7 @@ ${RUN_PREFIX} docker run \ ...@@ -393,6 +406,7 @@ ${RUN_PREFIX} docker run \
--ipc host \ --ipc host \
${PRIVILEGED_STRING} \ ${PRIVILEGED_STRING} \
${USER_STRING} \ ${USER_STRING} \
${GROUP_ADD_STRING} \
${NAME_STRING} \ ${NAME_STRING} \
${ENTRYPOINT_STRING} \ ${ENTRYPOINT_STRING} \
${IMAGE} \ ${IMAGE} \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment