|
| 1 | +# Hashicorp Vault |
| 2 | + |
| 3 | +## Example setup |
| 4 | + |
| 5 | +This configuration is an example, which shows how you can connect OpenID Connect with Hashicorp Vault. |
| 6 | + |
| 7 | +Create `vault.json` with the following content: |
| 8 | + |
| 9 | +```json |
| 10 | +{ |
| 11 | + "backend":{ |
| 12 | + "file":{ |
| 13 | + "path":"/vault/file" |
| 14 | + } |
| 15 | + }, |
| 16 | + "listener":{ |
| 17 | + "tcp":{ |
| 18 | + "address":"0.0.0.0:8200", |
| 19 | + "tls_disable":1 |
| 20 | + } |
| 21 | + }, |
| 22 | + "default_lease_ttl":"168h", |
| 23 | + "max_lease_ttl":"168h", |
| 24 | + "ui":true, |
| 25 | + "log_level":"Debug" |
| 26 | +} |
| 27 | +``` |
| 28 | + |
| 29 | +Create `docker-compose.yaml` with the following content: |
| 30 | + |
| 31 | +```yaml |
| 32 | +services: |
| 33 | + vault: |
| 34 | + image: vault:latest |
| 35 | + container_name: vault |
| 36 | + environment: |
| 37 | + VAULT_ADDR: http://127.0.0.1:8200 |
| 38 | + ports: |
| 39 | + - "8200:8200" |
| 40 | + volumes: |
| 41 | + - ./volumes/vault:/vault/file:rw |
| 42 | + - ./vault.json:/vault/config/vault.json:rw |
| 43 | + cap_add: |
| 44 | + - IPC_LOCK |
| 45 | + entrypoint: vault server -config=/vault/config/vault.json -dev |
| 46 | +``` |
| 47 | +
|
| 48 | +Run it using `docker-compose up` command. |
| 49 | + |
| 50 | +Create root token using `docker exec -it vault vault operator init -n 1 -t 1`, write down the root token and unseal key. |
| 51 | + |
| 52 | +## Defguard configuration |
| 53 | + |
| 54 | +1. Go to **OpenID Apps** and click **Add new** button. |
| 55 | +2. Use Scopes: `openid email profile` |
| 56 | +3. Use `http://127.0.0.1:8200/ui/vault/auth/oidc/oidc/callback` as **Redirect URI** |
| 57 | +4. Copy and save **Client ID** and **Client secret**, we will need them later. |
| 58 | + |
| 59 | +## Vault configuration |
| 60 | + |
| 61 | + |
| 62 | +1. Unseal vault by accessing `http://127.0.0.1:8200/ui` and using unseal key. |
| 63 | +2. Login into Vault using method `TOKEN` and using root token. |
| 64 | +3. Navigate to **Access -> Auth Methods** and click **Enable new method** button. |
| 65 | +4. Enable **OIDC** method. |
| 66 | +5. Use values below: |
| 67 | +`OIDC discovery URL: https://defguard.company.net/` |
| 68 | +`OIDC client ID: <YOUR_CLIENT_ID>` |
| 69 | +`OIDC secret ID: <YOUR_CLIENT_SECRET>` |
| 70 | + |
| 71 | +## Creating role in vault |
| 72 | +1. Login into vault CLI using root token: `docker exec -it vault vault login <ROOT_TOKEN>` |
| 73 | +2. To create role `reader` use command below: |
| 74 | +```bash |
| 75 | +docker exec -it vault vault write auth/oidc/role/reader \ |
| 76 | + bound_audiences="<YOUR_CLIENT_ID>" \ |
| 77 | + allowed_redirect_uris="http://127.0.0.1:8200/ui/vault/auth/oidc/oidc/callback" \ |
| 78 | + user_claim="sub" \ |
| 79 | + token_policies="default" |
| 80 | +``` |
| 81 | + |
| 82 | +Now you can login into vault using Defguard. Use `OIDC` as login method and role `reader`. Please note this role will only allow you to login, to add permissions you need to create policy and assign it to role. |
0 commit comments