Prepare multiplexing support for database plugins (#16995)

* prepare multiplexing support for database plugins
This commit is contained in:
Max Coulombe 2022-09-06 14:00:37 -04:00 committed by GitHub
parent 98fffbe949
commit 10121fed37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 21 additions and 62 deletions

3
changelog/16995.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
plugins/multiplexing: Added multiplexing support to database plugins if run as external plugins
```

View File

@ -5,7 +5,7 @@ import (
"os" "os"
"github.com/hashicorp/vault/plugins/database/cassandra" "github.com/hashicorp/vault/plugins/database/cassandra"
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
) )
func main() { func main() {
@ -18,12 +18,7 @@ func main() {
// Run instantiates a Cassandra object, and runs the RPC server for the plugin // Run instantiates a Cassandra object, and runs the RPC server for the plugin
func Run() error { func Run() error {
dbType, err := cassandra.New() dbplugin.ServeMultiplex(cassandra.New)
if err != nil {
return err
}
dbplugin.Serve(dbType.(dbplugin.Database))
return nil return nil
} }

View File

@ -5,7 +5,7 @@ import (
"os" "os"
"github.com/hashicorp/vault/plugins/database/hana" "github.com/hashicorp/vault/plugins/database/hana"
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
) )
func main() { func main() {
@ -18,12 +18,7 @@ func main() {
// Run instantiates a HANA object, and runs the RPC server for the plugin // Run instantiates a HANA object, and runs the RPC server for the plugin
func Run() error { func Run() error {
dbType, err := hana.New() dbplugin.ServeMultiplex(hana.New)
if err != nil {
return err
}
dbplugin.Serve(dbType.(dbplugin.Database))
return nil return nil
} }

View File

@ -5,7 +5,7 @@ import (
"os" "os"
"github.com/hashicorp/vault/plugins/database/influxdb" "github.com/hashicorp/vault/plugins/database/influxdb"
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
) )
func main() { func main() {
@ -18,12 +18,7 @@ func main() {
// Run instantiates a Influxdb object, and runs the RPC server for the plugin // Run instantiates a Influxdb object, and runs the RPC server for the plugin
func Run() error { func Run() error {
dbType, err := influxdb.New() dbplugin.ServeMultiplex(influxdb.New)
if err != nil {
return err
}
dbplugin.Serve(dbType.(dbplugin.Database))
return nil return nil
} }

View File

@ -5,7 +5,7 @@ import (
"os" "os"
"github.com/hashicorp/vault/plugins/database/mongodb" "github.com/hashicorp/vault/plugins/database/mongodb"
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
) )
func main() { func main() {
@ -18,12 +18,7 @@ func main() {
// Run instantiates a MongoDB object, and runs the RPC server for the plugin // Run instantiates a MongoDB object, and runs the RPC server for the plugin
func Run() error { func Run() error {
dbType, err := mongodb.New() dbplugin.ServeMultiplex(mongodb.New)
if err != nil {
return err
}
dbplugin.Serve(dbType.(dbplugin.Database))
return nil return nil
} }

View File

@ -5,7 +5,7 @@ import (
"os" "os"
"github.com/hashicorp/vault/plugins/database/mssql" "github.com/hashicorp/vault/plugins/database/mssql"
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
) )
func main() { func main() {
@ -18,12 +18,7 @@ func main() {
// Run instantiates a MSSQL object, and runs the RPC server for the plugin // Run instantiates a MSSQL object, and runs the RPC server for the plugin
func Run() error { func Run() error {
dbType, err := mssql.New() dbplugin.ServeMultiplex(mssql.New)
if err != nil {
return err
}
dbplugin.Serve(dbType.(dbplugin.Database))
return nil return nil
} }

View File

@ -5,7 +5,7 @@ import (
"os" "os"
"github.com/hashicorp/vault/plugins/database/mysql" "github.com/hashicorp/vault/plugins/database/mysql"
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
) )
func main() { func main() {
@ -20,12 +20,8 @@ func main() {
func Run() error { func Run() error {
var f func() (interface{}, error) var f func() (interface{}, error)
f = mysql.New(mysql.DefaultUserNameTemplate) f = mysql.New(mysql.DefaultUserNameTemplate)
dbType, err := f()
if err != nil {
return err
}
dbplugin.Serve(dbType.(dbplugin.Database)) dbplugin.ServeMultiplex(f)
return nil return nil
} }

View File

@ -5,7 +5,7 @@ import (
"os" "os"
"github.com/hashicorp/vault/plugins/database/postgresql" "github.com/hashicorp/vault/plugins/database/postgresql"
dbplugin "github.com/hashicorp/vault/sdk/database/dbplugin/v5" "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
) )
func main() { func main() {
@ -18,12 +18,7 @@ func main() {
// Run instantiates a PostgreSQL object, and runs the RPC server for the plugin // Run instantiates a PostgreSQL object, and runs the RPC server for the plugin
func Run() error { func Run() error {
dbType, err := postgresql.New() dbplugin.ServeMultiplex(postgresql.New)
if err != nil {
return err
}
dbplugin.Serve(dbType.(dbplugin.Database))
return nil return nil
} }

View File

@ -4,30 +4,20 @@ import (
"log" "log"
"os" "os"
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/plugins/database/redshift" "github.com/hashicorp/vault/plugins/database/redshift"
"github.com/hashicorp/vault/sdk/database/dbplugin" "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
) )
func main() { func main() {
apiClientMeta := &api.PluginAPIClientMeta{} if err := Run(); err != nil {
flags := apiClientMeta.FlagSet()
flags.Parse(os.Args[1:])
if err := Run(apiClientMeta.GetTLSConfig()); err != nil {
log.Println(err) log.Println(err)
os.Exit(1) os.Exit(1)
} }
} }
// Run instantiates a RedShift object, and runs the RPC server for the plugin // Run instantiates a RedShift object, and runs the RPC server for the plugin
func Run(apiTLSConfig *api.TLSConfig) error { func Run() error {
dbType, err := redshift.New() dbplugin.ServeMultiplex(redshift.New)
if err != nil {
return err
}
dbplugin.Serve(dbType.(dbplugin.Database), api.VaultPluginTLSProvider(apiTLSConfig))
return nil return nil
} }