fix(query): handle list-form access_logs in ELBv2 LB Access Log Disabled#8068
Open
arpitjain099 wants to merge 1 commit into
Open
fix(query): handle list-form access_logs in ELBv2 LB Access Log Disabled#8068arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
The Terraform query aws/elb_v2_lb_access_log_disabled assumed access_logs was
always parsed as a single object and read resource.access_logs.enabled directly.
When access_logs is written as a list (access_logs = [{ ... enabled = true }]),
the parser stores it as an array, so that path is undefined and the load
balancer is flagged even though access logging is enabled.
Normalize access_logs to a list of blocks (mirroring the object-or-array
handling used by other queries such as efs_volume_with_disabled_transit_encryption)
so the enabled check works for both the single-block and list shapes. The
true-positive cases (access_logs absent, enabled missing, or enabled = false)
are still reported, including when access_logs is a list.
Adds negative3.tf (list form with enabled = true, must not flag) and
positive7.tf (list form with enabled = false, must still flag).
Closes Checkmarx#8036
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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.
Description
The Terraform query
aws/elb_v2_lb_access_log_disabled(ELBv2 LB Access Log Disabled) reports a false positive whenaccess_logsis written as a list of objects rather than a single nested block.The query read
resource.access_logs.enableddirectly, assumingaccess_logsis always parsed as an object. When the config uses the list form:the parser stores
access_logsas an array, soresource.access_logs.enabledis undefined. The secondCxPolicyblock (not valid_key(resource.access_logs, "enabled")) then fires and the load balancer is flagged as having access logging disabled even thoughenabled = true.Fix
Normalize
access_logsto a list of blocks before theenabledcheck, mirroring the object-or-array handling already used by other queries (for exampleaws/efs_volume_with_disabled_transit_encryption). Theenabledcheck then works for both the single-block and list shapes, and the search key / search line are indexed only in the list case so the single-block results are unchanged.True positives are preserved:
access_logsabsent,enabledmissing, orenablednot set totrueare still reported, including whenaccess_logsis a list.Tests
test/negative3.tf: list-formaccess_logswithenabled = true(the reported false positive) - must not be flagged.test/positive7.tf: list-formaccess_logswithenabled = false- must still be flagged.test/positive_expected_result.jsonupdated forpositive7.tf.Verified locally:
go test ./test/ -run 'TestQueries$/terraform/aws/elb_v2_lb_access_log_disabled'passes.TestQueriesContentandTestQueriesMetadatafor the query pass.query.regowhile keeping the new fixtures makes the test fail (the original query flagsnegative3.tfand reportspositive7.tfon the wrong line), confirming the fix is what resolves the false positive.Closes #8036