Control: EC2 instances should use IMDSv2
Description
Ensure the Instance Metadata Service Version 2 (IMDSv2) method is enabled to help protect access and control of Amazon Elastic Compute Cloud (Amazon EC2) instance metadata.
Usage
Run the control in your terminal:
powerpipe control run terraform_aws_compliance.control.ec2_instance_uses_imdsv2
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run terraform_aws_compliance.control.ec2_instance_uses_imdsv2 --share
SQL
This control uses a named query:
select address as resource, case when coalesce(trim(attributes_std -> 'metadata_options' ->> 'http_tokens'),'') in ('optional', '') then 'alarm' else 'ok' end as status, split_part(address, '.', 2) || case when (attributes_std -> 'metadata_options' -> 'http_tokens') is null then ' ''http_tokens'' is not defined' when (attributes_std -> 'metadata_options' ->> 'http_tokens') = 'optional' then ' not configured to use Instance Metadata Service Version 2 (IMDSv2)' else ' configured to use Instance Metadata Service Version 2 (IMDSv2)' end || '.' as reason , path || ':' || start_linefrom terraform_resourcewhere type = 'aws_instance';