Skip to content

Commit

Permalink
Sanitize private_key from returned db plugin config (#10416)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhjp authored Nov 19, 2020
1 parent 8d01681 commit c843aa6
Show file tree
Hide file tree
Showing 2 changed files with 11 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

0 comments on commit c843aa6

Please sign in to comment.