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(general): add policy metadata filter exception flag #6132

Merged
merged 4 commits into from Apr 2, 2024

Conversation

kartikp10
Copy link
Contributor

@kartikp10 kartikp10 commented Mar 30, 2024

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

Adds a new --policy-metadata-filter-exception flag that can only be used with a Prisma Cloud API key. This adds the ability to exclude checks based on policy metadata filters.

Filters can be specified in a comma-separated key-value list, for example:

checkov -d . --bc-api-key "xxx::xxx" --policy-metadata-filter-exception policy.label=A,cloud.type=aws,policy.mode=custom

When you list checks with a filter, checks returned by the filter are excluded.

Some important behaviors:

If a filter is invalid, checkov will continue execution with a warning and will run as though no filters were specified.

If --policy-metadata-filter and --policy-metadata-filter-exception are simultaneously used, the former is applied first, then the checks returned by the exception flag are removed. For example:

  • Policies P1, P2, P3 have the label CRITICAL
  • Policies P1, P2 have the label EXCEPTION

Running the following command will result in only running policy P3. P1 and P2 will not be executed (not skipped).

checkov -d . --bc-api-key "xxx::xxx" --policy-metadata-filter policy.label=CRITICAL --policy-metadata-filter-exception policy.label=EXCEPTION

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

checkov/runner_filter.py Dismissed Show dismissed Hide dismissed
@@ -468,6 +468,13 @@ def add_parser_args(self) -> None:
"information on allowed filters. Format: policy.label=test,cloud.type=aws ",
default=None,
)
self.add(
"--policy-metadata-filter-exception",
help="comma separated key:value string to exclude filtered policies based on Prisma Cloud policy metadata. "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a description of what happens when you use both options (the subtraction logic), to this as well as to the other one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

@kartikp10 kartikp10 merged commit 258139e into main Apr 2, 2024
36 of 38 checks passed
@kartikp10 kartikp10 deleted the add-exclude-label-flag branch April 2, 2024 17:15
pull bot pushed a commit to tooniez/checkov that referenced this pull request Apr 3, 2024
…o#6132)

* add exception flag

* add tests

* add type hints

* refine help text
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.

None yet

3 participants