Skip to content

Commit 347a51f

Browse files
committed
ilab-wrapper: Run podman with sudo
# Background The ilab command is wrapped by an `ilab` script which launches ilab inside a podman container. # Issue Since the ilab container image is pulled during the bootc image build process using the root user, the image is not accessible to non-root users. # Solution We run the container as sudo in order to be able to access the root container storage. But for security reasons we map root UID 0 inside the container to the current user's UID (and all the other subuids to the user's /etc/subuid range) so that we're effectively running the container as the current user. # Future work 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
1 parent 7409fdc commit 347a51f

File tree

2 files changed

+58
-22
lines changed
  • training
    • ilab-wrapper
    • nvidia-bootc/duplicated/ilab-wrapper

2 files changed

+58
-22
lines changed

training/ilab-wrapper/ilab

+29-11
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,39 @@ export ENTRYPOINT="/opt/python3.11/venv/bin/ilab"
88
export PARAMS=("$@")
99

1010
for dir in "$HOME/.cache" "$HOME/.config" "$HOME/.local"; do
11-
mkdir -p "$dir"
11+
mkdir -p "$dir"
1212
done
1313

1414
if [[ "$1" = "shell" ]]; then
15-
export ENTRYPOINT=bash
16-
export PARAMS=()
15+
export ENTRYPOINT=bash
16+
export PARAMS=()
1717
fi
1818

19-
PODMAN_COMMAND=("podman" "run" "--rm" "-it"
20-
"--device" "${CONTAINER_DEVICE}"
21-
"--security-opt" "label=disable" "--net" "host"
22-
"-v" "$HOME:$HOME"
23-
"--env" "HOME"
24-
"--entrypoint" "$ENTRYPOINT"
25-
"--env" "HF_TOKEN"
26-
"${IMAGE_NAME}")
19+
# We run the container as sudo in order to be able to access the root container
20+
# storage, which has the ilab image pre-pulled. But for security reasons we map
21+
# root UID 0 inside the container to the current user's UID (and all the other
22+
# subuids to the user's /etc/subuid range) so that we're effectively running
23+
# the container as the current user.
24+
#
25+
# In the future, we will run podman as the current user, once we figure a
26+
# reasonable way for the current user to access the root's user container
27+
# storage.
28+
CURRENT_USER_NAME=$(id --user --name)
29+
CURRENT_USER_SUBUID_RANGE=$(awk \
30+
--field-separator ':' \
31+
--assign current_user="$CURRENT_USER_NAME" \
32+
'$1 == current_user {print $2 ":" $3}' \
33+
/etc/subuid)
34+
IMPERSONATE_CURRENT_USER_PODMAN_FLAGS=("--uidmap" "0:$UID" "--uidmap" "1:$CURRENT_USER_SUBUID_RANGE")
35+
36+
PODMAN_COMMAND=("sudo" "podman" "run" "--rm" "-it"
37+
"${IMPERSONATE_CURRENT_USER_PODMAN_FLAGS[@]}"
38+
"--device" "${CONTAINER_DEVICE}"
39+
"--security-opt" "label=disable" "--net" "host"
40+
"-v" "$HOME:$HOME"
41+
"--env" "HOME"
42+
"--entrypoint" "$ENTRYPOINT"
43+
"--env" "HF_TOKEN"
44+
"${IMAGE_NAME}")
2745

2846
exec "${PODMAN_COMMAND[@]}" "${PARAMS[@]}"

training/nvidia-bootc/duplicated/ilab-wrapper/ilab

+29-11
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,39 @@ export ENTRYPOINT="/opt/python3.11/venv/bin/ilab"
88
export PARAMS=("$@")
99

1010
for dir in "$HOME/.cache" "$HOME/.config" "$HOME/.local"; do
11-
mkdir -p "$dir"
11+
mkdir -p "$dir"
1212
done
1313

1414
if [[ "$1" = "shell" ]]; then
15-
export ENTRYPOINT=bash
16-
export PARAMS=()
15+
export ENTRYPOINT=bash
16+
export PARAMS=()
1717
fi
1818

19-
PODMAN_COMMAND=("podman" "run" "--rm" "-it"
20-
"--device" "${CONTAINER_DEVICE}"
21-
"--security-opt" "label=disable" "--net" "host"
22-
"-v" "$HOME:$HOME"
23-
"--env" "HOME"
24-
"--entrypoint" "$ENTRYPOINT"
25-
"--env" "HF_TOKEN"
26-
"${IMAGE_NAME}")
19+
# We run the container as sudo in order to be able to access the root container
20+
# storage, which has the ilab image pre-pulled. But for security reasons we map
21+
# root UID 0 inside the container to the current user's UID (and all the other
22+
# subuids to the user's /etc/subuid range) so that we're effectively running
23+
# the container as the current user.
24+
#
25+
# In the future, we will run podman as the current user, once we figure a
26+
# reasonable way for the current user to access the root's user container
27+
# storage.
28+
CURRENT_USER_NAME=$(id --user --name)
29+
CURRENT_USER_SUBUID_RANGE=$(awk \
30+
--field-separator ':' \
31+
--assign current_user="$CURRENT_USER_NAME" \
32+
'$1 == current_user {print $2 ":" $3}' \
33+
/etc/subuid)
34+
IMPERSONATE_CURRENT_USER_PODMAN_FLAGS=("--uidmap" "0:$UID" "--uidmap" "1:$CURRENT_USER_SUBUID_RANGE")
35+
36+
PODMAN_COMMAND=("sudo" "podman" "run" "--rm" "-it"
37+
"${IMPERSONATE_CURRENT_USER_PODMAN_FLAGS[@]}"
38+
"--device" "${CONTAINER_DEVICE}"
39+
"--security-opt" "label=disable" "--net" "host"
40+
"-v" "$HOME:$HOME"
41+
"--env" "HOME"
42+
"--entrypoint" "$ENTRYPOINT"
43+
"--env" "HF_TOKEN"
44+
"${IMAGE_NAME}")
2745

2846
exec "${PODMAN_COMMAND[@]}" "${PARAMS[@]}"

0 commit comments

Comments
 (0)