-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: use entrypoint id remapping instead
Switch everything to use entrypoint remapping. Use dumb-init to clean up any potential forks and gosu to switch user and execute command. Gosu is preferred over standard su because it ignores command line arguments and handles shell commands as well as binary paths. This uses the internal user and group "developer". Signed-off-by: Randolph Sapp <rs@ti.com>
- Loading branch information
1 parent
8cb4f58
commit 00bbc47
Showing
6 changed files
with
77 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
|
||
get_attribs() { | ||
local file_stats file_to_test useful_attribs | ||
if file_to_test=$(realpath "$1") && [[ $2 =~ ^[0-9]+$ ]] ; then | ||
useful_attribs=$(stat "$file_to_test" -t) | ||
read -r -a file_stats <<< "${useful_attribs#"$file_to_test"}" | ||
echo "${file_stats["$2"]}" | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
get_build_uid() { | ||
get_attribs /workdir 3 | ||
} | ||
|
||
get_build_gid() { | ||
get_attribs /workdir 4 | ||
} | ||
|
||
if NEW_GID=$(get_build_gid) && NEW_UID=$(get_build_uid); then | ||
# bypass everything if podman is remapping the id to root | ||
if [ "${NEW_UID}" == "0" ]; then | ||
if [ "$(id -u)" == "0" ]; then | ||
exec dumb-init -- "$@" | ||
else | ||
echo "Unable to resolve ns mapping!" | ||
fi | ||
fi | ||
|
||
# change the uid and gid of developer otherwise | ||
[ "$NEW_GID" != "$(id -g developer)" ] && groupmod -g "${NEW_GID}" developer | ||
[ "$NEW_UID" != "$(id -u developer)" ] && usermod -u "${NEW_UID}" developer | ||
else | ||
echo "Not able to detect UID/GID for remapping!" | ||
fi | ||
|
||
if [ "$(id -u)" == "$(id -u developer)" ]; then | ||
exec dumb-init -- "$@" | ||
else | ||
exec dumb-init -- gosu developer "$@" | ||
fi |