Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: image failures for non-root uses of yarn and pnpm #391

Merged
merged 2 commits into from
Feb 22, 2024
Merged

Conversation

maxrake
Copy link
Contributor

@maxrake maxrake commented Feb 22, 2024

The lockfile generation tool yarn fails when used in the phylum-ci Docker image as a non-root user. An example of the failure can be seen from the output of the "smoke test," which is using scripts/docker_tests.sh to ensure basic functionality:

yarn --version
Internal Error: EACCES: permission denied, open '/usr/local/corepack/lastKnownGood.json'
Error: EACCES: permission denied, open '/usr/local/corepack/lastKnownGood.json'

The same behavior happens for pnpm. These are the tools installed by corepack, which changed recently to "Bump Known Good Release when downloading new version" (nodejs/corepack#364). Part of that change was to make use of the COREPACK_DEFAULT_TO_LATEST environment variable to not update the last known good version, but setting that to 0 does not appear to prevent all writes (or creating a file handle with write permission) to the lastKnownGood.json file.

This fix simply modifies the file permissions for lastKnownGood.json so that non-root users can read and write to it. This approach may seem specific to a file that may change name or location in the future, but the alternative method of adding ${COREPACK_HOME} to the list of directories that get updated with a chmod -vR 777 was deemed to be too blunt and therefore less desirable.

The lockfile generation tool `yarn` fails when used in the `phylum-ci`
Docker image as a non-root user. An example of the failure can be seen
from the output of the "smoke test," which is using
`scripts/docker_tests.sh` to ensure basic functionality:

```
yarn --version
Internal Error: EACCES: permission denied, open '/usr/local/corepack/lastKnownGood.json'
Error: EACCES: permission denied, open '/usr/local/corepack/lastKnownGood.json'
```

The same behavior happens for `pnpm`. These are the tools installed by
`corepack`, which changed recently to "Bump Known Good Release when
downloading new version" (nodejs/corepack#364).
Part of that change was to make use of the `COREPACK_DEFAULT_TO_LATEST`
environment variable to *not* update the last known good version, but
setting that to `0` does not appear to prevent *all* writes (or creating
a file handle with write permission) to the `lastKnownGood.json` file.

This fix simply modifies the file permissions for `lastKnownGood.json`
so that non-root users can read and write to it. This approach may seem
specific to a file that may change name or location in the future, but
the alternative method of adding `${COREPACK_HOME}` to the list of
directories that get updated with a `chmod -vR 777` was deemed to be too
blunt and therefore less desirable.
@maxrake maxrake self-assigned this Feb 22, 2024
@maxrake maxrake requested a review from a team as a code owner February 22, 2024 20:19
@maxrake maxrake requested a review from kylewillmon February 22, 2024 20:19
kylewillmon
kylewillmon previously approved these changes Feb 22, 2024
Dockerfile Outdated Show resolved Hide resolved
Co-authored-by: Kyle Willmon <kyle@phylum.io>
@maxrake maxrake requested a review from kylewillmon February 22, 2024 20:45
@maxrake maxrake enabled auto-merge (squash) February 22, 2024 20:46
@maxrake maxrake merged commit 345ecd2 into main Feb 22, 2024
13 checks passed
@maxrake maxrake deleted the smoke_out branch February 22, 2024 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants