Skip to content

Commit

Permalink
Backport 1.6.1: sanitize private key (#10474)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhjp authored Dec 2, 2020
1 parent 4165786 commit 804debb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion builtin/logical/database/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ func TestBackend_connectionCrud(t *testing.T) {
"allowed_roles": []string{"plugin-role-test"},
"username": "postgres",
"password": "secret",
"private_key": "PRIVATE_KEY",
}
req = &logical.Request{
Operation: logical.UpdateOperation,
Expand All @@ -669,9 +670,17 @@ func TestBackend_connectionCrud(t *testing.T) {
if err != nil || (resp != nil && resp.IsError()) {
t.Fatalf("err:%s resp:%#v\n", err, resp)
}
if strings.Contains(resp.Data["connection_details"].(map[string]interface{})["connection_url"].(string), "secret") {
returnedConnectionDetails := resp.Data["connection_details"].(map[string]interface{})
if strings.Contains(returnedConnectionDetails["connection_url"].(string), "secret") {
t.Fatal("password should not be found in the connection url")
}
// Covered by the filled out `expected` value below, but be explicit about this requirement.
if _, exists := returnedConnectionDetails["password"]; exists {
t.Fatal("password should NOT be found in the returned config")
}
if _, exists := returnedConnectionDetails["private_key"]; exists {
t.Fatal("private_key should NOT be found in the returned config")
}

// Replace connection url with templated version
req.Operation = logical.UpdateOperation
Expand Down
1 change: 1 addition & 0 deletions builtin/logical/database/path_config_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (b *databaseBackend) connectionReadHandler() framework.OperationFunc {
}

delete(config.ConnectionDetails, "password")
delete(config.ConnectionDetails, "private_key")

return &logical.Response{
Data: structs.New(config).Map(),
Expand Down
3 changes: 3 additions & 0 deletions changelog/10416.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
secrets/database: Sanitize `private_key` field when reading database plugin config
```
3 changes: 3 additions & 0 deletions changelog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# changelog

This folder holds changelog updates from commit 3bc7d15 onwards. See [hashicorp/go-changelog](https://github.com/hashicorp/go-changelog) for full documentation on the supported entries.

0 comments on commit 804debb

Please sign in to comment.