Skip to content

Commit

Permalink
Merge pull request #729 from omertuc/norootmap
Browse files Browse the repository at this point in the history
ilab-wrapper: don't map UIDs if we're already running as root
  • Loading branch information
rhatdan authored Aug 6, 2024
2 parents cc2447e + 50fb00f commit 6662956
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions training/ilab-wrapper/ilab
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,30 @@ fi
# In the future, we will run podman as the current user, once we figure a
# reasonable way for the current user to access the root's user container
# storage.
CURRENT_USER_NAME=$(id --user --name)
CURRENT_USER_SUBUID_RANGE=$(awk \
--field-separator ':' \
--assign current_user="$CURRENT_USER_NAME" \
--assign current_uid="$UID" \
'$1 == current_user || $1 == current_uid {print $2 ":" $3}' \
/etc/subuid)
if [[ "$UID" == 0 ]]; then
# If we're already running as root, we don't need to map any UIDs
IMPERSONATE_CURRENT_USER_PODMAN_FLAGS=()
else
CURRENT_USER_NAME=$(id --user --name)
CURRENT_USER_SUBUID_RANGE=$(awk \
--field-separator ':' \
--assign current_user="$CURRENT_USER_NAME" \
--assign current_uid="$UID" \
'$1 == current_user || $1 == current_uid {print $2 ":" $3}' \
/etc/subuid)

# TODO: Handle multiple subuid ranges, for now, hard fail
if [[ $(wc -l <<<"$CURRENT_USER_SUBUID_RANGE") != 1 ]]; then
if [[ -z "$CURRENT_USER_SUBUID_RANGE" ]]; then
echo-err "No subuid range found for user $CURRENT_USER_NAME ($UID)"
else
echo-err "Multiple subuid ranges found for user $CURRENT_USER_NAME ($UID), this is currently unsupported"
echo-err "$CURRENT_USER_SUBUID_RANGE"
# TODO: Handle multiple subuid ranges, for now, hard fail
if [[ $(wc -l <<<"$CURRENT_USER_SUBUID_RANGE") != 1 ]]; then
if [[ -z "$CURRENT_USER_SUBUID_RANGE" ]]; then
echo-err "No subuid range found for user $CURRENT_USER_NAME ($UID)"
else
echo-err "Multiple subuid ranges found for user $CURRENT_USER_NAME ($UID), this is currently unsupported"
echo-err "$CURRENT_USER_SUBUID_RANGE"
fi
exit 1
fi
exit 1

IMPERSONATE_CURRENT_USER_PODMAN_FLAGS=("--uidmap" "0:$UID" "--uidmap" "1:$CURRENT_USER_SUBUID_RANGE")
fi

IMPERSONATE_CURRENT_USER_PODMAN_FLAGS=("--uidmap" "0:$UID" "--uidmap" "1:$CURRENT_USER_SUBUID_RANGE")
Expand Down

0 comments on commit 6662956

Please sign in to comment.