-
Notifications
You must be signed in to change notification settings - Fork 346
fix(query): adding support for CloudFormation queries missing ingress/egress resources - Part 1 #7750
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
Open
cx-andre-pereira
wants to merge
50
commits into
master
Choose a base branch
from
AST-115332-FN-For-cloudformation-ingress_egress_queries
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix(query): adding support for CloudFormation queries missing ingress/egress resources - Part 1 #7750
cx-andre-pereira
wants to merge
50
commits into
master
from
AST-115332-FN-For-cloudformation-ingress_egress_queries
Conversation
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
…rce support for elb_with_security_group_withtout_outbound_rules
…_with_public_scope
…d searchKey, added searchLine and better tests
… common library, db_security_group_with_public_scope now checks for all ipv6 open address forms
…ricted_traffic, added searchLine values and condensed tests
…e to reference sec. group to flag exposed sec. groups, fixed expected results formatting
…oved upd exclusive sensitive port list and altered get_ingress_list logic slightly
…, print values TODO
…ork, new tests, searchLine added and improved searchValue; fallback for keyExpectedValue and ActualValue(s) for ec2_sensitive_port_is_publicly_exposed query
…ents to overall query logic
…with_public_scope
…tandalone ingress
…' of https://github.com/Checkmarx/kics into AST-115332-FN-For-cloudformation-ingress_egress_queries
…' of https://github.com/Checkmarx/kics into AST-115332-FN-For-cloudformation-ingress_egress_queries
…restricted_traffic
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
aws
PR related with AWS Cloud
cloudformation
CloudFormation query
query
New query feature
terraform
Terraform query
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.
Closes #7303
Reason for Proposed Changes
Part 2 | Part 3
Currently some CloudFormation queries do not support the newer "AWS::EC2::SecurityGroupIngress" and "AWS::EC2::SecurityGroupEgress" resources, only working for samples with the legacy "AWS::EC2::SecurityGroup" resource.
This Pull Request will only handle the first 5 queries to simplify the review processes to come.
Query List
Proposed Changes
Firstly i fixed the issues mentioned for the ✅"ELB With Security Group Without Inbound Rules" query, the new implementation now works as intended, additionally new negative tests were added to show "AWS::EC2::SecurityGroupIngress" resources prevent flagging and new positive tests to show that the "GroupId" must have the correct reference name, lastly some of these new tests have an "elb" of type "AWS::ElasticLoadBalancingV2::LoadBalancer" to ensure that said type is also supported. Note that the changes on this query affected 4 E2E tests because line 14 was wrongfully flagged on positive.yaml, the security grup has standalone ingress rules but still flagged because it did not declare a "SecurityGroupIngress" array.
✅ELB With Security Group Without Outbound Rules
✅DB Security Group With Public Scope
The default behavior value depends on your VPC setup and the database subnet group.
" , so we cannot assume that it defaults to "false".✅Default Security Groups With Unrestricted Traffic
default
" does not flag.Note : In the query the "searchValue" for the current implementation to the whole "Properties" field of the flagged "AWS::EC2::SecurityGroup" field when it could point to the "Properties.SecurityGroupIngress" or "Properties.SecurityGroupEgress" fields, this time i left said value unchanged; it does not seem warranted given the impact on the simID.
get_ingress_list_if_exists
function and thesearch_for_standalone_ingress
function to get all ingresses available; additionally the "IpProtocol" set to "-1" scenario is properly handles by theget_sensitive_ports
function.udp
" protocol as well not just the ones that are "expected" to be used through TCP only; with this change the related queries were simplified and are more thorough overall.Note : Initially i found the "EC2" query's implementation to be particularly odd; it did not flag all "AWS::EC2::SecurityGroup" that were exposed, only the ones associated with an "AWS::EC2::Instance". This is inline with the query naming but goes against the way most other queries work and how the analog terraform query works. The "ELB" analog has the same behavior for ELB resources. I believe it could be argued the analog terraform query's approach is better by, with a single query, flagging all exposed security groups regardless of being in use or not; but since deleting a query is not something i can do out of the blue i decided to simply fall back to focus on the original intent of both these queries with focus on the support for the missing resource, the "AWS::EC2::SecurityGroupIngress".
After completing all the queries initial implementations i decided to adjust the logic for the DB Security Group With Public Scope query since the code for the main auxiliary function was significantly bigger than necessary. (a5fd335)
Additionally i checked if it was possible to include the legacy "[AWS::RDS::DBSecurityGroup]
(https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-rds-dbsecuritygroup.html)" resource whenever possible but it is only possible for the query that already checked for it (Default Security Groups With Unrestricted Traffic), all the other queries rely on referencing of security groups through either the an "ELB" or "EC2" instance resource which exclusively support "AWS::EC2::SecurityGroup" VPC based security groups, they are incompatible with the "EC2-Classic" based "AWS::RDS::DBSecurityGroup" which is mostly unused nowadays. The one query that could apply "Default Security Groups With Unrestricted Traffic" is also incompatible since it relies on checking that the "GroupName" field is set to default, this field is exclusive to the newer security group resource.
Final Notes:
I submit this contribution under the Apache-2.0 license.