|
1 | 1 | # Vault Backend |
2 | 2 |
|
3 | | -[](https://github.com/pre-commit/pre-commit) |
4 | | - |
5 | | - |
6 | | -[](https://goreportcard.com/report/github.com/gherynos/vault-backend) |
7 | | - |
8 | | -A Terraform [HTTP backend](https://www.terraform.io/docs/backends/types/http.html) that stores the state in a [Vault secret](https://www.vaultproject.io/docs/secrets/kv/kv-v2). |
9 | | - |
10 | | -The server supports locking and leverages the versioning capabilities of Vault by creating a new secret version when creating/updating the state. |
11 | | - |
12 | | -## Terraform config |
13 | | - |
14 | | -The server authenticates to Vault using [AppRole](https://www.vaultproject.io/docs/auth/approle), with `role_id` and `secret_id` passed respectively as the `username` and `password` in the configuration: |
15 | | - |
16 | | -```terraform |
17 | | -terraform { |
18 | | - backend "http" { |
19 | | - address = "http://localhost:8080/state/<STATE_NAME>" |
20 | | - lock_address = "http://localhost:8080/state/<STATE_NAME>" |
21 | | - unlock_address = "http://localhost:8080/state/<STATE_NAME>" |
22 | | -
|
23 | | - username = "<VAULT_ROLE_ID>" |
24 | | - password = "<VAULT_SECRET_ID>" |
25 | | - } |
26 | | -} |
27 | | -``` |
28 | | - |
29 | | -or directly with a [token](https://www.vaultproject.io/docs/auth/token): |
30 | | - |
31 | | -```terraform |
32 | | -terraform { |
33 | | - backend "http" { |
34 | | - address = "http://localhost:8080/state/<STATE_NAME>" |
35 | | - lock_address = "http://localhost:8080/state/<STATE_NAME>" |
36 | | - unlock_address = "http://localhost:8080/state/<STATE_NAME>" |
37 | | -
|
38 | | - username = "TOKEN" |
39 | | - password = "<TOKEN_VALUE>" |
40 | | - } |
41 | | -} |
42 | | -``` |
43 | | - |
44 | | -where `<STATE_NAME>` is an arbitrary value used to distinguish the backends. |
45 | | - |
46 | | -With the above configuration, Terraform connects to a vault-backend server running locally on port 8080 when loading/storing/locking the state, and the server manages the following secrets in Vault: |
47 | | - |
48 | | -- `/<VAULT_STORE>/<VAULT_PREFIX>/<STATE_NAME>` |
49 | | -- `/<VAULT_STORE>/<VAULT_PREFIX>/<STATE_NAME>-lock` |
50 | | - |
51 | | -the latter gets created when a lock is acquired and deleted when released. |
52 | | - |
53 | | -## Vault Backend config |
54 | | - |
55 | | -The following environment variables can be set to change the configuration: |
56 | | - |
57 | | -- `VAULT_URL` (default `http://localhost:8200`) the URL of the Vault server |
58 | | -- `VAULT_PREFIX` (default `vbk`) the prefix used when storing the secrets |
59 | | -- `VAULT_STORE` (default `secret`) the store path used when storing secrets |
60 | | -- `LISTEN_ADDRESS` (default `0.0.0.0:8080`) the listening address and port |
61 | | -- `TLS_CRT` and `TLS_KEY` to set the path of the TLS certificate and key files |
62 | | -- `DEBUG` to enable verbose logging |
63 | | - |
64 | | -## Vault policy |
65 | | - |
66 | | -The policy associated to the AppRole used by the server needs to grant access to the secrets. |
67 | | - |
68 | | -I.e., for a `<STATE_NAME>` set as `cloud-services` and the default `VAULT_PREFIX` and `VAULT_STORE`: |
69 | | - |
70 | | -```vault |
71 | | -path "secret/data/vbk/cloud-services" |
72 | | -{ |
73 | | - capabilities = ["create", "read", "update"] |
74 | | -} |
75 | | -
|
76 | | -path "secret/data/vbk/cloud-services-lock" |
77 | | -{ |
78 | | - capabilities = ["create", "read", "update"] |
79 | | -} |
80 | | -
|
81 | | -path "secret/metadata/vbk/cloud-services-lock" |
82 | | -{ |
83 | | - capabilities = ["delete"] |
84 | | -} |
85 | | -``` |
86 | | - |
87 | | -## Docker |
88 | | - |
89 | | -The Docker images for Vault Backend are available here: <https://hub.docker.com/r/gherynos/vault-backend> |
90 | | - |
91 | | -Example execution command: |
92 | | - |
93 | | -```shell |
94 | | -docker run -d -p 8080:8080 -e VAULT_URL=https://some.vault.address:8200 gherynos/vault-backend |
95 | | -``` |
96 | | - |
97 | | -## Author |
98 | | - |
99 | | -> GitHub [@gherynos](https://github.com/gherynos) |
100 | | -
|
101 | | -## License |
102 | | - |
103 | | -Vault Backend is licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). |
| 3 | +Repository moved to Codeberg: <https://codeberg.org/gherynos/vault-backend> |
0 commit comments