Repository navigation
Description
Summary
The Dockerfile does not chown the npm cache directory under /home/madz, so it is left owned by root when the container is used. The madz user then hits EACCES when npm tries to read or write the cache.
Environment
- OS: Linux 7.0.14-linuxkit
- Node.js: v26.13.0
- madz version: 1.129.2
- LLM provider: Unknown — user to confirm
Reproduction
Steps to reproduce the behavior:
- Build the image:
docker build -t madz:latest . - Start the container and SSH in as the
madzuser (the entrypoint startssshd; themadzuser has an empty password). - As
madz, run any npm command that touches the cache, e.g.npm install -g <pkg>ornpm cache verify. - Observe a permission error on
/home/madz/.npm.
Expected Behavior
The npm cache directory under /home/madz (e.g. /home/madz/.npm) should be owned by madz:node so the madz user can read and write it without EACCES.
Actual Behavior
The npm cache directory under /home/madz is owned by root. Commands run as the madz user fail with a permission error such as EACCES: permission denied when npm attempts to access the cache.
Additional Context
The root cause is an ordering problem in the Dockerfile. The recursive chown -R madz:node /app /home/madz runs at line 57, but the global npm installs (npm install -g yarn pnpm and npm install -g @fission-ai/openspec@latest) run afterward at lines 66–70 as root. Because ENV HOME=/home/madz is set at line 53, those global installs populate the npm cache under /home/madz as root, and nothing re-chowns it. The fix is either to reorder the chown to run after all npm operations, or to re-chown the cache directory recursively after the global installs.
Root Cause Analysis
The chown -R madz:node /app /home/madz at line 57 of the Dockerfile executes before the global npm installs at lines 66–70. With ENV HOME=/home/madz set at line 53, npm resolves its cache to /home/madz/.npm, and the global installs create that cache as root. No subsequent chown corrects the ownership, so the cache remains root-owned.
Testing Strategy
- Build test: Build the image and inspect the cache ownership with
docker run --rm madz:latest stat -c '%U:%G' /home/madz/.npm(orls -ld /home/madz/.npm); assert the owner ismadz:node. - Functional test: As the
madzuser, run an npm command that writes to the cache (e.g.npm install -g <pkg>) and assert it succeeds withoutEACCES. - Edge cases: Confirm the cache is owned correctly both when the global installs create a fresh cache and when a pre-existing cache directory is present; confirm no other root-owned artifacts are left under
/home/madz.
Security Considerations
- Least privilege: The
madzuser should own its own home directory and cache; leaving root-owned files under a non-root user's home is a least-privilege violation and can cause silent permission failures. - Input validation: N/A — this is a build-time ownership fix, not a runtime input path.
- OWASP: No direct OWASP Top 10 surface, but correct ownership prevents a user from being unable to operate the tooling they are granted, which is a defense-in-depth concern.
Audit Findings (for Issue 1624)
Dockerfile:57—RUN chown -R madz:node /app /home/madzruns before the global npm installs. This is the ordering bug.Dockerfile:53—ENV HOME=/home/madzmakes npm resolve its cache to/home/madz/.npmfor any npm command run after this line.Dockerfile:66-67—RUN npm install -g yarn pnpmruns as root, creating/home/madz/.npmas root.Dockerfile:69-70—RUN npm install -g @fission-ai/openspec@latestruns as root, further populating the root-owned cache.Dockerfile:80—RUN mkdir -p ./projects && chown madz:node ./projectsshows the project already re-chowns individual dirs after creation; the same pattern should be applied to the npm cache.docker-entrypoint.sh:18-21— the entrypoint already re-chowns/app/memory/checkpointsand/app/memory/vectorSearchat runtime; the npm cache is not covered there.
Fix Steps
- Locate the ordering bug — Open
Dockerfileand review lines 53, 57, and 66–70. Thechownat line 57 precedes the global npm installs at lines 66–70. - Re-chown the cache after the global installs — Add a
RUN chown -R madz:node /home/madz/.npmimmediately after line 70 (after the OpenSpec install), or move the line 57chownto run after all npm operations. - Make it robust — Prefer re-chowning the cache directory explicitly (e.g.
chown -R madz:node /home/madz/.npm) so a future global install cannot re-break ownership; optionally setENV NPM_CONFIG_CACHE=/home/madz/.npmto pin the location. - Add a build-time assertion — Optionally add a
RUNstep that fails the build if the cache is not owned bymadz(e.g.test "$(stat -c '%U' /home/madz/.npm)" = madz). - Verify — Build the image and run
docker run \-\-rm madz:latest stat -c '%U:%G' /home/madz/.npm; assert the output ismadz:node, then run an npm command asmadzto confirm noEACCES.
Activity
fix: chown npm cache after global installs in Dockerfile
avoidwork commentedon Nov 1, 2026
Fixed in #1626.