fix(kubernetes): correlate secret rules with resourceNames - #7625
Open
0xTaoZ wants to merge 1 commit into
Open
Conversation
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #7616.
CKV2_K8S_5previously treatedrules.resourceNames existsas a role-wide safe condition. That meant a ClusterRole with one unrestricted secrets-read rule and a separate resourceNames-scoped secrets rule could pass, because the scoped rule satisfied the flattened attribute check.This changes the policy to use a JSONPath condition that looks for the risky case on the same RBAC rule entry: secrets or wildcard resources, read verbs or wildcard verbs, and no
resourceNames. The check now passes only when no such unscoped rule exists.Tests
pytest -q tests/kubernetes/graph/checks/test_yaml_policies.py -k ReadAllSecretsgit diff --checkcheckov -f tests/kubernetes/graph/checks/resources/ReadAllSecrets/Failing/MixedResourceNamesClusterRole.yaml --framework kubernetes --check CKV2_K8S_5 --quietNote: the CLI smoke scan emitted a local certificate warning while fetching Prisma guideline metadata, but still evaluated the fixture and reported the expected CKV2_K8S_5 failure.
Risk
Narrow policy-only change with a parser-backed Kubernetes graph regression fixture. Existing safe resourceNames-scoped RoleBinding coverage remains in the same test case.