Browse the Repo

file-type-icon.circleci
file-type-icon_ci
file-type-icon_docs
file-type-iconexamples
file-type-iconroot-example
file-type-iconvault-agent
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconuser-data-auth-client.sh
file-type-iconuser-data-consul.sh
file-type-iconuser-data-vault.sh
file-type-iconvariables.tf
file-type-iconvault-auto-unseal
file-type-iconvault-cluster-private
file-type-iconvault-consul-ami
file-type-iconvault-ec2-auth
file-type-iconvault-examples-helper
file-type-iconvault-iam-auth
file-type-iconvault-s3-backend
file-type-iconmodules
file-type-icontest
file-type-icon.gitignore
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconLICENSE
file-type-iconNOTICE
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf

Browse the Repo

file-type-icon.circleci
file-type-icon_ci
file-type-icon_docs
file-type-iconexamples
file-type-iconroot-example
file-type-iconvault-agent
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconuser-data-auth-client.sh
file-type-iconuser-data-consul.sh
file-type-iconuser-data-vault.sh
file-type-iconvariables.tf
file-type-iconvault-auto-unseal
file-type-iconvault-cluster-private
file-type-iconvault-consul-ami
file-type-iconvault-ec2-auth
file-type-iconvault-examples-helper
file-type-iconvault-iam-auth
file-type-iconvault-s3-backend
file-type-iconmodules
file-type-icontest
file-type-icon.gitignore
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconLICENSE
file-type-iconNOTICE
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
HashiCorp Vault

HashiCorp Vault

Deploy a Vault cluster. Supports automatic bootstrapping, Consul and S3 backends, self-signed TLS certificates, and auto healing.

Code Preview

Preview the Code

mobile file icon

README.md

down

Vault agent example

This example shows how to use Vault agent's auto-auth feature to authenticate to a vault cluster. Vault agent automatically handles renewal and re-authentication and thus you do not have to implement potentially complicated renewal logic yourself.

This example uses the AWS IAM Auth Method to authenticate, and builds upon the IAM auth example, creating the same Vault example-role. The difference between that and this example is instead of using curl to access the Vault API to authenticate, this example uses Vault agent to authenticate. The authentication token is written to a file under the Vault agent install directory (by default, /opt/vault/data/vault-token), which only the vault user has access to after installation.

Note: To keep this example as simple to deploy and test as possible and because we are focusing on authentication, it deploys the Vault cluster into your default VPC and default subnets, all of which are publicly accessible. This is OK for learning and experimenting, but for production usage, we strongly recommend deploying the Vault cluster into the private subnets of a custom VPC.

Running this example

You will need to create an [Amazon Machine Image (AMI)][ami] that has both Vault and Consul installed, which you can do using the vault-consul-ami example). All the EC2 Instances in this example (including the EC2 Instance that authenticates to Vault) install either Dnsmasq (via the install-dnsmasq module) or setup-systemd-resolved (in the case of Ubuntu 18.04) so that all DNS queries for *.consul will be directed to the Consul Server cluster. Because Consul has knowledge of all the Vault nodes (and in some cases, of other services as well), this setup allows the EC2 Instance to use Consul's DNS server for service discovery, and thereby to discover the IP addresses of the Vault nodes.

Quick start

  1. git clone this repo to your computer.
  2. Build a Vault and Consul AMI. See the vault-consul-ami example documentation for instructions. Make sure the install_auth_signing_script variable is true. Make sure to note down the ID of the AMI.
  3. Install Terraform.
  4. Open variables.tf, set the environment variables specified at the top of the file, and fill in any other variables that don't have a default. Put the AMI ID you previously took note into the ami_id variable.
  5. Run terraform init.
  6. Run terraform apply.
  7. Run the vault-examples-helper.sh script to print out the IP addresses of the Vault server and some example commands you can run to interact with the cluster: ../vault-examples-helper/vault-examples-helper.sh.
  8. Run curl <auth-instance-ip>:8080 to check if the client instance is fetching the secret from Vault properly

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?