Use AWS auth to Secure EC2 Instances with HashiCorp Vault
HashiCorp Vault’s aws auth method provides an easy and secure way to authenticate EC2 instances to Vault and retrieve secrets. There are two ways of using aws auth - ec2 and iam. Both ways have a completely different workflow, and this Shortcut is focused on the ec2 way.
Prerequisites
-
You need a running Vault cluster. Refer to the Shortcut “Run HashiCorp Vault with Helm” for a refresher on running Vault. Ensure that your Vault cluster is available over the internet to allow your EC2 instance to connect to it.
-
You also need a running EC2 instance. If needed, refer to the official AWS documentation on launching an EC2 instance.
Update EC2 Instance
-
Create an IAM role in AWS with the following policy attached to it:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "sts:AssumeRole", "Resource": "*" } ] } -
Attach the IAM role to your EC2 instance.
-
Install Vault on the EC2 instance per the official HashiCorp documentation.
Set Up AWS auth Method in Vault
-
Enable the
aws authmethod:vault auth enable aws
You should see a success message.
-
Configure the
aws authmethod:vault write auth/aws/config/client access_key=<your-aws-access-key> secret_key=<your-aws-secret-key> region=<your-aws-region>
You should see a success message like the following:
Success! Data written to: auth/aws/config/client
-
Create a role.
-
Copy your EC2 ...
-
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access