mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 11:08:10 +00:00
Remove sensitive fields when reading config data (#4216)
* Remove sensitive fields when reading config data * Do not use structs; build and return map explicitly * Revert tag in postgresql * Fix tests
This commit is contained in:
committed by
GitHub
parent
08770c6366
commit
938b748914
@@ -116,7 +116,6 @@ func (b *backend) pathConfigClientRead(ctx context.Context, req *logical.Request
|
|||||||
return &logical.Response{
|
return &logical.Response{
|
||||||
Data: map[string]interface{}{
|
Data: map[string]interface{}{
|
||||||
"access_key": clientConfig.AccessKey,
|
"access_key": clientConfig.AccessKey,
|
||||||
"secret_key": clientConfig.SecretKey,
|
|
||||||
"endpoint": clientConfig.Endpoint,
|
"endpoint": clientConfig.Endpoint,
|
||||||
"iam_endpoint": clientConfig.IAMEndpoint,
|
"iam_endpoint": clientConfig.IAMEndpoint,
|
||||||
"sts_endpoint": clientConfig.STSEndpoint,
|
"sts_endpoint": clientConfig.STSEndpoint,
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/fatih/structs"
|
|
||||||
"github.com/go-ldap/ldap"
|
"github.com/go-ldap/ldap"
|
||||||
multierror "github.com/hashicorp/go-multierror"
|
multierror "github.com/hashicorp/go-multierror"
|
||||||
"github.com/hashicorp/vault/helper/tlsutil"
|
"github.com/hashicorp/vault/helper/tlsutil"
|
||||||
@@ -174,9 +173,24 @@ func (b *backend) pathConfigRead(ctx context.Context, req *logical.Request, d *f
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp := &logical.Response{
|
resp := &logical.Response{
|
||||||
Data: structs.New(cfg).Map(),
|
Data: map[string]interface{}{
|
||||||
|
"url": cfg.Url,
|
||||||
|
"userdn": cfg.UserDN,
|
||||||
|
"groupdn": cfg.GroupDN,
|
||||||
|
"groupfilter": cfg.GroupFilter,
|
||||||
|
"groupattr": cfg.GroupAttr,
|
||||||
|
"upndomain": cfg.UPNDomain,
|
||||||
|
"userattr": cfg.UserAttr,
|
||||||
|
"certificate": cfg.Certificate,
|
||||||
|
"insecure_tls": cfg.InsecureTLS,
|
||||||
|
"starttls": cfg.StartTLS,
|
||||||
|
"binddn": cfg.BindDN,
|
||||||
|
"deny_null_bind": cfg.DenyNullBind,
|
||||||
|
"discoverdn": cfg.DiscoverDN,
|
||||||
|
"tls_min_version": cfg.TLSMinVersion,
|
||||||
|
"tls_max_version": cfg.TLSMaxVersion,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
resp.AddWarning("Read access to this endpoint should be controlled via ACLs as it will return the configuration information as-is, including any passwords.")
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/structs"
|
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
"github.com/hashicorp/vault/logical/framework"
|
"github.com/hashicorp/vault/logical/framework"
|
||||||
)
|
)
|
||||||
@@ -104,9 +103,15 @@ func (b *backend) pathConfigRead(ctx context.Context, req *logical.Request, d *f
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp := &logical.Response{
|
resp := &logical.Response{
|
||||||
Data: structs.New(cfg).Map(),
|
Data: map[string]interface{}{
|
||||||
|
"host": cfg.Host,
|
||||||
|
"port": cfg.Port,
|
||||||
|
"unregistered_user_policies": cfg.UnregisteredUserPolicies,
|
||||||
|
"dial_timeout": cfg.DialTimeout,
|
||||||
|
"read_timeout": cfg.ReadTimeout,
|
||||||
|
"nas_port": cfg.NasPort,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
resp.AddWarning("Read access to this endpoint should be controlled via ACLs as it will return the configuration information as-is, including any secrets.")
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/fatih/structs"
|
|
||||||
"github.com/hashicorp/vault/helper/certutil"
|
"github.com/hashicorp/vault/helper/certutil"
|
||||||
"github.com/hashicorp/vault/helper/tlsutil"
|
"github.com/hashicorp/vault/helper/tlsutil"
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
@@ -100,14 +99,20 @@ func (b *backend) pathConnectionRead(ctx context.Context, req *logical.Request,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Password = "**********"
|
resp := &logical.Response{
|
||||||
if len(config.PrivateKey) > 0 {
|
Data: map[string]interface{}{
|
||||||
config.PrivateKey = "**********"
|
"hosts": config.Hosts,
|
||||||
|
"username": config.Username,
|
||||||
|
"tls": config.TLS,
|
||||||
|
"insecure_tls": config.InsecureTLS,
|
||||||
|
"certificate": config.Certificate,
|
||||||
|
"issuing_ca": config.IssuingCA,
|
||||||
|
"protocol_version": config.ProtocolVersion,
|
||||||
|
"connect_timeout": config.ConnectTimeout,
|
||||||
|
"tls_min_version": config.TLSMinVersion,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
return resp, nil
|
||||||
return &logical.Response{
|
|
||||||
Data: structs.New(config).Map(),
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *backend) pathConnectionWrite(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
func (b *backend) pathConnectionWrite(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||||
|
|||||||
@@ -209,10 +209,8 @@ func TestBackend_config_connection(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expected := map[string]interface{}{
|
expected := map[string]interface{}{
|
||||||
"plugin_name": "postgresql-database-plugin",
|
"plugin_name": "postgresql-database-plugin",
|
||||||
"connection_details": map[string]interface{}{
|
"connection_details": map[string]interface{}{},
|
||||||
"connection_url": "sample_connection_url",
|
|
||||||
},
|
|
||||||
"allowed_roles": []string{"*"},
|
"allowed_roles": []string{"*"},
|
||||||
"root_credentials_rotate_statements": []string{},
|
"root_credentials_rotate_statements": []string{},
|
||||||
}
|
}
|
||||||
@@ -519,10 +517,8 @@ func TestBackend_connectionCrud(t *testing.T) {
|
|||||||
|
|
||||||
// Read connection
|
// Read connection
|
||||||
expected := map[string]interface{}{
|
expected := map[string]interface{}{
|
||||||
"plugin_name": "postgresql-database-plugin",
|
"plugin_name": "postgresql-database-plugin",
|
||||||
"connection_details": map[string]interface{}{
|
"connection_details": map[string]interface{}{},
|
||||||
"connection_url": connURL,
|
|
||||||
},
|
|
||||||
"allowed_roles": []string{"plugin-role-test"},
|
"allowed_roles": []string{"plugin-role-test"},
|
||||||
"root_credentials_rotate_statements": []string{},
|
"root_credentials_rotate_statements": []string{},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,6 +168,11 @@ func (b *databaseBackend) connectionReadHandler() framework.OperationFunc {
|
|||||||
if err := entry.DecodeJSON(&config); err != nil {
|
if err := entry.DecodeJSON(&config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, ok := config.ConnectionDetails["connection_url"]; ok {
|
||||||
|
delete(config.ConnectionDetails, "connection_url")
|
||||||
|
}
|
||||||
|
|
||||||
return &logical.Response{
|
return &logical.Response{
|
||||||
Data: structs.New(config).Map(),
|
Data: structs.New(config).Map(),
|
||||||
}, nil
|
}, nil
|
||||||
|
|||||||
@@ -102,10 +102,6 @@ func TestBackend_config_connection(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 resp.Data["uri"] != configData["uri"] {
|
|
||||||
t.Fatalf("bad: %#v", resp)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBackend_basic(t *testing.T) {
|
func TestBackend_basic(t *testing.T) {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/fatih/structs"
|
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
"github.com/hashicorp/vault/logical/framework"
|
"github.com/hashicorp/vault/logical/framework"
|
||||||
"gopkg.in/mgo.v2"
|
"gopkg.in/mgo.v2"
|
||||||
@@ -43,13 +42,7 @@ func (b *backend) pathConnectionRead(ctx context.Context, req *logical.Request,
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var config connectionConfig
|
return nil, nil
|
||||||
if err := entry.DecodeJSON(&config); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &logical.Response{
|
|
||||||
Data: structs.New(config).Map(),
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *backend) pathConnectionWrite(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
func (b *backend) pathConnectionWrite(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ func TestBackend_config_connection(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete(configData, "verify_connection")
|
delete(configData, "verify_connection")
|
||||||
|
delete(configData, "connection_string")
|
||||||
if !reflect.DeepEqual(configData, resp.Data) {
|
if !reflect.DeepEqual(configData, resp.Data) {
|
||||||
t.Fatalf("bad: expected:%#v\nactual:%#v\n", configData, resp.Data)
|
t.Fatalf("bad: expected:%#v\nactual:%#v\n", configData, resp.Data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/fatih/structs"
|
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
"github.com/hashicorp/vault/logical/framework"
|
"github.com/hashicorp/vault/logical/framework"
|
||||||
)
|
)
|
||||||
@@ -53,8 +52,11 @@ func (b *backend) pathConnectionRead(ctx context.Context, req *logical.Request,
|
|||||||
if err := entry.DecodeJSON(&config); err != nil {
|
if err := entry.DecodeJSON(&config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &logical.Response{
|
return &logical.Response{
|
||||||
Data: structs.New(config).Map(),
|
Data: map[string]interface{}{
|
||||||
|
"max_open_connections": config.MaxOpenConnections,
|
||||||
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ func TestBackend_config_connection(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configData := map[string]interface{}{
|
configData := map[string]interface{}{
|
||||||
"value": "",
|
|
||||||
"connection_url": "sample_connection_url",
|
"connection_url": "sample_connection_url",
|
||||||
"max_open_connections": 9,
|
"max_open_connections": 9,
|
||||||
"max_idle_connections": 7,
|
"max_idle_connections": 7,
|
||||||
@@ -106,6 +105,7 @@ func TestBackend_config_connection(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete(configData, "verify_connection")
|
delete(configData, "verify_connection")
|
||||||
|
delete(configData, "connection_url")
|
||||||
if !reflect.DeepEqual(configData, resp.Data) {
|
if !reflect.DeepEqual(configData, resp.Data) {
|
||||||
t.Fatalf("bad: expected:%#v\nactual:%#v\n", configData, resp.Data)
|
t.Fatalf("bad: expected:%#v\nactual:%#v\n", configData, resp.Data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/fatih/structs"
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
"github.com/hashicorp/vault/logical/framework"
|
"github.com/hashicorp/vault/logical/framework"
|
||||||
@@ -63,8 +62,12 @@ func (b *backend) pathConnectionRead(ctx context.Context, req *logical.Request,
|
|||||||
if err := entry.DecodeJSON(&config); err != nil {
|
if err := entry.DecodeJSON(&config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &logical.Response{
|
return &logical.Response{
|
||||||
Data: structs.New(config).Map(),
|
Data: map[string]interface{}{
|
||||||
|
"max_open_connections": config.MaxOpenConnections,
|
||||||
|
"max_idle_connections": config.MaxIdleConnections,
|
||||||
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ func TestBackend_config_connection(t *testing.T) {
|
|||||||
|
|
||||||
configData := map[string]interface{}{
|
configData := map[string]interface{}{
|
||||||
"connection_url": "sample_connection_url",
|
"connection_url": "sample_connection_url",
|
||||||
"value": "",
|
|
||||||
"max_open_connections": 9,
|
"max_open_connections": 9,
|
||||||
"max_idle_connections": 7,
|
"max_idle_connections": 7,
|
||||||
"verify_connection": false,
|
"verify_connection": false,
|
||||||
@@ -110,6 +109,7 @@ func TestBackend_config_connection(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete(configData, "verify_connection")
|
delete(configData, "verify_connection")
|
||||||
|
delete(configData, "connection_url")
|
||||||
if !reflect.DeepEqual(configData, resp.Data) {
|
if !reflect.DeepEqual(configData, resp.Data) {
|
||||||
t.Fatalf("bad: expected:%#v\nactual:%#v\n", configData, resp.Data)
|
t.Fatalf("bad: expected:%#v\nactual:%#v\n", configData, resp.Data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/fatih/structs"
|
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
"github.com/hashicorp/vault/logical/framework"
|
"github.com/hashicorp/vault/logical/framework"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
@@ -73,8 +72,12 @@ func (b *backend) pathConnectionRead(ctx context.Context, req *logical.Request,
|
|||||||
if err := entry.DecodeJSON(&config); err != nil {
|
if err := entry.DecodeJSON(&config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &logical.Response{
|
return &logical.Response{
|
||||||
Data: structs.New(config).Map(),
|
Data: map[string]interface{}{
|
||||||
|
"max_open_connections": config.MaxOpenConnections,
|
||||||
|
"max_idle_connections": config.MaxIdleConnections,
|
||||||
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user