|
| 1 | +# vault-plugin-database-couchbasecapella with Docker |
| 2 | + |
| 3 | +Please note this build is not recommended for Production use. It is designed for testing using Docker. |
| 4 | + |
| 5 | +## Build |
| 6 | + |
| 7 | +You can build a test Vault image where this plugin will be copied to the `/vault/plugins` folder |
| 8 | + |
| 9 | +```bash |
| 10 | +docker build -t vault:with-cb-capella-plugin . |
| 11 | +``` |
| 12 | + |
| 13 | +## Setup |
| 14 | + |
| 15 | +The following command will start Vault in development mode with a root token `password`. This can be used to test the plugin |
| 16 | + |
| 17 | +```bash |
| 18 | +docker run --cap-add=IPC_LOCK --name="couchbase_vault" --rm \ |
| 19 | + -e VAULT_DEV_LISTEN_ADDRESS=0.0.0.0:8200 \ |
| 20 | + -e VAULT_ADDR=http://0.0.0.0:8200 \ |
| 21 | + -p 8200:8200 \ |
| 22 | + vault:with-cb-capella-plugin \ |
| 23 | + vault server -dev -dev-root-token-id="password" \ |
| 24 | + -log-level=debug -config=/vault/config/config.json |
| 25 | +``` |
| 26 | + |
| 27 | +### Enable Database secrets |
| 28 | + |
| 29 | +```bash |
| 30 | +docker exec -it "couchbase_vault" /bin/ash -c "vault login password && vault secrets enable database" |
| 31 | +``` |
| 32 | +### Register the plugin |
| 33 | + |
| 34 | +The multi-stage docker container first builds the plugin. It also generates the SHA256 and saves it the following file: |
| 35 | +*/vault/vault-plugin-database-couchbasecapella.sha256* |
| 36 | + |
| 37 | +```bash |
| 38 | +docker exec -it "couchbase_vault" /bin/ash -c "SHA256=\$(cat /vault/vault-plugin-database-couchbasecapella.sha256) && vault login password && vault write sys/plugins/catalog/database/vault-plugin-database-couchbasecapella sha256=\$SHA256 command=vault-plugin-database-couchbasecapella" |
| 39 | +``` |
| 40 | + |
| 41 | +You can check if the plugin was registered by listing the installed plugins with the following command |
| 42 | + |
| 43 | +```bash |
| 44 | +docker exec -it "couchbase_vault" /bin/ash -c "vault login password && vault plugin list" |
| 45 | +``` |
| 46 | + |
| 47 | +### Upload password policy |
| 48 | + |
| 49 | +Couchbase provides a Vault password policy file that can be used with the plugin. The policy can be found at */vault/password_policy.hcl* |
| 50 | + |
| 51 | +```bash |
| 52 | +docker exec -it "couchbase_vault" /bin/ash -c "vault login password && vault write sys/policies/password/couchbasecapella policy=@/vault/password_policy.hcl" |
| 53 | +``` |
| 54 | + |
| 55 | +## Testing |
| 56 | + |
| 57 | +### Create database config |
| 58 | + |
| 59 | +You can use the following command to create a database config that sets up the connection to your Capella cluster. |
| 60 | +Make sure to replace the variables. |
| 61 | + |
| 62 | +```bash |
| 63 | +docker exec -it "couchbase_vault" /bin/ash -c 'vault login password && vault write database/config/vault-plugin-database-couchbasecapella plugin_name="vault-plugin-database-couchbasecapella" cloud_api_base_url="https://cloudapi.cloud.couchbase.com/v4" organization_id="$your_capella_organization_id" project_id="$your_capella_project_id" cluster_id="$your_capella_cluster_id" username="$your_capella_access_key_name" password="$your_capella_access_key_secret" password_policy="couchbasecapella" allowed_roles="*"' |
| 64 | +``` |
| 65 | +> Please note: it uses the password policy we registered before |
| 66 | +
|
| 67 | +### Rotate root credentials |
| 68 | + |
| 69 | +The plugin supports rotating the root credentials that was used to initialize the database config |
| 70 | + |
| 71 | +```bash |
| 72 | +docker exec -it "couchbase_vault" /bin/ash -c "vault login password && vault write -force database/rotate-root/vault-plugin-database-couchbasecapella" |
| 73 | +``` |
| 74 | +### Create a dynamic role |
| 75 | + |
| 76 | +```bash |
| 77 | +docker exec -it "couchbase_vault" /bin/ash -c 'vault login password && vault write database/roles/dynamicrole1 db_name="vault-plugin-database-couchbasecapella" creation_statements='\''{"access": [ { "privileges": [ "data_reader", "data_writer" ], "resources": { "buckets": [ { "name": "vault-bucket-1", "scopes": [ { "name": "vault-bucket-1-scope-1", "collections": [ "*" ] } ] } ] } } ]}'\'' default_ttl="5m" max_ttl="1h"' |
| 78 | +``` |
| 79 | + |
| 80 | +> Please note: this example assumes you have a bucket called: *vault-bucket-1* and a scope called: *vault-bucket-1-scope-1* |
| 81 | +
|
| 82 | +### Create a new credential |
| 83 | + |
| 84 | +Using the dynamic role setup in the earlier step, we can ask Vault to create a new set of database credentials |
| 85 | + |
| 86 | +```bash |
| 87 | +docker exec -it "couchbase_vault" /bin/ash -c 'vault login password && vault read database/creds/dynamicrole1' |
| 88 | +``` |
0 commit comments