Skip to content

fix: chown npm cache after global installs in Dockerfile - #1626

Merged
avoidwork merged 3 commits into
mainfrom
fix/dockerfile-npm-cache-chown-ordering
Nov 1, 2026
Merged

avoidwork merged 3 commits into
mainfrom
fix/dockerfile-npm-cache-chown-ordering

Conversation

@avoidwork

@avoidwork avoidwork commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Description

Fix a Dockerfile bug (issue #1624) where the npm cache under /home/madz/.npm was left owned by root after the global npm installs, causing EACCES for the madz user at runtime. Root cause is ordering: RUN chown -R madz:node /app /home/madz ran before the global installs (npm install -g yarn pnpm and npm install -g @fission-ai/openspec@latest), and ENV HOME=/home/madz made npm resolve its cache to /home/madz/.npm, which those root-run installs populated as root with nothing re-chowning it afterward.

This change:

  • Pins ENV NPM_CONFIG_CACHE=/home/madz/.npm so the chown target is explicit and stable rather than implicitly derived from HOME.
  • Adds RUN chown -R madz:node /home/madz/.npm after every global install, so a future npm install -g cannot silently re-break ownership as long as it stays the last ownership operation on the cache.
  • Adds a build-time assertion RUN test "$(stat -c '%U' /home/madz/.npm)" = madz that fails the build if the cache is not owned by madz.
  • Includes the OpenSpec change (proposal, design, spec delta, tasks) and its archive.

Type of Change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional changes)
  • Performance improvement
  • CI / build / tooling

Testing

Dockerfile-only change; the project has no unit-test infrastructure for Dockerfile ownership. The regression guard is a build-time assertion (RUN test "$(stat -c '%U' /home/madz/.npm)" = madz) that fails the build if the cache is not owned by madz. Verification: build the image and assert stat -c '%U:%G' /home/madz/.npm returns madz:node. CI lint and test jobs pass.

Coverage

  • Line coverage maintained

Checklist

  • npm run lint passes
  • Tests pass with maintained line coverage
  • No forbidden patterns used
  • Conventional Commit style applied

Closes #1624

@avoidwork avoidwork added the bug Something isn't working label Nov 1, 2026
@avoidwork avoidwork self-assigned this Nov 1, 2026
The global npm installs (yarn, pnpm, @fission-ai/openspec) run as root and
populate the npm cache (/home/madz/.npm, derived from ENV HOME) as root, with
nothing re-chowning it afterward, so the madz user hits EACCES. Re-chown the
cache after the global installs, pin NPM_CONFIG_CACHE, and add a build-time
assertion that fails the build if the cache is not owned by madz.

Closes #1624
Sync the new dockerfile-npm-cache-ownership capability spec into
openspec/specs/ and move the change into the archive.
@avoidwork

Copy link
Copy Markdown
Owner Author

Audit Results — dockerfile-npm-cache-chown-ordering (issue #1624)

Goal fulfillment: The npm cache under /home/madz/.npm is now owned by madz:node after the global npm installs, resolving the EACCES reported in the issue.

Spec compliance:

  • ENV NPM_CONFIG_CACHE=/home/madz/.npm pins the cache location so the chown target is explicit and stable.
  • RUN chown -R madz:node /home/madz/.npm runs after every global install, so a future npm install -g cannot silently re-break ownership as long as it stays the last ownership operation on the cache.
  • Build-time assertion RUN test "$(stat -c '%U' /home/madz/.npm)" = madz fails the build on regression.

Task completion: All OpenSpec tasks implemented; change archived to openspec/changes/archive/2026-11-01-dockerfile-npm-cache-chown-ordering/ and the spec synced to openspec/specs/dockerfile-npm-cache-ownership/spec.md.

Quality check:

  • CI lint and test jobs pass.
  • No forbidden patterns (no console.log, no silent catch, no eval).
  • Conventional Commit style applied across the three commits.
  • No unit-test infrastructure exists for Dockerfile ownership; the regression guard is the build-time assertion, which is the appropriate mechanism for a build-time ownership fix.

Verification: Build the image and assert stat -c '%U:%G' /home/madz/.npm returns madz:node.

@avoidwork
avoidwork merged commit d4005ec into main Nov 1, 2026
2 checks passed
@avoidwork
avoidwork deleted the fix/dockerfile-npm-cache-chown-ordering branch November 1, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant