feat(general): Add warnings when API-dependent parameters are used without API key #7380
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
This PR implements a warning system that alerts users when they attempt to use severity-based filtering parameters without a Bridgecrew/Prisma Cloud API key.
The Problem:
Users attempting to use
--check,--skip-check,--hard-fail-on, or--soft-fail-onwith severity codes (CRITICAL, HIGH, MEDIUM, MODERATE, LOW, INFO, NONE) without an API key experience silent failures - these parameters are completely ignored with no indication of why. This leads to confusion, wasted debugging time, and potentially false security confidence in CI/CD pipelines.The Solution:
This PR adds clear, actionable warnings when severity codes are detected in filtering parameters without an API key configured. The warnings:
Impact:
Fixes #7379
New/Edited policies (Delete if not relevant)
Not applicable - This is a UX improvement, not a policy change.
Implementation Details
Files Added:
checkov/common/util/api_key_warnings.py- Core warning system module with three main functions:check_for_severity_filtering_without_api_key(): Detects severity codes in CLI parameters (supports CSV format)check_for_api_key_usage_warnings(): Main warning coordinatorwarn_about_missing_metadata_without_api_key(): General informational message about API-dependent featuresFiles Modified:
checkov/main.py(lines 310-315): Integration point - calls warning functions after API key initializationtests/common/util/test_api_key_warnings.py: Comprehensive test suite with 13 tests covering all scenariosKey Features:
--check,--skip-check,--hard-fail-on,--soft-fail-on--check CKV_1,HIGH,CKV_2Namespaceandfrom __future__ import annotationsExample Output:
Without API key (warning displayed):
With API key (no warning):
Mixed parameters:
Test Coverage
All scenarios are covered by 13 unit tests:
test_no_severity_filtering- No warning when only check IDs usedtest_severity_in_check_parameter- Detects severities in --checktest_severity_in_skip_check_parameter- Detects severities in --skip-checktest_severity_in_hard_fail_on_parameter- Detects severities in --hard-fail-ontest_severity_in_soft_fail_on_parameter- Detects severities in --soft-fail-ontest_multiple_severities_same_parameter- Multiple severities in one parametertest_severity_filtering_multiple_parameters- Severities across multiple parameterstest_mixed_check_ids_and_severities- Mix of check IDs and severitiestest_with_api_key_no_warning- No warning when API key is presenttest_severity_filtering_with_csv_string- CSV format: 'HIGH,CKV_AWS_1,MEDIUM'test_severity_filtering_with_mixed_csv- CSV with checks and severitiestest_complex_csv_combination- Complex CSV across all parameterstest_no_warning_with_only_check_ids_in_csv- No false positives for CSV check IDsTest Results:
$ pytest tests/common/util/test_api_key_warnings.py -v ==================== 13 passed in 0.010s ====================Technical Implementation Notes
Python Best Practices:
from __future__ import annotationsfor modern type hintsNamespaceinstead ofAnyTYPE_CHECKINGto avoid circular dependenciesCSV Format Handling:
Leverages existing
convert_csv_string_arg_to_list()utility fromcheckov.common.util.type_forcers:['CKV_1,HIGH,CKV_2']→['CKV_1', 'HIGH', 'CKV_2']Logging:
Integration:
Real-World Use Case
This change directly addresses the issue described in #7379 where users building CI/CD pipelines encounter silent failures when attempting to use severity-based filtering without understanding the API key requirement.
Before this PR:
After this PR:
User now understands they need to either:
--bc-api-key ${{ secrets.PRISMA_API_KEY }}--hard-fail-on CKV_AWS_1,CKV_AWS_2Checklist:
Additional Notes for Reviewers
Thank you for considering this contribution! This change will help prevent the frustration I experienced when trying to implement severity-based filtering in my CI/CD pipelines.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.