Skip to content

fix: npm cache under /home/madz left root-owned in Dockerfile #1624

Closed

Description

@avoidwork

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:

  1. Build the image: docker build -t madz:latest .
  2. Start the container and SSH in as the madz user (the entrypoint starts sshd; the madz user has an empty password).
  3. As madz, run any npm command that touches the cache, e.g. npm install -g <pkg> or npm cache verify.
  4. 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 (or ls -ld /home/madz/.npm); assert the owner is madz:node.
  • Functional test: As the madz user, run an npm command that writes to the cache (e.g. npm install -g <pkg>) and assert it succeeds without EACCES.
  • 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 madz user 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/madz runs before the global npm installs. This is the ordering bug.
  • Dockerfile:53 — ENV HOME=/home/madz makes npm resolve its cache to /home/madz/.npm for any npm command run after this line.
  • Dockerfile:66-67 — RUN npm install -g yarn pnpm runs as root, creating /home/madz/.npm as root.
  • Dockerfile:69-70 — RUN npm install -g @fission-ai/openspec@latest runs as root, further populating the root-owned cache.
  • Dockerfile:80 — RUN mkdir -p ./projects && chown madz:node ./projects shows 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/checkpoints and /app/memory/vectorSearch at runtime; the npm cache is not covered there.

Fix Steps

  1. Locate the ordering bug — Open Dockerfile and review lines 53, 57, and 66–70. The chown at line 57 precedes the global npm installs at lines 66–70.
  2. Re-chown the cache after the global installs — Add a RUN chown -R madz:node /home/madz/.npm immediately after line 70 (after the OpenSpec install), or move the line 57 chown to run after all npm operations.
  3. 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 set ENV NPM_CONFIG_CACHE=/home/madz/.npm to pin the location.
  4. Add a build-time assertion — Optionally add a RUN step that fails the build if the cache is not owned by madz (e.g. test "$(stat -c '%U' /home/madz/.npm)" = madz).
  5. Verify — Build the image and run docker run \-\-rm madz:latest stat -c '%U:%G' /home/madz/.npm; assert the output is madz:node, then run an npm command as madz to confirm no EACCES.

Activity

  1. added a commit that references this issue on Nov 1, 2026
    848af8b
  2. avoidwork commented on Nov 1, 2026

    @avoidwork
    OwnerAuthor

    Fixed in #1626.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedAn identifier for Madz to take action.bugSomething isn't workingin progress

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions