Giter Club home page Giter Club logo

vault-aws-demoserver's Introduction

Hashicorp Vault on AWS Demo

Vault Auto-unseal using AWS KMS

RDS MYSQL database permissions

Vault CA backed SSH

This repo contains a file storage based Vault single server in AWS.
_ THIS IS NOT FOR PRODUCTION _


Setup

  1. Set this location as your working directory
  2. Set your AWS credentials as environment variables: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
  3. Set option variables by renaming terraform.tfvars.example to terraform.tfvars and edit the values to your needs.
  4. Grab the latest version of [Terraform https://www.terraform.io/downloads.html] (https://www.terraform.io/downloads.html)

Deployment Commands

Pull necessary plugins

$ terraform init

Run the terraform plan

$ terraform plan

Output provides the SSH instruction

$ terraform apply

Connect to the servers

Connect to the vault, ssh, and bastion servers

  • Look in the terraform output for the server ssh info
    $ ssh -i private.key ubuntu@<IP_ADDRESS>

Once logged in to any instance

$ vault status

Check out the vault credentials and unseal key on the Vault server

$ cat /opt/vault/setup/vault.unseal.info

Login on any server with the root token from above

$ vault login <INITIAL_ROOT_TOKEN>

NGINX Certs Demo

Run the scipt /opt/vault/nginx_demo.sh

Postgres Demo

$ vault login <INITIAL_ROOT_TOKEN>
$ vault read database/creds/admin-role
$ psql -h <YOUR_AMAZON_PUBILC_DNS> -d proddb -U

USERNAME -W
SELECT u.usename AS "Role name",
  CASE WHEN u.usesuper AND u.usecreatedb THEN CAST('superuser, create
database' AS pg_catalog.text)
       WHEN u.usesuper THEN CAST('superuser' AS pg_catalog.text)
       WHEN u.usecreatedb THEN CAST('create database' AS
pg_catalog.text)
       ELSE CAST('' AS pg_catalog.text)
  END AS "Attributes"
FROM pg_catalog.pg_user u
ORDER BY 1;

Transit Engine Demo

$ vault login
$ vault write transit/encrypt/orders plaintext=$(base64 <<< "4111 1111 1111 1111")
$ vault write transit/decrypt/orders ciphertext=“CIPHER"
$ base64 -d <<< <RESULTOFABOVE>

SSH Demo

THIS IS IN THE OUTPUT OF TERRAFORM

On the SSH host and the bastion host do one of these:

$ sudo curl -o /etc/ssh/trusted-user-ca-keys.pem http://54.176.94.52:8200/v1/ssh-client-signer/public_key
or
$ sudo su - $ VAULT_ADDR=http://54.176.94.52:8200 vault read -field=public_key ssh-client-signer/config/ca > /etc/ssh/trusted-user-ca-keys.pem

Update the sshd_config on both SSH and Bastion host:

$ sudo vi /etc/ssh/sshd_config

# ...
TrustedUserCAKeys /etc/ssh/trusted-user-ca-keys.pem

Restart sshd

$ sudo systemctl restart sshd

Do this on the vault server:

create a sshkey:

$ ssh-keygen -t rsa -C "ubuntu"

Ask Vault to sign the public key:

$ vault login
$ vault write ssh-client-signer/sign/my-role public_key=@$HOME/.ssh/id_rsa.pub

Save the signed key to disk:

$ vault write -field=signed_key ssh-client-signer/sign/my-role public_key=@$HOME/.ssh/id_rsa.pub > signed-cert.pub

Now ssh to the client host:

$ ssh -i signed-cert.pub -i ~/.ssh/id_rsa [email protected]

Now that we can connect to the host, we want to connnect through the bastion

Add this to vault server ~vault/.ssh/ssh_config

Host bastion
  Hostname <BASTION_HOST>
  IdentityFile ~/.ssh/id_rsa
  CertificateFile ~/.ssh/signed-cert.pub
  User ubuntu
Host <SSH_HOST>
  IdentityFile ~/.ssh/id_rsa
  ProxyCommand ssh -F uname bastion nc %h %p
  User ubuntu

Now let's try to connect:

$ ssh -i signed-cert.pub -i ~/.ssh/id_rsa ubuntu@<YOUR_AWS_HOST>

Clean up...

$ terraform destroy -force
$ rm -rf .terraform terraform.tfstate*

vault-aws-demoserver's People

Contributors

stoffee avatar

Watchers

 avatar  avatar

Forkers

jdizz arthofer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.