feat(general): Add warnings when API-dependent parameters are used without API key - #7380
feat(general): Add warnings when API-dependent parameters are used without API key#7380jasonouellet wants to merge 16 commits into
Conversation
- Focus on behavior differences rather than warnings - Explain that severity filtering uses estimated defaults without API key - Clarify which parameters require API key for full functionality - Update CLI Command Reference with concise API key requirement notes - Update Hard and soft fail doc to emphasize functional impact delete: second doc
8a4cc00 to
cf9146d
Compare
There was a problem hiding this comment.
Pull request overview
Adds a centralized warning system to alert users when CLI flags that depend on Bridgecrew/Prisma Cloud platform data are used without an API key, aiming to prevent silent misconfiguration (notably severity-based filtering).
Changes:
- Introduces
checkov/common/util/api_key_warnings.pyto detect severity codes in filtering/fail flags and warn when no API key is configured. - Integrates the warning checks into
checkov/main.pyafter API key persistence. - Adds unit tests and updates CLI docs to describe API-key-dependent behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
checkov/common/util/api_key_warnings.py |
New module implementing API-key-related warnings and a “limited metadata” info message. |
checkov/main.py |
Hooks the new warning utilities into the main execution flow. |
tests/common/util/test_api_key_warnings.py |
Adds unit tests for severity/API-key warning behavior and other API-key-dependent flags. |
docs/2.Basics/Hard and soft fail.md |
Documents severity filtering behavior without an API key. |
docs/2.Basics/CLI Command Reference.md |
Updates CLI flag documentation with API key requirement notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| expected_codes = {'CRITICAL', 'HIGH', 'MEDIUM', 'MODERATE', 'LOW', 'INFO', 'NONE'} | ||
| self.assertEqual(SEVERITY_CODES, expected_codes) |
There was a problem hiding this comment.
SEVERITY_CODES in production code currently omits severities that exist in checkov.common.bridgecrew.severities (e.g., IMPORTANT, OFF). This test will force that incomplete set and could cause valid CLI severity values to go unwarned. Update the expectation to match the canonical severity set (ideally derived from Severities/BcSeverities) once the constant is corrected.
| # Severity codes that can be used for filtering | ||
| SEVERITY_CODES = {'CRITICAL', 'HIGH', 'MEDIUM', 'MODERATE', 'LOW', 'INFO', 'NONE'} | ||
|
|
There was a problem hiding this comment.
SEVERITY_CODES duplicates and partially diverges from the canonical severity definitions in checkov.common.bridgecrew.severities (which includes IMPORTANT and OFF). This can cause missed warnings for valid CLI severity values. Consider deriving the set from Severities/BcSeverities rather than maintaining a separate hard-coded list.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.