Control: 170 EC2 launch templates should use Instance Metadata Service Version 2 (IMDSv2)
Description
This control checks whether an Amazon EC2 launch template is configured with Instance Metadata Service Version 2 (IMDSv2). The control fails if HttpTokens is set to optional.
Running resources on supported software versions ensures optimal performance, security, and access to the latest features. Regular updates safeguard against vulnerabilities, which help ensure a stable and efficient user experience.
Remediation
To require IMDSv2 on an EC2 launch template, see Configure the Instance Metadata Service options in the Amazon EC2 User Guide.
Usage
Run the control in your terminal:
powerpipe control run aws_compliance.control.foundational_security_ec2_170
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run aws_compliance.control.foundational_security_ec2_170 --share
SQL
This control uses a named query:
select launch_template_id as resource, case when launch_template_data -> 'MetadataOptions' ->> 'HttpTokens' = 'required' then 'ok' else 'alarm' end as status, case when launch_template_data -> 'MetadataOptions' ->> 'HttpTokens' = 'required' then title || ' configured to use Instance Metadata Service Version 2 (IMDSv2).' else title || ' not configured to use Instance Metadata Service Version 2 (IMDSv2).' end as reason , region, account_idfrom aws_ec2_launch_template_versionwhere default_version;