fix(ansible): respect inline checkov:skip on block tasks#7583
Open
m-khan-97 wants to merge 1 commit into
Open
Conversation
The suppression-context key for a block resource was built with one extra "." than the graph builder's vertex ID (e.g. "block..name" vs "block.name"), so the skip lookup never matched and inline checkov:skip comments on block tasks (e.g. for CKV2_ANSIBLE_3) were silently ignored. Fixes bridgecrewio#7501
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
checkov:skipsuppression silently ignored for Ansible block checks #7501: inlinecheckov:skip=CKV2_ANSIBLE_3:...(and any other graph check) comments placed on an Ansibleblock:task were silently ignored, so the check always reportedFAILEDinstead ofSKIPPED.checkov/ansible/utils.py,_process_blocksbuilt the suppression-context key for a block asf"{prefix}.{name}"whereprefixalready ends in"."(e.g."block."), producing"block..name". The graph builder (checkov/ansible/graph_builder/local_graph.py) creates the corresponding vertex ID asf"{prefix}{name}"→"block.name". The mismatched keys meant the skip lookup in the suppression logic never found the resource's skip comment.., so the context key now matches the graph vertex ID exactly, the same waygenerate_task_namealready does for non-block tasks.Test plan
tests/ansible/examples/block_skip.ymlreproducing the reported scenario (ablock:task with an inlinecheckov:skip=CKV2_ANSIBLE_3comment).test_runner_with_block_skipintests/ansible/test_runner.py(parametrized over both graph connectors) asserting the check is now reported asSKIPPEDwith the correct resource id.tests/ansible/suite locally — all existing tests still pass (no regressions for flat tasks, blocks, or nested blocks).