-
Notifications
You must be signed in to change notification settings - Fork 341
fix(query): fp for security_groups_not_used - terraform/aws #7566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(query): fp for security_groups_not_used - terraform/aws #7566
Conversation
…or_not_declared--terraform/aws
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey André, great work.
Can you take a look at my comments please?
Don't blindly approve the suggested changes as lines may differ from the actual document as github sometimes has a hard time highlighting the right reviewed lines.
assets/queries/terraform/aws/security_groups_not_used/query.rego
Outdated
Show resolved
Hide resolved
assets/queries/terraform/aws/security_groups_not_used/query.rego
Outdated
Show resolved
Hide resolved
assets/queries/terraform/aws/security_groups_not_used/query.rego
Outdated
Show resolved
Hide resolved
…5314--FP_Security_group_must_be_used_or_not_declared--terraform/aws
…ed--terraform/aws' of https://github.com/cx-andre-pereira/kics into AST-65314--FP_Security_group_must_be_used_or_not_declared--terraform/aws
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice job André.
…or_not_declared--terraform/aws
Closes #7212
Reason for Proposed Changes
security_group_id
declarations inside modules. These modules support array based declaration of this sort :security_group_id = [aws_security_group.test.id]
so the query should be adjusted to prevent FP due to lack of proper array case handling.contains
policy use; basically the policy is written in a way that allows for easy FNs to occur in case , for example, a security resource is declared with the name "test" and then , when ensuring the use of this resource, we find something like "test_2". The "test_2" serves as confirmation of "test"´s usage due to only relying on a comparison that is equivalent to prefix matching.Proposed Changes
I expanded on the
terraform-aws-modules/security-groups/aws case handling
that was already there to allow the use of arrays; but also streamlined the needlessly large amount of policies from the original query to rely on aget_security_groups_if_exists
policy instead, a policy that is very much alike the ones found in terraform.rego (library of common use case policies).Given that the current implementation does not account for trailing character of text when comparing group names, I have enforced the name that we are searching for to be encased in "." , in doing this i am assuming all use cases are as follows:
aws_security_group.
our_resource_name.id
This is corroborated by our list of tests, even if the id field is somehow given a different name as long as we are searching for a specific field inside that group this will ensure proper full name matching.
Finally the negative and positive tests added are to ensure, respectively, that the currently unsupported arrays are handled properly and that a name with equivalent prefix that has trailing characters compared to the resource´s name does not prevent it form being flagged.
Note : I also could not help but notice how my new policy
get_security_groups_if_exists
is not catching every possible scenario for security_groups, but seen as though i do not have access to files that confirm the FPs that might arise from this i will leave it as is; given this changes it should be simple to add any case handling needed by updating the new policy.I submit this contribution under the Apache-2.0 license.