mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-11-03 20:17:59 +00:00 
			
		
		
		
	Sanitize private_key from returned db plugin config (#10416)
This commit is contained in:
		@@ -649,6 +649,7 @@ func TestBackend_connectionCrud(t *testing.T) {
 | 
				
			|||||||
		"allowed_roles":  []string{"plugin-role-test"},
 | 
							"allowed_roles":  []string{"plugin-role-test"},
 | 
				
			||||||
		"username":       "postgres",
 | 
							"username":       "postgres",
 | 
				
			||||||
		"password":       "secret",
 | 
							"password":       "secret",
 | 
				
			||||||
 | 
							"private_key":    "PRIVATE_KEY",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	req = &logical.Request{
 | 
						req = &logical.Request{
 | 
				
			||||||
		Operation: logical.UpdateOperation,
 | 
							Operation: logical.UpdateOperation,
 | 
				
			||||||
@@ -669,9 +670,17 @@ func TestBackend_connectionCrud(t *testing.T) {
 | 
				
			|||||||
	if err != nil || (resp != nil && resp.IsError()) {
 | 
						if err != nil || (resp != nil && resp.IsError()) {
 | 
				
			||||||
		t.Fatalf("err:%s resp:%#v\n", err, resp)
 | 
							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")
 | 
							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
 | 
						// Replace connection url with templated version
 | 
				
			||||||
	req.Operation = logical.UpdateOperation
 | 
						req.Operation = logical.UpdateOperation
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -207,6 +207,7 @@ func (b *databaseBackend) connectionReadHandler() framework.OperationFunc {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		delete(config.ConnectionDetails, "password")
 | 
							delete(config.ConnectionDetails, "password")
 | 
				
			||||||
 | 
							delete(config.ConnectionDetails, "private_key")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return &logical.Response{
 | 
							return &logical.Response{
 | 
				
			||||||
			Data: structs.New(config).Map(),
 | 
								Data: structs.New(config).Map(),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user