Terraform-provider-aws: Support setting EC2 instance metadata to require token (IMDSv2)

Created on 20 Nov 2019  ·  4Comments  ·  Source: hashicorp/terraform-provider-aws

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Launched here: https://aws.amazon.com/blogs/security/defense-in-depth-open-firewalls-reverse-proxies-ssrf-vulnerabilities-ec2-instance-metadata-service/

EC2 instances can be set to require IMDSv2 only. This can be done to running instances with https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#EC2.ModifyInstanceMetadataOptions or new instances with the MetadataOptions field of RunInstancesInput.

New or Affected Resource(s)

  • aws_instance

Potential Terraform Configuration

resource "aws_instance" "this" {
    // ...
    metadata_options {
        http_tokens = "required"
    }
}

References

enhancement servicec2

Most helpful comment

This should also support optionally setting the PUT response hop limit

Such as outlined by the following AWS CLI command
aws ec2 modify-instance-metadata-options --instance-id i-1234567898abcdef0 --http-put-response-hop-limit 3

```terraform
resource "aws_instance" "this" {
// ...
metadata_options {
http_tokens = "required"
http_put_response_hop_limit = "1"
}
}
````

All 4 comments

This should also support optionally setting the PUT response hop limit

Such as outlined by the following AWS CLI command
aws ec2 modify-instance-metadata-options --instance-id i-1234567898abcdef0 --http-put-response-hop-limit 3

```terraform
resource "aws_instance" "this" {
// ...
metadata_options {
http_tokens = "required"
http_put_response_hop_limit = "1"
}
}
````

Support for configuring metadata options in the aws_instance and aws_launch_template resources has been merged and will release with version 2.55.0 of the Terraform AWS Provider, later today. Thanks to @stefansundin and @ewbankkit for the implementation. 👍

This has been released in version 2.55.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings