cloudformation-coverage-roadmap icon indicating copy to clipboard operation
cloudformation-coverage-roadmap copied to clipboard

AWS::EC2::Instance - MetadataOptions

Open michaelwittig opened this issue 5 years ago • 23 comments

1. AWS::EC2::Instance-MetadataOptions

2. Scope of request

Add support to configure the EC2 IMDS to support:

  • Enable/disable the endpoint
  • Set the HTTP response hop limit
  • Make HTTP tokens optional (default) or required (disables IMDSv1)

3. Expected behavior

Allow CloudFormation to launch EC2 instance with IMDS disabled or restricted to v2.

5. Helpful Links to speed up research and evaluation

  • Description of IMDS: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
  • create: MetadataOptions attribute of https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html
  • update: https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_ModifyInstanceMetadataOptions.html

6. Category

  1. Compute (EC2, ECS, EKS, Lambda...)

7. Context

related #273 for for WS::AutoScaling::LaunchConfiguration

michaelwittig avatar Oct 15 '20 14:10 michaelwittig

Looks like this is now possible via Launch Templates: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-launchtemplatedata.html#cfn-ec2-launchtemplate-launchtemplatedata-metadataoptions

0xdabbad00 avatar Oct 05 '21 18:10 0xdabbad00

@0xdabbad00 Right, that has been true for quite a while. This issue is to add it to the AWS::EC2::Instance type: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html

mildebrandt avatar Oct 05 '21 18:10 mildebrandt

Any update?

coreylane avatar Mar 17 '22 21:03 coreylane

Any update?

yoroto avatar Mar 18 '22 00:03 yoroto

This would also be useful to set the feature "instance-metadata-tags" to enabled

fortygigserver avatar Mar 22 '22 22:03 fortygigserver

I agree this is a useful feature to set the feature "instance-metadata-tags" to enabled.

r-azh avatar Mar 25 '22 14:03 r-azh

Hi, any update on this? Having to use launch templates to enable ImdsV2 on EC2 instance is causing us issues. Launch template don't allow tags with spaces, and our SCP policies fail if we enforce both tags and ImdsV2 at the same time, hopefully when this CloudFormation limitation is resolved.

kenlawrie1 avatar May 13 '22 00:05 kenlawrie1

Any updates? Also need this feature.

edc1934 avatar Jul 25 '22 19:07 edc1934

Going on two years for this trivial feature. I'm still trying to use Service Catalog, which requires vanilla CloudFormation. The InstanceMetadataTags option is missing from Launch Templates, so I can't use that either.

Add me to the list of people who would like this feature added.

donwalter avatar Sep 22 '22 19:09 donwalter

Hi everyone,

Is there any example of enabling IMDSv2 in Autoscaling:Launchconfiguration cloudformation template? I would highly appreciate any reference or example.

torabTech avatar Oct 30 '22 18:10 torabTech

@torabTech HttpPutResponseHopLimit set to 2 is required because the IMDSv2 will bring the extra hop in communication with metadata service

"LaunchTemplate":{
  "Properties":{
    "LaunchTemplateData":{
      "MetadataOptions":{
        "HttpTokens":"required",
        "HttpPutResponseHopLimit":2
      }
    }
  },
  "Type":"AWS::EC2::LaunchTemplate"
}

"AutoScalingGroup": {
  "Properties": {
    "LaunchTemplate": {
      "LaunchTemplateId": {
        "Ref": "LaunchTemplate"
      },

      "Version": {
        "Fn::GetAtt": [
          "LaunchTemplate",
          "LatestVersionNumber"
        ]
      }
    }
  "Type": "AWS::AutoScaling::AutoScalingGroup"
}

otakusid avatar Oct 31 '22 09:10 otakusid

Adding a +1 here. We need this option as well.

AWS - What if we said Pretty Please?

bv300t avatar Nov 09 '22 13:11 bv300t

IMDSv2 is also part of the Security Hub standards - EC2.8 EC2 instances should use Instance Metadata Service Version 2 (IMDSv2). Our security score gets dinged when we don't use IMDSv2, but we're also supposed to use code to provision resources. This creates a catch-22 situation. I hope this helps as far as prioritizing. Thank you!

Rob-El avatar Dec 12 '22 21:12 Rob-El

@Rob-El : use a launch template for your instance with only those parts that you need, and include that in the instance. It also allows you to tag network interfaces and volumes as a bonus. But beware of changes in the launch template once deployed, as that can cause a redeploy.

siebrand avatar Dec 12 '22 22:12 siebrand

@siebrand Thanks for the tip! I do understand that launch templates are a workaround, I read through all the previous comments. In my opinion, Launch Templates adds a cumbersome amount of config, for various reasons.

Also, redeployment is highly undesirable in our environment, as we have a lot of 3rd-party, static applications that are long-lived. (We create the server, install the OS, hand it off to another team.) Over time we add additional tags, add a volume, etc. If any of those operations (or the dozen other reasons we update a CF template) caused a re-deploy, it would wipe the app and force a restore from backups, etc.

I'm happy to use ELB, ASGs, and Launch Templates for their own particular use cases, but these applications are not designed for use in those environments. Thanks again!

Rob-El avatar Dec 12 '22 22:12 Rob-El

Extremely useful option. This should be roadmapped.

josephhernandezphd avatar Dec 12 '22 23:12 josephhernandezphd

Same here, having to rewrite all my template to be able to get "instance-metadata-tags" to enabled, 2 years seems a long time for this to be at minimum reviewed.

smorgant avatar Jan 18 '23 22:01 smorgant

Ugh

kylegibson-rldatix avatar May 02 '23 11:05 kylegibson-rldatix

Oh yes please. Been wishing for this since 2019!

kz974 avatar Jun 15 '23 21:06 kz974

Have you guys realised you can disable IMDSV1 in a running AMI?

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-IMDS-new-instances.html

Run the following from a place where you can run AWS commands,

aws ec2 modify-image-attribute \ --image-id ami-0123456789example \ --imds-support v2.0

Any EC2 instances launched using the above AMI will have IMDSV1 disabled.

I hope this helps, Thanks

anjanasilva avatar Sep 05 '23 17:09 anjanasilva