From 62dd8d503cfcd7c8a85a1345038f7ece008a13ac Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 23 Jul 2023 18:54:21 +0100 Subject: [PATCH 1/2] Allow the for changing of the UID/GID of the user/group pihole Signed-off-by: Adam Warner --- src/Dockerfile | 3 ++- src/start.sh | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Dockerfile b/src/Dockerfile index 1d7aec8..69cc365 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -28,7 +28,8 @@ RUN apk add --no-cache \ procps \ ncurses \ binutils \ - tzdata + tzdata \ + shadow ADD https://ftl.pi-hole.net/macvendor.db /macvendor.db COPY crontab.txt /crontab.txt diff --git a/src/start.sh b/src/start.sh index f538c29..94b6326 100644 --- a/src/start.sh +++ b/src/start.sh @@ -24,6 +24,25 @@ echo " [i] Starting docker specific checks & setup for docker pihole/pihole" # Initial checks # =========================== + +# If PIHOLE_UID is set, modify the pihole user's id to match +if [ -n "${PIHOLE_UID}" ]; then + currentId=$(id -u ${username}) + [[ ${currentId} -eq ${PIHOLE_UID} ]] && return + + echo " [i] Changing ID for user: pihole (${currentId} => ${PIHOLE_UID})" + usermod -o -u ${PIHOLE_UID} pihole +fi + +# If PIHOLE_GID is set, modify the pihole group's id to match +if [ -n "${PIHOLE_GID}" ]; then + currentId=$(id -g pihole) + [[ ${currentId} -eq ${PIHOLE_GID} ]] && return + + echo " [i] Changing ID for group: pihole (${currentId} => ${PIHOLE_GID})" + groupmod -o -g ${PIHOLE_GID} pihole +fi + fix_capabilities # validate_env || exit 1 ensure_basic_configuration From f09b0d68bbcc4082f9a3a5cad42657ed34d93fee Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 26 Jul 2023 08:31:29 +0100 Subject: [PATCH 2/2] Add tests for UID/GID switching Signed-off-by: Adam Warner --- test/tests/test_general.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/tests/test_general.py diff --git a/test/tests/test_general.py b/test/tests/test_general.py new file mode 100644 index 0000000..3a4be2c --- /dev/null +++ b/test/tests/test_general.py @@ -0,0 +1,11 @@ +import pytest + +@pytest.mark.parametrize("test_args", ['-e "PIHOLE_UID=456"']) +def test_pihole_uid_env_var(docker): + func = docker.run('id -u pihole') + assert "456" in func.stdout + +@pytest.mark.parametrize("test_args", ['-e "PIHOLE_GID=456"']) +def test_pihole_gid_env_var(docker): + func = docker.run('id -g pihole') + assert "456" in func.stdout \ No newline at end of file