diff --git a/changelog/13469.txt b/changelog/13469.txt new file mode 100644 index 000000000..97cb471a2 --- /dev/null +++ b/changelog/13469.txt @@ -0,0 +1,3 @@ +```release-note:bug +secrets/database/mssql: Accept a boolean for `contained_db`, rather than just a string. +``` diff --git a/plugins/database/mssql/mssql.go b/plugins/database/mssql/mssql.go index 38ae7b4a8..094fa7dbb 100644 --- a/plugins/database/mssql/mssql.go +++ b/plugins/database/mssql/mssql.go @@ -5,13 +5,14 @@ import ( "database/sql" "errors" "fmt" - "strconv" "strings" _ "github.com/denisenkom/go-mssqldb" - multierror "github.com/hashicorp/go-multierror" + "github.com/hashicorp/go-multierror" + "github.com/hashicorp/go-secure-stdlib/parseutil" "github.com/hashicorp/go-secure-stdlib/strutil" - dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" + + "github.com/hashicorp/vault/sdk/database/dbplugin/v5" "github.com/hashicorp/vault/sdk/database/helper/connutil" "github.com/hashicorp/vault/sdk/database/helper/dbutil" "github.com/hashicorp/vault/sdk/helper/dbtxn" @@ -98,20 +99,14 @@ func (m *MSSQL) Initialize(ctx context.Context, req dbplugin.InitializeRequest) return dbplugin.InitializeResponse{}, fmt.Errorf("invalid username template - did you reference a field that isn't available? : %w", err) } - containedDB := false - containedDBRaw, err := strutil.GetString(req.Config, "contained_db") - if err != nil { - return dbplugin.InitializeResponse{}, fmt.Errorf("failed to retrieve contained_db: %w", err) - } - if containedDBRaw != "" { - containedDB, err = strconv.ParseBool(containedDBRaw) + if v, ok := req.Config["contained_db"]; ok { + containedDB, err := parseutil.ParseBool(v) if err != nil { - return dbplugin.InitializeResponse{}, fmt.Errorf("parsing error: incorrect boolean operator provided for contained_db: %w", err) + return dbplugin.InitializeResponse{}, fmt.Errorf(`invalid value for "contained_db": %w`, err) } + m.containedDB = containedDB } - m.containedDB = containedDB - resp := dbplugin.InitializeResponse{ Config: newConf, } diff --git a/plugins/database/mssql/mssql_test.go b/plugins/database/mssql/mssql_test.go index 5f8c2964c..42f15ca19 100644 --- a/plugins/database/mssql/mssql_test.go +++ b/plugins/database/mssql/mssql_test.go @@ -11,7 +11,7 @@ import ( "time" mssqlhelper "github.com/hashicorp/vault/helper/testhelpers/mssql" - dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" + "github.com/hashicorp/vault/sdk/database/dbplugin/v5" dbtesting "github.com/hashicorp/vault/sdk/database/dbplugin/v5/testing" "github.com/hashicorp/vault/sdk/helper/dbtxn" ) @@ -43,6 +43,15 @@ func TestInitialize(t *testing.T) { }, }, "contained_db set": { + dbplugin.InitializeRequest{ + Config: map[string]interface{}{ + "connection_url": connURL, + "contained_db": true, + }, + VerifyConnection: true, + }, + }, + "contained_db set string": { dbplugin.InitializeRequest{ Config: map[string]interface{}{ "connection_url": connURL,