fix: add corepack to docker image#8386
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Well seen, I ask to copilot to help me to write this change description because we turn around since many hours on how to get owasp working with our NodeJS project using yarn berry and corepack.
Yes, of course, I tested and I thought it works but after more tests, it seems not totally in this first try. Let me add a short description on what we have before: And after the first MR try (not fully automated for CI/CD): After further test, it seems that adding the environnement variable COREPACK_ENABLE_DOWNLOAD_PROMPT=false make the yarn version download totally transparent: |
eb59de3 to
9fcbd7d
Compare
This comment was marked as outdated.
This comment was marked as outdated.
9fcbd7d to
dd19330
Compare
|
Update done as requested with prepached images for yarn (v1) and pnpm (latest): Current: After MR: This build will now allow users to install custom package managers if needed. |
dd19330 to
0110cd0
Compare
marcelstoer
left a comment
There was a problem hiding this comment.
I do not support this proposal. Specific extensions should be handled in downstream images that extend from ours.
Not sure how familiar you are with the node/npm ecosystem but it’s a bit more complex than “specific extensions” in my view. We already pre-package node, npm, yarn and pnpm using disparate approaches. The ODC code for these analyzers is already “corepack compatible/aware”. For many years (prior to Node 25) corepack was pre-distributed with all Node versions (like with npm) and for all of these alternate package managers was the recommended approach to either bootstrap or install them, and provide a mechanism to “lock” ones version manager for reproducibility. Corepack shimmed the entry point scripts and would look at the In other words, prior to Node 25, one could consider corepack being installed and enabled to be a sensible default for a “Swiss army knife” image like this which already pre-packages all sorts of tools. For some reason node voted not to package it anymore, which adds friction for every single alternate package manager. It’s worth noting that this change will not graduate to LTS until April/May 2027 so for now, corepack is still “LTS”ish. According to OP, there appears to be a gap in the ODC image at the moment that causes yarn and pnpm to not work in a corepack aware way, and our image was possibly not “caught up” when the Yarn 2+ support was finally fixed in ODC itself. I think we need to confirm what these problems are. This is important now because yarn/pnpm are directly invoked by ODC and failure to use the correct version implied by package.json will cause scanning failures. It’s likely only an accidental side effect of Alpine’s non-standard packaging process for node/npm that corepack has not been included earlier. Most distros follow nodes official packaging and include it. Some other distros also split corepack from node, but they include a proper package for it, so you’re not installing into the npm global space (Arch, Wolfi, newer Debian). For some reason Alpine has no distinct corepack package, however provides corepack in a compliant way with the Now, to summarise my earlier messages, the messy bit is determining how to move forward and requires some research into whether pnpm, yarn and others will continue to recommend corepack. It doesn’t make sense for us to add it if everyone is moving away. In retrospect it’d probably have been better to open an issue to discuss the problem before submitting a solution, but it’s not the end of the world, as there’s not too much effort here I think. In my personal view, if corepack still has a role, rather than using npm global space, I would suggest
But I think we need to figure out exactly which combinations are not working right now with the pre-installed versions and whether corepack still has a role - before we decide to do anything. |
|
👍 Thanks for the effort that went into this write-up! Much appreciated. |
This comment was marked as outdated.
This comment was marked as outdated.
0110cd0 to
f91f33f
Compare
|
Hi everyone, Due to security and performance requirements, we must upgrade to newer Yarn versions in our CI pipelines. With our current setup, this makes the official Docker image incompatible for us in its current form. If the preferred direction is for users to maintain their own Docker images, that’s acceptable for us, but we would appreciate some high‑level guidance on the recommended way forward. Once we align on the approach, I’m willing to handle the required development work so we can unblock usage on recent environments. Let us know how you’d like to proceed. |
This comment was marked as outdated.
This comment was marked as outdated.
|
After having looked at this a bit further and testing locally, I think it makes sense to go ahead with this with some tweaks suggested in dcyrille18#1 to clean-up cache cruft left behind in the image layers. Current image
corepack direction of tools
Advantages
Disadvantages
@dcyrille18 if you could review/merge my PR-to-your-PR and go through the comments to resolve them here it will help make it easier to review for others. |
8429200 to
01a8586
Compare
|
Hi @chadlwilson, |
There was a problem hiding this comment.
Adding some comments to explain the changes I personally added on, for maintainer review benefit.
This LGTM now and I think is a worthwhile contribution 👍
$ docker run -it --entrypoint='' owasp/dependency-check:12.2.1-SNAPSHOT sh -c "pnpm --version && yarn --version && corepack yarn@latest --version"
10.33.0
1.22.22
4.13.0| RUN apk upgrade --no-cache && \ | ||
| apk add --no-cache --virtual .build-deps curl && \ | ||
| apk add --no-cache git ruby npm && \ | ||
| gem install --no-document bundler-audit && \ | ||
| npm install --global --ignore-scripts corepack && \ |
There was a problem hiding this comment.
I made these changes, just for cleanup while we are here
- we are using
--no-cacheso thinkupdatewas intended asupgrade tarno longer neededbundle audit updateneeds to be done in the user context, not cached as root- can avoid need for rdoc by using
--no-documentruby install
There was a problem hiding this comment.
Worth installing corepack from package-lock.json and then running npm ci --ignore-scripts. Thanks
There was a problem hiding this comment.
That’s not how global installs work?
| apk del .build-deps && \ | ||
| rm -rf /tmp/* /root/.cache /root/.npm |
There was a problem hiding this comment.
Cleaning up, since Node and Ruby leave unnecessary cruft in /tmp and root's home.
| printf "enableTelemetry: false\nenableScripts: false\n" >> ${HOME}/.yarnrc.yml && \ | ||
| rm -rf /tmp/* |
There was a problem hiding this comment.
Being a good citizen be removing undocumented internet access by yarn, and disable scripts by default during yarn install for supply chain security good practices.
Also removes cache cruft that results from running node and v8.
There was a problem hiding this comment.
Pull request overview
This PR updates the base owasp/dependency-check Docker image to include Corepack so Yarn/pnpm can be used via Node’s package-manager tooling without requiring downstream installation steps.
Changes:
- Add
COREPACK_ENABLE_DOWNLOAD_PROMPT=falseand install Corepack vianpm. - Remove manual Yarn download/symlink and global pnpm install, replacing them with Corepack preparation.
- Add a post-
USERlayer to prefetch/activate Yarn/pnpm and write a Yarn config file.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| ### Cache pieces needed for the specific run user | ||
| RUN bundle audit update && \ | ||
| corepack prepare pnpm@latest yarn@latest yarn@1 --activate && \ |
There was a problem hiding this comment.
corepack prepare pnpm@latest yarn@latest ... is non-deterministic and can change the image contents over time (including unexpected major upgrades). Recommend pinning explicit versions (possibly via build args) and avoiding latest for release images.
There was a problem hiding this comment.
Worth tagging to a specific SHA or a version to avoid a supply-chain attack please. Thanks
There was a problem hiding this comment.
In my opinion - no. That adds additional maintenance burden that dependabot cannot help us with and will likely lead to stale versions without security fixes in the underlying software, which is of bigger risk to users.
Whose supply chain? What's the attack vector?
- For ODC's own supply chain this is within an ODC container so it poses minimal threat because the npm install is within a docker build running inside a docker buildx container which doesn't have access to anything privileged.
- For user's supply chains it poses little risk because ODC is not released constantly. It'd require extremely bad luck for the latest version at the time of a release build to contain a vulnerable version
If yarn or pnpm publishing to npm are breached the world has MUCH bigger problems than ODC as an entrance. If you can suggest a way to keep the versions updated which dependabot can handle then it’d be OK to do this, but otherwise I do not think it is worth the trade off of additional unpaid OSS maintainer work and risk of unpatched versions staying around for longer.
As I already said earlier, this PR is really not the place for this discussion since we already have unpinned npm installs here.
There was a problem hiding this comment.
If you use this image for your paid work for your employer and are still concerned and feel you can mitigate supply chain risks better yourself - you can always build your own image?
- clean up cruft left behind within image - fix local user caching of bundle audit database - disable telemetry and scripts by default for privacy/security Signed-off-by: Chad Wilson <29788154+chadlwilson@users.noreply.github.com>
01a8586 to
206f2f9
Compare
Description of Change
This merge request adds Corepack to the base OWASP Dependency-Check Docker image.
The goal is to provide native support for package managers such as Yarn and pnpm without requiring downstream images or CI pipelines to manually install Corepack.
This change enables:
No breaking changes are introduced:
If Node.js tooling is not needed, the image behaves exactly as before.
Corepack is now enabled and used as recommended by the pnpm and yarn projects.