Skip to content

Commit 41bfaaa

Browse files
committed
Try just letting podman run things as the "root" user inside the container
1 parent 9aefa14 commit 41bfaaa

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

bin/container-wrapper

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,31 @@ case "${uname_out}" in
3232
*) host_os="UNKNOWN:${uname_out}"
3333
esac
3434

35-
# not strictly required with magic in `container-entry` script and mostly for
36-
# when running on Linux, but explicitly run as host user to help avoid any file
37-
# permission issues with mounted locations from the host file system
38-
run_flags+=(--user "$(id -u):$(id -g)")
35+
# TODO: make a consolidated setting/detection for rootless podman which seems to
36+
# have broken --userns=keep-id/--userns=keep-id:uid=$(id -u),gid=$(id -g)
37+
# handling so we need to let things inside the container run as root to most
38+
# seamlessly map created files back to the hosts uid/gid
39+
40+
# mostly for when running on Linux, but when using a daemon running as root,
41+
# explicitly run the container as host user to help avoid any file permission
42+
# issues with mounted locations from the host file system
43+
if [[ "${CONTAINER_CMD}" == "docker" ]]; then
44+
run_flags+=(--user "$(id -u):$(id -g)")
45+
fi
46+
47+
48+
if [[ "${CONTAINER_CMD}" == "docker" ]]; then
49+
CONTAINER_USER_HOME="${HOME}"
50+
else
51+
# otherwise the host user is going to be map to root user in the container
52+
CONTAINER_USER_HOME="/root"
53+
fi
3954

4055
# connect the host git config if present, for better chance committing with work
4156
# inside the container (theoretically someone may not have their name/email
4257
# configured even if the config file exists)
4358
if [[ -e "$HOME/.gitconfig" ]]; then
44-
run_flags+=("-v=$HOME/.gitconfig:/.gitconfig")
59+
run_flags+=("-v=$HOME/.gitconfig:${CONTAINER_USER_HOME}/.gitconfig")
4560
fi
4661

4762
# figure out what location to mount for logs
@@ -61,7 +76,7 @@ fi
6176
if [[ ! -d "${HOST_LOG_DIR}" ]]; then
6277
mkdir -p "${HOST_LOG_DIR}"
6378
fi
64-
run_flags+=("-v=${HOST_LOG_DIR}:/.local/state/nava-platform-cli/log:z")
79+
run_flags+=("-v=${HOST_LOG_DIR}:${CONTAINER_USER_HOME}/.local/state/nava-platform-cli/log:z")
6580

6681
# process the script arguments
6782
for ((i=1;i<=$#;i++))

0 commit comments

Comments
 (0)