-
Notifications
You must be signed in to change notification settings - Fork 0
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
[ENGPROD-6654] Ignore policies from a folder #6
Conversation
@@ -69,11 +72,29 @@ func FilterResult(ctx context.Context, result *types.Result, ignoreConf IgnoreCo | |||
if opt.PolicyFile != "" { | |||
var err error | |||
var ignored int | |||
filteredVulns, filteredMisconfs, ignored, filteredSecrets, filteredLicenses, err = applyPolicy(ctx, filteredVulns, filteredMisconfs, filteredSecrets, filteredLicenses, opt.PolicyFile) |
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.
So just subsequently exec this function for each target ignore rego file (either specified or found in the folder if the input value is the dir path) in the loop below.
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.
Nice, I just had some output recommendations, but the approach looks good to me!
return xerrors.Errorf("failed to find policy files: %w", err) | ||
} | ||
} else { | ||
policyFiles = append(policyFiles, opt.PolicyFile) |
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.
I think I'd like debug output to show which policy files it found when --debug
is used so I can verify it is seeing the policy files I think it should load (or not)
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.
That makes sense. And I was using exactly that debug logging during development 😄
The only inconvenience is that the ignore policies are loaded and applied for every result filtration.
So, I've added the logging of what result is being filtered and then the applied policies.
...
2024-02-15T13:51:33.946+0200 INFO Detecting pip vulnerabilities...
2024-02-15T13:51:33.946+0200 DEBUG Detecting library vulnerabilities, type: pip, path: requirements.txt
2024-02-15T13:51:33.949+0200 DEBUG Detecting library vulnerabilities, type: pip, path: api_client/requirements.txt
2024-02-15T13:51:33.949+0200 DEBUG Detecting library vulnerabilities, type: pip, path: dbt/requirements.txt
2024-02-15T13:51:33.949+0200 DEBUG Detecting library vulnerabilities, type: npm, path: engprod/package-lock.json
2024-02-15T13:51:33.951+0200 DEBUG Detecting library vulnerabilities, type: pip, path: misc/monitoring/searchblox/requirements.txt
--- NEW ---
2024-02-15T13:51:33.968+0200 DEBUG Filtering result with ignore policies, type: pom, path: node_modules/serverless/docs/providers/openwhisk/examples/hello-world/java/pom.xml
2024-02-15T13:51:33.968+0200 DEBUG Applying ignore policy: engprod/only_package.rego
2024-02-15T13:51:33.970+0200 DEBUG Applying ignore policy: engprod/subdir/flask.rego
2024-02-15T13:51:33.972+0200 DEBUG Filtering result with ignore policies, type: pom, path: node_modules/serverless/lib/plugins/aws/invoke-local/runtime-wrappers/java/pom.xml
2024-02-15T13:51:33.972+0200 DEBUG Applying ignore policy: engprod/only_package.rego
2024-02-15T13:51:33.973+0200 DEBUG Applying ignore policy: engprod/subdir/flask.rego
2024-02-15T13:51:33.974+0200 DEBUG Filtering result with ignore policies, type: npm, path: package-lock.json
2024-02-15T13:51:33.974+0200 DEBUG Applying ignore policy: engprod/only_package.rego
2024-02-15T13:51:33.975+0200 DEBUG Applying ignore policy: engprod/subdir/flask.rego
2024-02-15T13:51:33.976+0200 DEBUG Filtering result with ignore policies, type: pip, path: requirements.txt
2024-02-15T13:51:33.976+0200 DEBUG Applying ignore policy: engprod/only_package.rego
2024-02-15T13:51:33.977+0200 DEBUG Applying ignore policy: engprod/subdir/flask.rego
Description
Adjusted the
--ignore-policy
option to also support reading the *.rego policies files from a folder.The change is backward compatible. As usual, the
--ignore-policy ignore.rego
option can be used.If the option value is a filesystem directory it will recursively search for *.rego files in it and apply each found one to the scan results.
> ./trivy image --ignore-policy /path/to/folder/with/regos image_to_scan
Related issues
Related PRs
Remove this section if you don't have related PRs.
Checklist