diff --git a/docker-bake.hcl b/docker-bake.hcl index 1c080ac..6df8814 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -44,6 +44,7 @@ variable "LATEST_BENCH_RELEASE" { target "bench" { args = { GIT_REPO = "${BENCH_REPO}" + DEBIAN_BASE = "${DEBIAN_BASE}" } labels = { "org.opencontainers.image.source" = "https://github.com/frappe/frappe_docker" diff --git a/images/bench/Dockerfile b/images/bench/Dockerfile index b894abb..796a63d 100644 --- a/images/bench/Dockerfile +++ b/images/bench/Dockerfile @@ -1,4 +1,5 @@ -FROM debian:trixie-slim AS bench +ARG DEBIAN_BASE=trixie +FROM debian:${DEBIAN_BASE}-slim AS bench LABEL author=frappé @@ -76,14 +77,14 @@ RUN apt-get update \ file \ # For MIME type detection media-types \ - # Install wkhtmltopdf with patched qt \ + # Install wkhtmltopdf with patched qt && if [ "$(uname -m)" = "aarch64" ]; then export ARCH=arm64; fi \ && if [ "$(uname -m)" = "x86_64" ]; then export ARCH=amd64; fi \ && downloaded_file=wkhtmltox_${WKHTMLTOPDF_VERSION}.${WKHTMLTOPDF_DISTRO}_${ARCH}.deb \ && curl -sLO https://github.com/wkhtmltopdf/packaging/releases/download/$WKHTMLTOPDF_VERSION/$downloaded_file \ && apt-get install --no-install-recommends -y ./$downloaded_file \ && rm $downloaded_file \ - # Chromium \ + # Chromium && if [ "$INSTALL_CHROMIUM" != "false" ]; then \ DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ chromium-headless-shell; \ diff --git a/images/custom/Containerfile b/images/custom/Containerfile index 3b44601..a485095 100644 --- a/images/custom/Containerfile +++ b/images/custom/Containerfile @@ -81,7 +81,6 @@ RUN useradd -u 1000 -g 0 -d /home/frappe -ms /bin/bash frappe \ # OpenShift and arbitrary UID compatibility (GID 0 & group writable) && chgrp -R 0 /home/frappe /etc/nginx /var/log/nginx /var/lib/nginx /run \ && chmod -R g=u /home/frappe /etc/nginx /var/log/nginx /var/lib/nginx /run \ - && chmod g+w /etc/passwd \ && chmod 755 /usr/local/bin/nginx-entrypoint.sh \ && chmod 644 /templates/nginx/frappe.conf.template diff --git a/images/production/Containerfile b/images/production/Containerfile index b35bd0c..9ad612a 100644 --- a/images/production/Containerfile +++ b/images/production/Containerfile @@ -76,8 +76,7 @@ RUN useradd -u 1000 -g 0 -d /home/frappe -ms /bin/bash frappe \ && touch /run/nginx.pid \ # OpenShift and arbitrary UID compatibility (GID 0 & group writable) && chgrp -R 0 /home/frappe /etc/nginx /var/log/nginx /var/lib/nginx /run \ - && chmod -R g=u /home/frappe /etc/nginx /var/log/nginx /var/lib/nginx /run \ - && chmod g+w /etc/passwd + && chmod -R g=u /home/frappe /etc/nginx /var/log/nginx /var/lib/nginx /run COPY resources/core/nginx/nginx-template.conf /templates/nginx/frappe.conf.template COPY resources/core/nginx/nginx-entrypoint.sh /usr/local/bin/nginx-entrypoint.sh diff --git a/resources/core/main-entrypoint.sh b/resources/core/main-entrypoint.sh index f0f7664..d2ac6f9 100755 --- a/resources/core/main-entrypoint.sh +++ b/resources/core/main-entrypoint.sh @@ -3,16 +3,6 @@ set -e umask 0002 -if ! whoami &>/dev/null; then - if [ -w /etc/passwd ]; then - user_name="default" - if grep -q "^${user_name}:" /etc/passwd; then - user_name="default_$(id -u)" - fi - echo "${user_name}:x:$(id -u):0:${user_name} user:${HOME:-/home/frappe}:/bin/bash" >>/etc/passwd - fi -fi - ASSETS_PATH="/home/frappe/frappe-bench/sites/assets" BAKED_PATH="/home/frappe/frappe-bench/assets" diff --git a/tests/test_frappe_docker.py b/tests/test_frappe_docker.py index 2fc295e..906a21e 100644 --- a/tests/test_frappe_docker.py +++ b/tests/test_frappe_docker.py @@ -181,24 +181,21 @@ def test_arbitrary_uid_execution(compose: Compose): Executes the entrypoints directly to verify: - Container startup with arbitrary non-root UID (1000680000) and GID 0 - - Entrypoint dynamic user lookup (/etc/passwd mapping) - Effective runtime umask (0002) - Writability of required paths (/home/frappe, /tmp, sites directory) - - Frontend nginx configuration test and startup under arbitrary UID + - Frontend nginx configuration test under arbitrary UID """ check_script = ( "import os\n" - "import pwd\n" "import tempfile\n" "uid = os.getuid()\n" "gid = os.getgid()\n" "assert uid == 1000680000, f'Expected UID 1000680000, got {uid}'\n" "assert gid == 0, f'Expected GID 0, got {gid}'\n" - "user = pwd.getpwuid(uid).pw_name\n" - "assert user == 'default', f'Expected username default, got {user}'\n" "with open('/etc/passwd') as f:\n" " frappe_lines = [line for line in f if line.startswith('frappe:')]\n" "assert len(frappe_lines) == 1, f'Expected exactly 1 frappe user, found {len(frappe_lines)}'\n" + "assert not os.access('/etc/passwd', os.W_OK), '/etc/passwd must not be writable'\n" "old_umask = os.umask(0)\n" "os.umask(old_umask)\n" "assert old_umask == 0o002, f'Expected umask 0002, got {oct(old_umask)}'\n" @@ -208,7 +205,7 @@ def test_arbitrary_uid_execution(compose: Compose): " f.write(b'ok')\n" "with tempfile.NamedTemporaryFile(dir='/home/frappe/frappe-bench/sites') as f:\n" " f.write(b'ok')\n" - "print(f'VERIFIED:{user}:{uid}:{gid}')\n" + "print(f'VERIFIED:{uid}:{gid}')\n" ) compose(