-
Notifications
You must be signed in to change notification settings - Fork 670
feat: add iac --exclude param [IAC-3473] #6425
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
base: main
Are you sure you want to change the base?
feat: add iac --exclude param [IAC-3473] #6425
Conversation
|
bc2df00 to
8776571
Compare
7aa789d to
cf63a21
Compare
src/cli/main.ts
Outdated
| if (!(options.allProjects || options.yarnWorkspaces || options.iac)) { | ||
| throw new MissingOptionError('--exclude', [ | ||
| '--yarn-workspaces', | ||
| '--all-projects', | ||
| '--iac', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: is this tested? options.iac is configured here, do we intend to support the exclude flag for all scenarios where options.iac === true?
issue: the resulting MissingOptionError output also doesn't make sense:
FATAL Invalid flag option (SNYK-CLI-0004)
The --exclude option can only be used in combination with --all-projects or
--iac or --yarn-workspaces.
Docs: https://docs.snyk.io/scan-with-snyk/error-catalog#snyk-cli-0004
ID: urn:snyk:interaction:0b9d5ff3-c3a6-4b53-9d6e-aadc18bd2fef
--iac is not a flag option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was included by mistake. We are not changing anything regarding open source logic.
cf63a21 to
a0738a5
Compare
a0738a5 to
a130394
Compare
Pull Request Submission Checklist
are release-note ready, emphasizing
what was changed, not how.
What does this PR do?
This PR implements the
--excludeparameter for IaC scanning. The implementation is designed to be consistent with the existingsnyk testexclude behavior, focusing on global basename matching.Behavior
--exclude=dir1matches./dir1and./src/dir1/or\) in the exclude flagWhere should the reviewer start?
src/cli/commands/test/iac/local-execution/file-utils.ts- ReviewcreatePathExclusionMatcher. This is where input strings are converted into global glob patterns (**/nameand**/name/**).src/cli/commands/test/iac/local-execution/file-utils.ts- Check howmakeFileAndDirectoryGeneratoruses the matcher to skip excluded branches during the directory walk.How should this be manually tested?
mkdir -p test-iac-exclude/{included,excluded,ignored} printf 'data "aws_iam_policy_document" "s" {\n statement {\n actions = ["*"]\n resources = ["arn:aws:s3:::example"]\n }\n}\n' > test-iac-exclude/included/included.tf cp test-iac-exclude/included/included.tf test-iac-exclude/excluded/excluded.tf cp test-iac-exclude/included/included.tf test-iac-exclude/ignored/ignored.tf # Test single exclusion: only 'included.tf' and 'ignored.tf' should appear snyk iac test --exclude=excluded test-iac-exclude # Test multiple exclusions: only 'included.tf' should appear snyk iac test --exclude=excluded,ignored test-iac-exclude # Test file exclusion: only 'included.tf' and 'excluded.tf' should appear snyk iac test --exclude=ignored.tf test-iac-excludeWhat's the product update that needs to be communicated to CLI users?
New Feature: Exclude files and directories from IaC scans
Users can now exclude specific files and directories from IaC scans using the --exclude parameter:
snyk iac test --exclude=excluded-folder,ignored-file.tfThis update allows you to skip specific files or folders by name, no matter where they are located in your project. If the name matches a folder, Snyk CLI will ignore that folder and every file inside it. This is particularly useful for excluding test files, temporary files, or other non-production IaC files from security scans.
Risk assessment: Low
Any background context you want to provide?
This feature was requested to allow users to exclude test files, temporary files, and other non-production IaC files from security scans.
What are the relevant tickets?