Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(docker): skip symlinks when re-owning /app/data
Yudhi Armyndharis8bb3f9a9e77a
diff --git a/Dockerfile b/Dockerfileindex f6be5943d..9847c5a56 100644--- a/Dockerfile+++ b/Dockerfile@@ -302,9 +302,10 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \# then drops to the openwa user via gosu before starting the node process.## NOTE — no `USER openwa` directive on purpose (Trivy DS-0002 will flag it, ignore).-# The Node process does NOT run as root: docker-entrypoint.sh:30 is-# `exec gosu openwa "$@"` after the chowns on lines 7 and 25. Adding `USER openwa`-# here would run the entrypoint as openwa and break the chown-before-drop pattern-# that makes named-volume mounts work on first boot (#254, #259).+# The Node process does NOT run as root: docker-entrypoint.sh ends with+# `exec gosu openwa "$@"`, after it chowns /app/data and the Chromium XDG+# dirs. Adding `USER openwa` here would run the entrypoint as openwa and break+# the chown-before-drop pattern that makes named-volume mounts work on first+# boot (#254, #259).ENTRYPOINT ["dumb-init", "--", "/usr/local/bin/docker-entrypoint.sh"]CMD ["node", "dist/main"]diff --git a/docker-compose.yml b/docker-compose.ymlindex 41e591501..070e1f1b9 100644--- a/docker-compose.yml+++ b/docker-compose.yml@@ -72,7 +72,7 @@ services:cap_drop:- ALLcap_add:- - CHOWN # entrypoint: chown -R openwa /app/data on the named volume+ - CHOWN # entrypoint: chown openwa /app/data on the named volume- DAC_OVERRIDE # entrypoint: chown across pre-existing files- FOWNER- SETGID # gosu: drop to the openwa groupdiff --git a/docker-entrypoint.sh b/docker-entrypoint.shindex 10c0b3a63..e1bf6dac2 100644--- a/docker-entrypoint.sh+++ b/docker-entrypoint.sh@@ -9,12 +9,15 @@ mkdir -p /app/data/sessions /app/data/media /app/data/plugins# not remove them on an unclean shutdown; stale locks block the next launch ("profile appears to be# in use by another Chromium process", exit Code 21). No Chromium is running yet at entrypoint time,# so clearing them lets sessions re-launch after a crash/restart. (#259)-# This runs BEFORE the chown: the three are symlinks, and a bind mount on Docker Desktop's file-# sharing refuses to change a symlink's owner. Under `set -e` that failed chown would stop the-# script before this cleanup and crash-loop the container on every restart (#1722).rm -f /app/data/sessions/*/Singleton* 2>/dev/null || true-chown -R openwa:openwa /app/data+# Re-own everything under /app/data except symlinks. Some bind mounts (Docker Desktop's file+# sharing) refuse to change a symlink's owner, which a link never needs, so a `chown -R` that met+# any link (a Chromium lock under a custom SESSION_DATA_PATH, a relocated session profile, a backup+# staging copy) failed under `set -e` and crash-looped the container on every start (#1722).+# Neither find nor `chown -h` follows a link, so a path swapped for a link between the walk and+# the chown never re-owns the link's target. A real chown failure still stops the script.+find /app/data ! -type l -exec chown -h openwa:openwa {} +# Chromium resolves its home from the passwd entry (no /home/openwa exists), so it hard-crashes at# launch unless its config/cache dirs exist and are writable. XDG_CONFIG_HOME/XDG_CACHE_HOME (set indiff --git a/src/common/ci-privilege-gate.spec.ts b/src/common/ci-privilege-gate.spec.tsindex 9a2d44c40..5e2ce16fb 100644--- a/src/common/ci-privilege-gate.spec.ts+++ b/src/common/ci-privilege-gate.spec.ts@@ -81,13 +81,28 @@ describe('the non-root drop is enforced, not merely documented', () => {expect(entrypoint).toMatch(/exec\s+gosu\s+openwa/);});- // The stale Chromium Singleton* entries are symlinks. A bind mount that refuses to chown a symlink- // (Docker Desktop file sharing) fails the recursive chown under `set -e`, so the cleanup has to run- // first or it never runs and the container crash-loops (#1722).- it('clears stale Chromium locks before the recursive chown', () => {+ // The Dockerfile explains the missing USER directive by pointing at the entrypoint. A line number+ // goes stale on the next entrypoint edit and sends the reader to the wrong statement.+ it('does not cite entrypoint line numbers from the Dockerfile', () => {+ const dockerfile = fs.readFileSync(path.join(__dirname, '..', '..', 'Dockerfile'), 'utf8');+ expect(dockerfile).toContain('docker-entrypoint.sh ends with');+ expect(dockerfile).not.toMatch(/docker-entrypoint\.sh:\d/);+ expect(dockerfile).not.toMatch(/chowns? on lines? \d/);+ });++ // Chromium's Singleton* locks, a relocated session profile and a backup staging copy are all+ // symlinks under /app/data. A bind mount that refuses to chown a symlink (Docker Desktop file+ // sharing) failed a recursive chown under `set -e` and crash-looped the container (#1722), and a+ // lock cleanup can only cover the default path. The ownership fix itself has to skip links.+ // `-h` too: find tests the type before the batched chown runs, so without it a path replaced by a+ // link in between would have root re-own the link's target.+ it('re-owns /app/data without touching symlinks', () => {const entrypoint = fs.readFileSync(path.join(__dirname, '..', '..', 'docker-entrypoint.sh'), 'utf8');const cleanup = entrypoint.search(/^rm -f \/app\/data\/sessions\/\*\/Singleton\*/m);- const chown = entrypoint.search(/^chown -R openwa:openwa \/app\/data/m);+ const chown = entrypoint.search(/^find \/app\/data ! -type l -exec chown -h openwa:openwa \{\} \+$/m);+ expect(entrypoint).not.toMatch(/^\s*chown\s+-R\b.*\/app\/data/m);+ // Swallowing the failure would hide a real refusal (NFS root_squash, SELinux).+ expect(entrypoint).not.toMatch(/-exec chown[^\n]*\|\|/);expect(cleanup).toBeGreaterThan(-1);expect(chown).toBeGreaterThan(-1);expect(cleanup).toBeLessThan(chown);