fix: use a clean install when generating the SBOM for the npm-ci builder - #1248
Open
AliAltivate wants to merge 1 commit into
Open
AliAltivate wants to merge 1 commit into
AliAltivate wants to merge 1 commit into
Conversation
GetModuleSBomGenCommands ran 'npm install' for every npm-family builder, including npm-ci. For a module built with npm-ci the build itself installs strictly from package-lock.json, so resolving dependencies afresh for the SBOM can record versions that are not the ones actually shipped. Use 'npm clean-install' for the npm-ci builder, matching the spelling already used for that builder in configs/builder_type_cfg.yaml. npm, grunt and evo keep 'npm install' unchanged. Fixes SAP#1197 Signed-off-by: Ali Abuhassan <AliAltivate@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1197.
GetModuleSBomGenCommandsgroupsnpm,npm-ci,gruntandevointo one switch case and runsnpm installfor all of them. For a module built with thenpm-cibuilder, the build itself installs strictly frompackage-lock.json, so resolving dependencies afresh just to generate the SBOM can record versions that are not the ones actually shipped. That is what the reporter hit: an SBOM listing dependencies they do not ship, which fails their SLC-41 SBOM upload.This makes the
npm-cibuilder usenpm clean-installfor SBOM generation.npm,gruntandevokeepnpm installexactly as before.On the spelling:
npm clean-installis an alias ofnpm ci. I usedclean-installbecause that is the spelling already inconfigs/builder_type_cfg.yamlfor this builder (npm clean-install --production), so the SBOM path and the build path now read the same. Happy to switch it tonpm ciif you prefer the shorter form.On
--production: deliberately not added. The build path uses--productionto ship a lean artifact; the SBOM path has always installed everything, and dropping devDependencies would change which components appear in the SBOM. That is a different behavioural change from what this issue asks for, so only install-vs-clean-install changes here.Left alone on purpose: the other
npm installin this function, in thecustombuilder fallback fornodejsmodules (currently line 386). A custom builder is a black box and may not use a lock file at all — andnpm clean-installhard-fails whenpackage-lock.jsonis absent — so assuming a clean install there would risk breaking working builds. Say the word if you'd like it changed too and I'll follow up.Tests
Two
Itblocks added to the existingDescribe("GetModuleSBomGenCommands", ...):npm-cibuilder emitsnpm clean-installas its first command, followed by the unchangednpx @cyclonedx/cyclonedx-npm ...command;npmbuilder still emitsnpm install— a regression guard so a future refactor can't silently swap the two.I checked that they actually pin the behaviour rather than just passing: reverting the fix makes the
npm-cispec fail (1 of 38 specs, 0 passed, 1 failed), and with the fix both pass (2 of 38 specs, 2 passed).Checklist
gofmt,go vetclean)Note on the full suite:
internal/commands(the package changed here) is green — 73 of 73 specs.cmdandinternal/artifactsfail on my machine, but they fail identically on unmodifiedmaster(I re-ran them on a clean checkout to confirm), so those are environment-related and not caused by this change. No new dependencies, sogo mod vendoroutput is unchanged.