vault/sdk/database/helper/connutil/cloudsql.go
Vault Automation a23dc5c0e0
[VAULT-43618] sdk: migrate from github.com/docker/docker to github.com/moby/moby
Resolve GHSA-x744-4wpc-v9h2 and GHSA-pxq6-2prw-chj9 in `vault` by replacing
`github.com/docker/docker` with `github.com/moby/moby/client` @ `v0.3.0` and
`github.com/moby/moby/api` @ `v1.54.0`. This is necessary as `docker/docker`
 is no longer maintained and the fixes are not available in it.

Resolve GO-2026-4518, GHSA-x6gf-mpr2-68h6 and GHSA-jqcq-xjh3-6g23 by
upgrading to github.com/jackc/pgx/v5. This is necessary as v4 is not
longer maitained.

Signed-off-by: Ryan Cragun <me@ryan.ec>
Co-authored-by: Ryan Cragun <me@ryan.ec>
2026-04-02 13:58:05 -04:00

64 lines
1.7 KiB
Go

// Copyright IBM Corp. 2016, 2025
// SPDX-License-Identifier: MPL-2.0
package connutil
import (
"fmt"
"cloud.google.com/go/cloudsqlconn"
"cloud.google.com/go/cloudsqlconn/postgres/pgxv5"
)
func (c *SQLConnectionProducer) getCloudSQLDriverType() (string, error) {
var driverType string
// using switch case for future extensibility
switch c.Type {
case dbTypePostgres:
driverType = cloudSQLPostgres
default:
return "", fmt.Errorf("unsupported DB type for cloud IAM: %s", c.Type)
}
return driverType, nil
}
func (c *SQLConnectionProducer) registerDrivers(driverName string, credentials string, usePrivateIP bool, usePSC bool) (func() error, error) {
typ, err := c.getCloudSQLDriverType()
if err != nil {
return nil, err
}
opts, err := GetCloudSQLAuthOptions(credentials, usePrivateIP, usePSC)
if err != nil {
return nil, err
}
// using switch case for future extensibility
switch typ {
case cloudSQLPostgres:
return pgxv5.RegisterDriver(driverName, opts...)
}
return nil, fmt.Errorf("unrecognized cloudsql type encountered: %s", typ)
}
// GetCloudSQLAuthOptions takes a credentials JSON and returns
// a set of GCP CloudSQL options - always WithIAMAUthN, and then the appropriate file/JSON option.
func GetCloudSQLAuthOptions(credentials string, usePrivateIP bool, usePSC bool) ([]cloudsqlconn.Option, error) {
opts := []cloudsqlconn.Option{cloudsqlconn.WithIAMAuthN()}
if credentials != "" {
opts = append(opts, cloudsqlconn.WithCredentialsJSON([]byte(credentials)))
}
if usePrivateIP {
opts = append(opts, cloudsqlconn.WithDefaultDialOptions(cloudsqlconn.WithPrivateIP()))
}
if usePSC {
opts = append(opts, cloudsqlconn.WithDefaultDialOptions(cloudsqlconn.WithPSC()))
}
return opts, nil
}