📣 Limited offer: subscribe to cloudonaut plus, get a t-shirt for free

📣 Limited offer: free cloudonaut t-shirt

EC2 Instance Connect is an insecure default!

Andreas Wittig – 20 Aug 2019

You can also listen to this topic in our podcast!

Two months before, Michael wrote about why AWS SSM is a trojan horse. Shortly after that, AWS released EC2 Instance Connect, which is even worse. If you use Amazon Linux 2 or Ubuntu, the chances are high that everyone in your AWS account can SSH into every EC2 instance!

Rant

What is EC2 Instance Connect

EC2 Instance Connect makes your public SSH key available on an EC2 instance using the metadata service. To push your public key to an EC2 instance, you use the SendSSHPublicKey API.

The SSH daemon (sshd) needs to be configured to ask the metadata service for all public keys when someone connects via SSH. This configuration is enabled for you by default on Amazon Linux 2 and Ubuntu AMIs. We discovered this breaking change in November 2018.

Special offer: cloudonaut t-shirt

Do you love our blog posts and podcast episodes? Unlock our weekly videos and online events by subscribing to cloudonaut plus.

Special offer: Join cloudonaut plus before November 30th, and we will send you a cloudonaut t-shirt for free.

Subscribe now!

How the backdoor works

These three conditions must be met:

  1. Use the official Amazon Linux 2 or Ubuntu AMIs
  2. Allow traffic on port 22. If you used SSH in the past to manage your instances, the port is already open.
  3. Your IAM user or role needs permissions (action ec2-instance-connect:SendSSHPublicKey). Very likely, you have those permissions thanks to managed policies like AdministratorAccessor PowerUserAccess.

You can now open an SSH connection to every EC2 instance in your AWS account.

Protect yourself

If you are not interested in using EC2 Instance Connect, you can do one of the following:

If you want to use EC2 Instance Connect:

  1. Keep your Security Groups as close as possible and use a VPN to connect to your VPC.
  2. Grant the ec2-instance-connect:SendSSHPublicKey action carefully. According to IAM docs, you only can use a condition to restrict the OS user. According to the EC2 Instance Connect docs, you can also restrict access to specific EC2 instances using resource-level permissions. Unfortunately, EC2 Instance tags don’t seem to be supported.

Summary

AWS released a new feature called EC2 Instance Connect. It is enabled by default on Amazon Linux 2 and Ubuntu AMIs. We would appreciate if AWS would ask us - the customers - before they change defaults that increase our security risks. And we would also love to see up-to-date documentation on the IAM configuration. The information is contradictory at the moment, which is not satisfactory when security is at risk!

Andreas Wittig

Andreas Wittig

I’m an independent consultant, technical writer, and programming founder. All these activities have to do with AWS. I’m writing this blog and all other projects together with my brother Michael.

In 2009, we joined the same company as software developers. Three years later, we were looking for a way to deploy our software—an online banking platform—in an agile way. We got excited about the possibilities in the cloud and the DevOps movement. It’s no wonder we ended up migrating the whole infrastructure of Tullius Walden Bank to AWS. This was a first in the finance industry, at least in Germany! Since 2015, we have accelerated the cloud journeys of startups, mid-sized companies, and enterprises. We have penned books like Amazon Web Services in Action and Rapid Docker on AWS, we regularly update our blog, and we are contributing to the Open Source community. Besides running a 2-headed consultancy, we are entrepreneurs building Software-as-a-Service products.

We are available for projects.

You can contact me via Email, Twitter, and LinkedIn.

Briefcase icon
Hire me