Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(ci): actually run the non-root smoke test on the built image
Yudhi Armyndharisbdcda3c31725
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex fb5898dae..36551e786 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -425,3 +425,21 @@ jobs:sbom: truecache-from: type=ghacache-to: type=gha,mode=max++ # The image carries no USER directive by design: docker-entrypoint.sh starts as root to fix+ # named-volume ownership, then drops with `exec gosu openwa`. Nothing verified that drop —+ # smoke-test-non-root.sh existed but no job ran it, so a change leaving Node on uid 0 passed+ # every gate above and reached `latest`. Loaded single-arch from the same gha cache the+ # multi-arch build just populated, so this reuses those layers rather than building twice.+ - name: Load a single-arch image for the runtime smoke test+ uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7+ with:+ context: .+ load: true+ tags: openwa-ci:non-root-smoke+ cache-from: type=gha++ - name: Verify the image drops from root to the openwa user+ env:+ OPENWA_SMOKE_IMAGE: openwa-ci:non-root-smoke+ run: ./scripts/smoke-test-non-root.shdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0462bc6d1..73889451c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed+- The published image's drop from root to the `openwa` user is now verified in CI. The Dockerfile carries no `USER` directive by design — `docker-entrypoint.sh` starts as root to fix named-volume ownership and then runs `exec gosu openwa` — and `scripts/smoke-test-non-root.sh` was the only check of that drop, but no workflow ran it: its sole appearance in `ci.yml` was inside a comment. A change leaving the Node process on uid 0 passed lint, every test job, the multi-arch build and the image scan, and was promoted to `latest`. The Docker job now loads a single-arch image from the cache the multi-arch build already populated and runs the smoke test against it.+- The dashboard's dependency tree is now audited on both the PR and the tag path. It went unscanned by every job: `npm audit` ran against the root tree only, and the image scan sees OS packages and the built bundle rather than the npm graph behind it — so a HIGH advisory in a dependency that reaches an operator's browser could ride a release undetected. Two were present at this baseline: `socket.io-parser` (bundled into `dashboard/dist` via `socket.io-client`) and `brace-expansion` (dev-only, via ESLint), the latter pinned to a vulnerable version by an override that had not been bumped. Both are now overridden to patched releases.- `.env.example` shipped five keys the Infrastructure dashboard owns — `POSTGRES_BUILTIN`, `DATABASE_SSL`, `DATABASE_SSL_REJECT_UNAUTHORIZED`, `REDIS_BUILTIN` and `MINIO_BUILTIN` — uncommented, so an operator who followed the documented `cp .env.example .env` pinned them: the dashboard control still saved and reported success while the running value never changed, most consequentially leaving a Postgres connection unencrypted after the operator enabled SSL. The file's own header already promised a gate against this, but that gate only reached keys docker-compose forwards blank; it now covers every key the dashboard writes.diff --git a/scripts/smoke-test-non-root.sh b/scripts/smoke-test-non-root.shindex 5e13d36c8..e038ae6de 100755--- a/scripts/smoke-test-non-root.sh+++ b/scripts/smoke-test-non-root.sh@@ -8,10 +8,25 @@ set -e# so the build requires BuildKit. It's the modern default, but force it on in case the host disabled it.export DOCKER_BUILDKIT=1-IMAGE_TAG="openwa-test-non-root:smoke"+# CI already builds the image; set OPENWA_SMOKE_IMAGE to reuse that tag instead of paying for a+# second build. Unset (the local default) keeps the original behaviour: build here, remove after.+IMAGE_TAG="${OPENWA_SMOKE_IMAGE:-openwa-test-non-root:smoke}"+BUILT_HERE=0++if [ -z "${OPENWA_SMOKE_IMAGE:-}" ]; then+ BUILT_HERE=1+ echo "==> Building test image..."+ docker build -t "$IMAGE_TAG" .+else+ echo "==> Using pre-built image: $IMAGE_TAG"+fi-echo "==> Building test image..."-docker build -t "$IMAGE_TAG" .+# Only remove an image this script created — never one the caller handed us.+cleanup() {+ if [ "$BUILT_HERE" -eq 1 ]; then+ docker rmi "$IMAGE_TAG" > /dev/null 2>&1 || true+ fi+}echo ""echo "==> Checking process user inside container..."@@ -21,7 +36,7 @@ echo " $USER_OUTPUT"if echo "$USER_OUTPUT" | grep -q "uid=0(root)"; thenecho "FAIL: process is running as root!" >&2- docker rmi "$IMAGE_TAG" > /dev/null 2>&1 || true+ cleanupexit 1fi@@ -29,7 +44,7 @@ if echo "$USER_OUTPUT" | grep -q "openwa"; thenecho "PASS: process runs as openwa (non-root)"elseecho "FAIL: process is not running as the openwa user" >&2- docker rmi "$IMAGE_TAG" > /dev/null 2>&1 || true+ cleanupexit 1fi@@ -43,6 +58,6 @@ elseecho "WARN: PID 1 is '$PID1' (expected dumb-init) — check entrypoint chain"fi-docker rmi "$IMAGE_TAG" > /dev/null 2>&1 || true+cleanupecho ""echo "All smoke tests passed!"diff --git a/src/common/ci-privilege-gate.spec.ts b/src/common/ci-privilege-gate.spec.tsnew file mode 100644index 000000000..e67c2d3d1--- /dev/null+++ b/src/common/ci-privilege-gate.spec.ts@@ -0,0 +1,45 @@+import * as fs from 'fs';+import * as path from 'path';+import * as yaml from 'js-yaml';++/**+ * The published image has no `USER` directive by design: docker-entrypoint.sh starts as root to fix+ * named-volume ownership and then drops via `exec gosu openwa`. That drop is the only thing keeping+ * an internet-facing Node process (and its Chromium subprocess) off uid 0, and+ * `scripts/smoke-test-non-root.sh` is the only check of it.+ *+ * The script existed but no workflow ran it — its sole appearance in ci.yml was inside a comment+ * explaining why shellcheck names it. A change that left the process as root therefore passed lint,+ * every test job, the multi-arch build, the boot smoke and the image scan, and was promoted to+ * `latest`. These pin that the script is INVOKED, because a mention is not a gate.+ */++const workflowDir = path.join(__dirname, '..', '..', '.github', 'workflows');++type Workflow = { jobs?: Record<string, { steps?: Array<{ name?: string; run?: string; with?: unknown }> }> };++function runCommandsOf(file: string): string[] {+ const doc = yaml.load(fs.readFileSync(path.join(workflowDir, file), 'utf8')) as Workflow;+ return Object.values(doc.jobs ?? {}).flatMap(job => (job.steps ?? []).map(step => step.run ?? ''));+}++describe('the non-root drop is enforced, not merely documented', () => {+ // A `run:` extractor that silently matched nothing would make every assertion below vacuously+ // pass. Anchor it on a script the workflows have always invoked.+ it('extracts run commands from the workflows', () => {+ expect(runCommandsOf('ci.yml').join('\n')).toContain('smoke-test-backup-restore.sh');+ });++ it('invokes the non-root smoke test from ci.yml', () => {+ const invocations = runCommandsOf('ci.yml').filter(run => run.includes('smoke-test-non-root.sh'));+ expect(invocations.length).toBeGreaterThan(0);+ });++ // The Dockerfile relies on the entrypoint's gosu drop rather than a USER directive. If that ever+ // changes to a real USER line the smoke test still passes, but this records WHY the directive is+ // absent, so its absence is never read as an oversight and "fixed" by deleting the drop.+ it('keeps the entrypoint gosu drop the image depends on', () => {+ const entrypoint = fs.readFileSync(path.join(__dirname, '..', '..', 'docker-entrypoint.sh'), 'utf8');+ expect(entrypoint).toMatch(/exec\s+gosu\s+openwa/);+ });+});