Sanitize private_key from returned db plugin config (#10416)

This commit is contained in:
Tom Proctor
2020-11-19 10:58:55 +00:00
committed by GitHub
parent 8d01681a95
commit c843aa62b5
2 changed files with 11 additions and 1 deletions

View File

@@ -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,
@@ -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

View File

@@ -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(),