-
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): Ensure EC2 launch templates do not assign public IPs #4852
feat(ec2): Ensure EC2 launch templates do not assign public IPs #4852
Conversation
… chose what we save for each launch template version, adjust the service test to the changes
f"EC2 Launch Template {template.name} in template versions: " | ||
f"{', '.join(versions_with_public_ip)} is configured to assign a public IP address." |
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.
f"EC2 Launch Template {template.name} in template versions: " | |
f"{', '.join(versions_with_public_ip)} is configured to assign a public IP address." | |
f"EC2 Launch Template {template.name} is configured to assign a public IP address to network interfaces upon launch in template versions: f"{', '.join(versions_with_public_ip)}." |
) | ||
else: | ||
report.status = "PASS" | ||
report.status_extended = f"No versions of EC2 Launch Template {template.name} are configured to assign a public IP address." |
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.
report.status_extended = f"No versions of EC2 Launch Template {template.name} are configured to assign a public IP address." | |
report.status_extended = f"EC2 Launch Template {template.name} is not configured to assign a public IP address to network interfaces upon launch." |
Can we also check the second part of the check? |
…-in-template-data-in-launch-template-version' into PRWLR-4304-add-new-ec-2-check-to-ensure-public-i-ps-are-not-assigned-to-network-interfaces
…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
…-in-template-data-in-launch-template-version' into PRWLR-4304-add-new-ec-2-check-to-ensure-public-i-ps-are-not-assigned-to-network-interfaces
…he-data-saved-in-template-data-in-launch-template-version
…-in-template-data-in-launch-template-version' into PRWLR-4304-add-new-ec-2-check-to-ensure-public-i-ps-are-not-assigned-to-network-interfaces
…blic_ip_addresses
…-in-template-data-in-launch-template-version' into PRWLR-4304-add-new-ec-2-check-to-ensure-public-i-ps-are-not-assigned-to-network-interfaces
…check, change the default value for the publi_ip_autoassign and add tests
…blic-i-ps-are-not-assigned-to-network-interfaces
versions_with_network_interfaces_public_ip.append( | ||
str(version.version_number) | ||
) | ||
break |
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 a break here? Don't we want to add all the versions with this issue?
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.
That break is only to stop looking in the network interfaces for public IPs, it will still add every version that is using a network interface with a public IP. That is only to optimize because a version can have a ton of network interfaces and it could take so long if not adding that break. My first idea was to add the network interface's id but that would require to iterate over all the network interfaces and that could cause the check to take a lot of time.
) | ||
if version.template_data.network_interfaces: | ||
for network_interface in version.template_data.network_interfaces: | ||
if network_interface.public_ip_addresses != []: |
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.
if network_interface.public_ip_addresses != []: | |
if network_interface.public_ip_addresses: |
if ( | ||
versions_with_autoassign_public_ip | ||
or versions_with_network_interfaces_public_ip | ||
): | ||
report.status = "FAIL" | ||
extended_messages = [] | ||
|
||
if versions_with_autoassign_public_ip: | ||
extended_messages.append( | ||
f"EC2 Launch Template {template.name} is configured to assign a public IP address to network interfaces upon launch in template versions: {', '.join(versions_with_autoassign_public_ip)}." | ||
) | ||
|
||
if versions_with_network_interfaces_public_ip: | ||
extended_messages.append( | ||
f"EC2 Launch Template {template.name} is using a network interface with public IP addresses in template versions: {', '.join(versions_with_network_interfaces_public_ip)}." | ||
) | ||
|
||
report.status_extended = " ".join(extended_messages) |
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.
It is better to create 3 different status extended that using this logic to mix two of them.
…blic-i-ps-are-not-assigned-to-network-interfaces
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4852 +/- ##
==========================================
+ Coverage 88.92% 88.97% +0.05%
==========================================
Files 945 958 +13
Lines 29026 29372 +346
==========================================
+ Hits 25810 26134 +324
- Misses 3216 3238 +22
|
Context
This check verifies whether Amazon EC2 launch templates are configured to assign public IP addresses to network interfaces upon launch. The check fails if an EC2 launch template is set to assign a public IP address to network interfaces or if any network interface has a public IP address.
Description
Added
ec2_launch_template_no_public_ip
check with metadata and respective unit tests.Checklist
License
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.