Merge pull request #1403 from pi-hole/v6/change-pihole-userid

Allow the for changing of the UID/GID of the user/group pihole
This commit is contained in:
Adam Warner 2023-07-26 17:37:59 +01:00 committed by GitHub
commit e0678bd803
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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