-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(ec2): Amazon EC2 Instances Should Not Use Multiple ENIs #4935
feat(ec2): Amazon EC2 Instances Should Not Use Multiple ENIs #4935
Conversation
… chose what we save for each launch template version, adjust the service test to the changes
…bute public_ip_addresses with ipaddress IPs to the NetworkInterface model with tests, added tags to LaunchTemplate model and list with network interfaces to TemplateData model
…erfaces to adjust to the change from list to dict and add new attribute public_ip_addresses to one ec2 test
…he-data-saved-in-template-data-in-launch-template-version
…blic_ip_addresses
…l, network_interfaces, and adjust service tests
…t-use-multiple-en-is
@@ -72,6 +72,11 @@ def _describe_instances(self, regional_client): | |||
if not self.audit_resources or ( | |||
is_resource_filtered(arn, self.audit_resources) | |||
): | |||
enis = [] | |||
for eni in instance.get("NetworkInterfaces"): |
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.
for eni in instance.get("NetworkInterfaces"): | |
for eni in instance.get("NetworkInterfaces, []"): |
) | ||
|
||
message_status_extended = "" | ||
if len(eni_types["efa"]) + len(eni_types["interface"]) > 1: |
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.
Why not trunk here?
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.
SecurityHub recommendation is to check only for multiple EFAs or interfaces. Thats because a trunk ENI is used to increase the number of ENIs you can attach to a instance. For more information look at the first paragraph here https://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-instance-eni.html and at the AWSVPC trunking section here https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-account-settings.html. I don't know if there should be a limit to trunk ENIs maybe we have to discuss that.
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.
Can we then ignore trunk ENIs in the check? So the user do not get confused when seeing the status extended since he is not going to be able to delete those trunk ENIs.
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.
Why aren't you able to delete trunk ENIs? Looked for it in the docs but didn't find it. Still I think is a good idea to ignore trunk ENIs since they only add noise and no real value to the provided information.
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.
We saw that trunks are normal interfaces with a specific option so I would count it as an ENI too.
@@ -0,0 +1,34 @@ | |||
{ | |||
"Provider": "aws", | |||
"CheckID": "ec2_instance_multiple_eni", |
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.
"CheckID": "ec2_instance_multiple_eni", | |
"CheckID": "ec2_instance_uses_single_eni", |
assert result[0].resource_id == "i-0123456789abcdef0" | ||
assert ( | ||
result[0].status_extended | ||
== "EC2 Instance i-0123456789abcdef0 uses multiple ENIs: " |
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.
Can you prettify this message please?
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.
What do you mean by prettify? Should I add global attributes for the instance id and enis ids?
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.
Something like:
"EC2 Instance i-0123456789abcdef0 uses only one ENI: (EFAs: ['eni-2'], Trunks: ['eni-1', 'eni-3'].)"
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4935 +/- ##
==========================================
+ Coverage 88.94% 88.98% +0.04%
==========================================
Files 951 955 +4
Lines 29182 29295 +113
==========================================
+ Hits 25956 26069 +113
Misses 3226 3226
|
Context
Using multiple ENIs can lead to increased network security complexity and unintended network paths, particularly in instances with multiple subnets. I added a new check that helps ensure that instances are not overly complex or exposed to additional network risks.
Checks whether an Amazon EC2 instance uses multiple Elastic Network Interfaces (ENIs) or Elastic Fabric Adapters (EFAs). The control passes if the instance is using a single network adapter.
Description
Change
ec2_service
to add a new attribute network interfaces to Instance model saving ENIs ids to check type. Added the check logic inec2_instance_multiple_eni
. Added tests for service and check.Checklist
License
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.