<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Geoffroy RENAUD</title>
    <description>The latest articles on Forem by Geoffroy RENAUD (@geoffroyrenaud).</description>
    <link>https://forem.com/geoffroyrenaud</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F273684%2F9a08cd2a-307b-4e2c-b401-c0a89bc1bc1b.jpg</url>
      <title>Forem: Geoffroy RENAUD</title>
      <link>https://forem.com/geoffroyrenaud</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/geoffroyrenaud"/>
    <language>en</language>
    <item>
      <title>AWS protect SSRF vulnerabilities with new EC2 Instance Metadata feature</title>
      <dc:creator>Geoffroy RENAUD</dc:creator>
      <pubDate>Wed, 20 Nov 2019 21:39:50 +0000</pubDate>
      <link>https://forem.com/geoffroyrenaud/aws-protect-ssrf-vulnerabilities-with-new-ec2-instance-metadata-feature-2b9l</link>
      <guid>https://forem.com/geoffroyrenaud/aws-protect-ssrf-vulnerabilities-with-new-ec2-instance-metadata-feature-2b9l</guid>
      <description>&lt;p&gt;After the annonce on the AWS Security blog for protecting AWS instance from SSRF attack, we should test and implement this new security feature: &lt;a href="https://aws.amazon.com/fr/blogs/security/defense-in-depth-open-firewalls-reverse-proxies-ssrf-vulnerabilities-ec2-instance-metadata-service/"&gt;https://aws.amazon.com/fr/blogs/security/defense-in-depth-open-firewalls-reverse-proxies-ssrf-vulnerabilities-ec2-instance-metadata-service/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;AWS documentation about this feature : &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#configuring-instance-metadata-options"&gt;https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#configuring-instance-metadata-options&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is 2 methods in order to use it :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add a policy to your users/geoups with this example policy :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Version": "2012-10-17",
    "Statement": [{
        "Sid": "RunInstanceWithImdsV2Only",
        "Effect": "Allow",
        "Action": "ec2:RunInstances",
        "Resource": "*",
        "Condition": {
            "StringEquals": {
                "ec2:MetadataHttpTokens": "required"
            }
        }
    }]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Modify a running instance metadata :
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;aws ec2 modify-instance-metadata-options --instance-id i-1234567898abcdef0 --http-token required&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;em&gt;We need to enforce this best practice if possible by design using AWS Organization SCP.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here a first try for a policy to Enforce EC2 Metadata Token :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "EnforceEC2metadataTOKEN",
            "Effect": "Deny",
            "Action": "ec2:RunInstances",
            "Resource": [
                "*"
            ],
            "Condition": {
                "StringNotEquals": {
                    "ec2:MetadataHttpTokens": "required"
                }
            }
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Seems working for me, I need to try more when Terraform or CDK will implement the  feature to completely validate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/aws/aws-cdk/issues/5137"&gt;https://github.com/aws/aws-cdk/issues/5137&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/terraform-providers/terraform-provider-aws/issues/10949"&gt;https://github.com/terraform-providers/terraform-provider-aws/issues/10949&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://twitter.com/ejcx_"&gt;@ejcx_&lt;/a&gt; wrote an article about this feature with a incomplete satisfaction, here why with explanation: &lt;a href="https://ejj.io/blog/fixing-capital-one"&gt;https://ejj.io/blog/fixing-capital-one&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>security</category>
      <category>ssrf</category>
    </item>
  </channel>
</rss>
