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

feat: container add --exclude-node-modules option #5636

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

adrobuta
Copy link
Contributor

Pull Request Submission Checklist

  • Follows CONTRIBUTING guidelines
  • Includes detailed description of changes
  • Contains risk assessment (Low | Medium | High)
  • Highlights breaking API changes (if applicable)
  • Links to automated tests covering new functionality
  • Includes manual testing instructions (if necessary)
  • Updates relevant GitBook documentation (PR link: ___)

What does this PR do?

Before v6.12.0, the docker cli plugin was able to scan npm projects only when strict package.json and package-lock.json pairs of files were identified within container images. The pair of files had to be outside of a node_modules folder’s context in order to avoid creating projects out of the dependencies. Scanning container images that had the manifests/lockfiles removed was not possible and customer needs were created to remove that constraint.

The scanning of npm global and local scoped node_modules directories has been enabled as a default behavior when a node.js image is scanned.
Adding an option to opt-out from the node_modules scan allows the user to scan npm projects only when [strict package.json and package-lock.json pairs] are identified in the container image, thus re-enabling the original npm scan behavior.

Where should the reviewer start?

How should this be manually tested?

  1. Build a docker image with multiple npm projects and global node_modules installed in the image:
    Dockerfile:
    `FROM node:18-alpine

COPY package.json /goof1/
COPY package-lock.json /goof1/
COPY package.json /
COPY package-lock.json /
WORKDIR /goof1
RUN npm install
WORKDIR /
RUN npm install`

docker build -t npm7-image .
2. Run test/monitor without disabling node_modules scan on the nodejs image
SNYK_API=https://app.pre-prod.snyk.io/api/v1 snyk container test npm7-image:latest
Expected Results:
Global node_modules are scanned.
A log line should appear that describes the target scanned:

Target file: /usr/local/lib/node_modules

  1. Run test/monitor with --exclude-node-modules option enabled
    SNYK_API=https://app.pre-prod.snyk.io/api/v1 snyk container test npm7-image:latest --exclude-node-modules

Expected Results
Global node_modules are excluded from the scan.

@adrobuta adrobuta requested a review from a team as a code owner December 19, 2024 12:51
Copy link
Contributor

github-actions bot commented Dec 19, 2024

Warnings
⚠️

Please make changes to snyk help text in Gitbook. Changes will be automatically synchronised to Snyk CLI as a scheduled PR.
For more information, see: help/README.md.

⚠️

"feat: container test/monitor add support for --exclude-node-modules option" is too long. Keep the first line of your commit message under 72 characters.

Generated by 🚫 dangerJS against 4756f27

@adrobuta adrobuta force-pushed the feat/exclude-node-modules-vulns branch from 6361aab to 4756f27 Compare December 19, 2024 13:07
@sandor-trombitas sandor-trombitas merged commit 03e82d6 into main Dec 19, 2024
7 checks passed
@sandor-trombitas sandor-trombitas deleted the feat/exclude-node-modules-vulns branch December 19, 2024 13:57
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