fix: remove insecure /etc/passwd write permissions and parameterize bench debian_base

- Remove chmod g+w /etc/passwd and dynamic /etc/passwd entrypoint edits (handled natively by CRI-O)
- Assert /etc/passwd is not writable in integration test
- Parameterize DEBIAN_BASE in bench Dockerfile and pass to bench target in docker-bake.hcl
- Clean up comment backslashes in bench Dockerfile and correct test docstring
This commit is contained in:
Revant Nandgaonkar 2026-09-21 15:35:51 +05:30
parent 6303620ff8
commit 5245412ac5
6 changed files with 9 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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