├── .gitignore ├── README.md └── terraform ├── cloud-config.yml ├── terraform.tf ├── terraform.tfvars.example └── variables.tf /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.tfvars 3 | *.tfstate* 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vault on CoreOS + Docker with Terraform (on Digital Ocean) 2 | 3 | This will deploy [Vault](https://vaultproject.io) on [CoreOS](http://coreos.com/) using [my Vault Docker container](https://registry.hub.docker.com/u/sjourdan/vault/) with [Terraform](http://terraform.io/). 4 | 5 | A first version of this will use [demo.consul.io](https://demo.consul.io) as a backend, but using [docker-vault](https://github.com/sjourdan/docker-vault) it can easily be extended to a private [Consul](https://consul.io/) backend. 6 | 7 | Terraform will start/manage the CoreOS infrastructure, cloud-init will give enough information to start/join the cluster and deploy required files. Then fleet will manage the containers. 8 | 9 | You **will** need to generate a [new etcd discovery token](https://discovery.etcd.io/new) and enter it in the `terraform.tf` file for the demo to work. 10 | 11 | The file `cloud-config.yml` contains: 12 | * The Vault configuration file (`/home/core/config/demo.hcl`) 13 | * The two `fleet` unit service files (`/home/core/services/vault@.service` and `/home/core/services/vault-discovery@.service`) 14 | * enough to start `etcd` and `fleet` 15 | 16 | ## Deploy the base infrastructure 17 | 18 | Fill in the blanks in the configuration file: 19 | 20 | $ cp terraform.tfvars.example terraform.tfvars 21 | $ terraform apply 22 | 23 | ## CoreOS 24 | 25 | Login and check `fleetctl` sees all the cluster machines: 26 | 27 | fleetctl list-machines 28 | MACHINE IP METADATA 29 | 6147c03d... 10.133.169.81 - 30 | [...] 31 | 32 | Units are empty: 33 | 34 | fleetctl list-units 35 | UNIT MACHINE ACTIVE SUB 36 | 37 | The unit files are empty: 38 | 39 | fleetctl list-unit-files 40 | UNIT HASH DSTATE STATE TARGET 41 | 42 | ### Vault Service (Unit) Files 43 | 44 | Submit the service files sent by cloud-config under `services/`: 45 | 46 | fleetctl submit services/vault\@.service services/vault-discovery\@.service 47 | 48 | Now we have unit files: 49 | 50 | fleetctl list-unit-files 51 | UNIT HASH DSTATE STATE TARGET 52 | vault-discovery@.service d15726b inactive inactive - 53 | vault@.service de5c96e inactive inactive - 54 | 55 | We want to start a Vault service on TCP/8200: 56 | 57 | fleetctl load vault@8200.service 58 | Unit vault@8200.service loaded on 6147c03d.../10.133.169.81 59 | 60 | fleetctl load vault-discovery@8200.service 61 | Unit vault-discovery@8200.service loaded on 6147c03d.../10.133.169.81 62 | 63 | ### Start the Vault Service 64 | 65 | Transfer the Vault configuration file from `config/` over to `/home/core/config` 66 | 67 | fleetctl start vault@8200.service 68 | Unit vault@8200.service launched on 6147c03d.../10.133.169.81 69 | 70 | Check the status: 71 | 72 |
73 | fleetctl status vault@8200.service 74 | ● vault@8200.service - Vault Service 75 | Loaded: loaded (/run/fleet/units/vault@8200.service; linked-runtime; vendor preset: disabled) 76 | Active: active (running) since Tue 2015-05-05 21:04:15 UTC; 2s ago 77 | May 05 21:04:15 core-1 docker[1628]: fdaa9c66787e: Download complete 78 | May 05 21:04:15 core-1 docker[1628]: fdaa9c66787e: Download complete 79 | May 05 21:04:15 core-1 docker[1628]: Status: Image is up to date for sjourdan/vault:latest 80 | May 05 21:04:15 core-1 systemd[1]: Started Vault Service. 81 | May 05 21:04:15 core-1 docker[1637]: ==> Vault server configuration: 82 | May 05 21:04:15 core-1 docker[1637]: Log Level: info 83 | May 05 21:04:15 core-1 docker[1637]: Mlock: supported: true, enabled: true 84 | May 05 21:04:15 core-1 docker[1637]: Backend: consul (HA available) 85 | May 05 21:04:15 core-1 docker[1637]: Listener 1: tcp (addr: "0.0.0.0:8200", tls: "disabled") 86 | May 05 21:04:15 core-1 docker[1637]: ==> Vault server started! Log data will stream in below: 87 |88 | 89 | Get from etcd the public IP and port to use: 90 | 91 | etcdctl get /announce/services/vault8200 92 | 188.166.87.74:8200 93 | 94 | ### Use the Vault Service 95 | 96 | On your workstation you can now use Vault: 97 | 98 | export VAULT_ADDR='http://188.166.87.74:8200' 99 | vault init 100 | vault --help 101 | 102 | ### Vault Container Logs 103 | 104 | Tail the 100 last line of container's logs: 105 | 106 | fleetctl journal -lines=100 -f vault@8200.service 107 | -- Logs begin at Tue 2015-05-05 17:13:23 UTC, end at Tue 2015-05-05 17:19:14 UTC. -- 108 | [...] 109 | 110 | If needed, attach a terminal to debug: 111 | 112 | docker exec -t -i