Skip to content

Commit 3c0a5e6

Browse files
authored
Merge pull request #48 from OpenConext/fix/python-runas2
Fail when RUNAS_* is absent
2 parents 547093d + a3e7ff2 commit 3c0a5e6

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

python3/bin/entrypoint.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
#!/usr/bin/env bash
2-
DEFAULT_UID=10000
3-
DEFAULT_GID=10000
4-
52
set -e
63

74
if [[ -v DEBUG ]]
@@ -85,8 +82,15 @@ then
8582
fi
8683

8784
# set up privilege dropping to user and group
88-
PRIVDROP=$(create_user_and_group "${RUNAS_UID:-$DEFAULT_UID}" "${RUNAS_GID:-$DEFAULT_GID}")
89-
echo "Dropping privileges to $($PRIVDROP id -u):$($PRIVDROP id -g)"
85+
PRIVDROP=
86+
if [ -n "$RUNAS_UID" ] || [ -n "$RUNAS_GID" ]
87+
then
88+
PRIVDROP=$(create_user_and_group "${RUNAS_UID}" "${RUNAS_GID}")
89+
echo "Dropping privileges to $($PRIVDROP id -u):$($PRIVDROP id -g)"
90+
else
91+
echo "ERROR: Please set RUNAS_UID and RUNAS_GID environment variables"
92+
exit 1
93+
fi
9094

9195
# run custom scripts before dropping privileges
9296
echo "Running custom scripts in /container-init as root"

python3/test.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ echo "Remove old container"
77
docker rm python3
88

99
# With RUNAS_UID and RUNAS_GID
10-
echo
11-
echo "Run image with env"
12-
docker run --name python3 --env RUNAS_UID=10001 --env RUNAS_GID=10001 python3:test
10+
# echo
11+
# echo "Run image with env"
12+
# docker run --name python3 --env RUNAS_UID=10000 --env RUNAS_GID=10000 python3:test
1313

1414
# Without RUNAS_UID and RUNAS_GID
15-
# echo
16-
# echo "Run without env"
17-
# docker run --name python3 python3:mve
15+
echo
16+
echo "Run without env"
17+
docker run --name python3 python3:test
1818

1919
echo
2020
echo "Start container"

0 commit comments

Comments
 (0)