Skip to content

Commit 1c231df

Browse files
corelight-rickyRicky Lin
andauthored
security: Enforce IMDSv2 on EC2 launch template (CKV_AWS_79) (#31)
* security: Enforce IMDSv2 on EC2 launch template (CKV_AWS_79) Remediation for Checkov security check CKV_AWS_79 and CISA Near-Term Essential Security (NES) requirement for EC2 instance metadata protection. Changes: - Add metadata_options block to aws_launch_template.sensor_launch_template - Set http_tokens = 'required' to enforce IMDSv2 (session-oriented) - Set http_put_response_hop_limit = 1 to limit metadata service access - Keep http_endpoint = 'enabled' to maintain metadata availability Security Benefits: - Prevents SSRF attacks against instance metadata service - Requires PUT request before GET (session tokens) - Aligns with AWS security best practices - Satisfies CISA NES control requirements References: - https://docs.aws.amazon.com/securityhub/latest/userguide/ec2-controls.html#ec2-8 - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html - https://www.cisa.gov/resources-tools/resources/near-term-essential-security-nes Testing: Verified with checkov security scanner before and after change. No functional impact - IMDSv2 is backward compatible with AWS SDKs. * refactor: Simplify metadata_options to match bastion module - Remove redundant http_put_response_hop_limit (defaults to 1) - Match existing pattern in modules/bastion/instance.tf - Still passes CKV_AWS_79 security check --------- Co-authored-by: Ricky Lin <ricky@Rickys-MacBook-Pro.local>
1 parent 25e0213 commit 1c231df

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

launch_template.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ resource "aws_launch_template" "sensor_launch_template" {
1414
}
1515
}
1616

17+
# CKV_AWS_79: Enforce IMDSv2 (Instance Metadata Service Version 2)
18+
metadata_options {
19+
http_endpoint = "enabled"
20+
http_tokens = "required"
21+
}
22+
1723
block_device_mappings {
1824
device_name = var.sensor_launch_template_volume_name
1925

0 commit comments

Comments
 (0)