Skip to content

Commit 5af1995

Browse files
authored
Merge pull request #17 from couchbasecloud/bugfix/fix-issue-with-return-code
fix the issue that fails to rotate the API credential
2 parents f0ecb8a + ccb30fa commit 5af1995

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

docker.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The multi-stage docker container first builds the plugin. It also generates the
3535
*/vault/vault-plugin-database-couchbasecapella.sha256*
3636

3737
```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"
38+
docker exec -it "couchbase_vault" /bin/ash -c "SHA256=\$(cat /vault/couchbasecapella-database-plugin.sha256) && vault login password && vault write sys/plugins/catalog/database/couchbasecapella-database-plugin sha256=\$SHA256 command=couchbasecapella-database-plugin"
3939
```
4040

4141
You can check if the plugin was registered by listing the installed plugins with the following command
@@ -57,10 +57,10 @@ docker exec -it "couchbase_vault" /bin/ash -c "vault login password && vault wri
5757
### Create database config
5858

5959
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.
60+
Make sure to replace the variables. Please keep in mind the Capella secret you download is base64 encoded. You need to decode it and grab the username and password from that secret. They are separated by :
6161

6262
```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="*"'
63+
docker exec -it "couchbase_vault" /bin/ash -c 'vault login password && vault write database/config/couchbasecapella-database-plugin plugin_name="couchbasecapella-database-plugin" 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="*"'
6464
```
6565
> Please note: it uses the password policy we registered before
6666
@@ -69,12 +69,12 @@ docker exec -it "couchbase_vault" /bin/ash -c 'vault login password && vault wri
6969
The plugin supports rotating the root credentials that was used to initialize the database config
7070

7171
```bash
72-
docker exec -it "couchbase_vault" /bin/ash -c "vault login password && vault write -force database/rotate-root/vault-plugin-database-couchbasecapella"
72+
docker exec -it "couchbase_vault" /bin/ash -c "vault login password && vault write -force database/rotate-root/couchbasecapella-database-plugin"
7373
```
7474
### Create a dynamic role
7575

7676
```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"'
77+
docker exec -it "couchbase_vault" /bin/ash -c 'vault login password && vault write database/roles/dynamicrole1 db_name="couchbasecapella-database-plugin" 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"'
7878
```
7979

8080
> Please note: this example assumes you have a bucket called: *vault-bucket-1* and a scope called: *vault-bucket-1-scope-1*

httputils.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func CreateCapellaDbCredUser(baseUrl string, cloudAPIclustersEndPoint string, ac
302302

303303
ep := c.baseURL + cloudAPIclustersEndPoint + "/users"
304304
resp, err := c.sendRequest(http.MethodPost, ep, string(data))
305-
if resp != nil && resp.StatusCode != 201 {
305+
if resp != nil && resp.StatusCode != http.StatusCreated {
306306
defer resp.Body.Close()
307307
// obfuscate password in the log
308308
obfData := fmt.Sprintf("{\"name\":\"%s\", \"password\":\"[password]\", \"access\":%v}", username, string(adata))
@@ -311,8 +311,8 @@ func CreateCapellaDbCredUser(baseUrl string, cloudAPIclustersEndPoint string, ac
311311
return fmt.Errorf("failed during capella user creation, reading response error = %v, ep = %s, user = %v, payload=%v,client=%v",
312312
err1, ep, username, obfData, c)
313313
}
314-
return fmt.Errorf("failed during capella user creation, response = %s, ep = %s, user = %v, payload = %v, access=%s, secret=%s",
315-
string(b), ep, username, obfData, accessKey, secretKey)
314+
return fmt.Errorf("failed during capella user creation, response = %s, ep = %s, user = %v, payload = %v",
315+
string(b), ep, username, obfData)
316316
}
317317
if err != nil {
318318
return err
@@ -345,9 +345,9 @@ func UpdateCapellaDbCredUser(baseUrl string, cloudAPIclustersEndPoint string, ac
345345
apiPathSlices := strings.Split(cloudAPIclustersEndPoint, "/")
346346
ep := c.baseURL + "/organizations/" + apiPathSlices[2] + "/apikeys/" + username + "/rotate"
347347
data := fmt.Sprintf("{\"secret\":\"%s\"}", password)
348-
c.logger.Info(fmt.Sprintf("%s %s %s", http.MethodPost, ep, data))
348+
c.logger.Info(fmt.Sprintf("%s %s", http.MethodPost, ep))
349349
resp, err := c.sendRequest(http.MethodPost, ep, data)
350-
if resp != nil && resp.StatusCode != 201 {
350+
if resp != nil && resp.StatusCode != http.StatusOK {
351351
return "", fmt.Errorf("failed during capella secret key rotate, response = %v, ep = %s",
352352
resp, ep)
353353
}
@@ -381,7 +381,7 @@ func DeleteCapellaDbCredUser(baseUrl string, cloudAPIclustersEndPoint string, ac
381381
}
382382
ep := c.baseURL + cloudAPIclustersEndPoint + "/users/" + userId
383383
resp, err := c.sendRequest(http.MethodDelete, ep, "")
384-
if resp != nil && resp.StatusCode != 204 {
384+
if resp != nil && resp.StatusCode != http.StatusNoContent {
385385
return fmt.Errorf("failed during capella user deletion, response = %v, ep = %s",
386386
resp, ep)
387387
}

0 commit comments

Comments
 (0)