This is quick howto for installing vault on AWS Linux, mostly to remind myself. At the end of this tutorial, you'll have a working vault server, using s3 for the backend, self signed certificates for tls, and supervisord to ensure that the vault server is always running, and starts on reboot.
First things first, let's set up an s3 bucket to use as the storage backend for our s3 instance.
-
From the AWS Mangement Console, go to the S3 console.
-
Click on the
Create Bucket
button -
Name it something
Next, let's create an IAM Policy with full access to our newly created bucket. We'll also create an IAM Role and IAM User in this step, but this should not be neccessary once Vault v5 is released.
-
From the AWS Management Console, go the IAM console.
-
Click on Policies in the sidenav
-
Click on Create Policy
-
Select S3 from the service section
-
Select All Actions (s3:*) from the Actions section
-
Open the Resources section and select Add ARN in the bucket section
-
Enter:
arn:aws:s3:::<your_bucket_name>
-
Add another ARN:
arn:aws:s3:::<your_bucket_name>/*
(this is required to let vault manage all keys within the bucket) -
Click Review Policy
-
Give the policy a name:
s3-vault-full-access
-
Click
Create Policy
Next, we create an IAM Role and attach our policy to it. We will use this role as the EC2 instance role later on.
-
Click on Roles in the side nav
-
Click Create Role
-
Under Create Role, select AWS Service and then EC2, then click Next: Permissions
-
Find our newly created
s3-vault-full-access
policy, select it and click Next: Tags -
Add tags, if you want, then click Next: Review
-
Give the role a name:
vault-ec2
-
Lastly, click Create Role
-
Click on Users from the side nav
-
Click on Add User
-
Enter a username:
vault
-
Select Programmatic access from the Select AWS access type section
-
Click Next: Permissions
-
Click Attach existing policies directly
-
Select the
s3-vault-full-access
policy. -
Click Next: Tags, then Next: Review
-
Click Create User
-
Save/download the security credentials on the next screen and click Close
-
Back to the Users screen, and click on our newly created user
Ok, now it's time to launch an ec2 that will act as our Vault server.
-
From the AWS Management Console, go to the EC2 console.
-
Click Launch Instance
-
Select the most recent Ubuntu Server LTS
-
Select an appropriate size, for this tutorial, I'll use a t2.nano
-
Click Next: Configure Instance Details
-
Under IAM role, select the IAM Role we created earlier (
s3-vault-full-access
) -
Click Next: Add Storage
-
The default storage is fine, so click Next: Add Tags
-
Add tags, if you want
-
Click Next: Configure Security Group
-
Give your security group a name:
vault
-
Give your security group a description:
vault server security group
-
Click Add Rule
-
Select Custom TCP Rule and define a port range:
8200
-
Under source, for the purposes of this tutorial, select My IP. However, in production, you should restrict this port to the security groups of the servers that require access to vault.
-
Click Review and Launch
-
Click Launch
-
If you have an existing key-pair, you can use it, or create a new one and download it
-
Lastly, click Launch Instances and then View Instances
Use your preferred method for pointing a domain (e.g. vault.netsensia.com) to your new EC2 instance.
- Temporarily enable inbound ports 80 and 443 from Anywhere, and port 22 from your local machine
- Login to the EC2 box using your generated key: e.g. ssh -i ~/Downloads/vault-key.pem [email protected]
- Run the following commands
sudo apt-get update -y
sudo git clone https://github.com/certbot/certbot /opt/letsencrypt
cd /etc
sudo mkdir letsencrypt
cd
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
./certbot-auto certonly --standalone --debug -d YOUR_DOMAIN
sudo bash
chown ubuntu:ubuntu /etc/letsencrypt/live/YOUR_DOMAIN/*.pem
- Remove the inbound rules added in step 1
Note that you will need to re-instate the inbound rules to renew the certificate.
Have a job set to run each day with the following command to avoid the certicate expiring after three months, or, alternatively, wait for it to expire and then run the command.
You will need to ensure that no services such as web servers are running on port 443.
Once the instance has finished initializing, it's time to download the Vault binary and unpack it.
- update the instance
sudo apt-get -y update
- install Vault (find the latest binary on the vault project page)
cd
wget https://releases.hashicorp.com/vault/1.1.0/vault_1.1.0_linux_amd64.zip
- unzip it
sudo apt-get install unzip
unzip vault_1.1.0_linux_amd64.zip
- move the binary
sudo mv vault /usr/local/bin/vault
- verify that Vault is ready to go
vault version
- create the vault configuration file
touch vault-config.hcl
- edit the file
vi vault-config.hcl
- define the vault configuration like so.
listener "tcp" {
address = "0.0.0.0:8200"
tls_cert_file="/home/ec2-user/.ssl/server.crt"
tls_key_file="/home/ec2-user/.ssl/server.key"
}
backend "s3" {
bucket = "<your_bucket_name>"
region = "eu-west-2"
}
disable_mlock=true
Next, we install supervisord, which will simplify the whole "let's get Vault running as a service, and have it start on reboot, blah blah blah"
- install
supervisor
sudo apt-get install -y supervisor
- create a new
supervisord
configuration file
echo_supervisord_conf > supervisord.conf
-
modify the configuration file
- under
[unix_http_server]
- change
;chmod=0700
tochmod=0766
- change
- change the
;[program:theprogramname]
header to[program:vault]
- under
[program:vault]
- change
;command=/bin/cat
tocommand=/usr/local/bin/vault server -config=/home/ubuntu/vault-config.hcl
- change
;user=chrism
touser=ubuntu
- change
;autostart=true
toautostart=true
- change
;environment=A="1",B="2"
toenvironment=AWS_ACCESS_KEY_ID="<your_access_key_id>",AWS_SECRET_ACCESS_KEY="<your_secret_access_key>"
, where<your_access_key_id>
and<your_secret_access_key>
are the credentials you downloaded/wrote down when we created thevault
user.
- change
- under
-
Move the file
sudo mv supervisord.conf /etc/supervisor/
- add the supervisor init script to chkconfig services
sudo update-rc.d supervisord defaults
- start the supervisord service
sudo service supervisor start
supervisorctl
Exit out of the Linux VM
exit
Create a key, require only the one key to unseal the vault.
export VAULT_ADDR=<vault url>:8200
vault init -key-shares=1 -key-threshold=1
Hi,
The last step before initializing Vault has failed for me. Calling "supervisorctl" resulted
"FATAL Exited too quickly (process log may have details)". Any idea what can be the reason or how to troubleshoot it?
Thanks,
Yossi