2018-11-07 01:21:24 +00:00
|
|
|
package builtinplugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
credAliCloud "github.com/hashicorp/vault-plugin-auth-alicloud"
|
|
|
|
credAzure "github.com/hashicorp/vault-plugin-auth-azure"
|
|
|
|
credCentrify "github.com/hashicorp/vault-plugin-auth-centrify"
|
2019-08-26 16:55:08 +00:00
|
|
|
credCF "github.com/hashicorp/vault-plugin-auth-cf"
|
2018-11-07 01:21:24 +00:00
|
|
|
credGcp "github.com/hashicorp/vault-plugin-auth-gcp/plugin"
|
|
|
|
credJWT "github.com/hashicorp/vault-plugin-auth-jwt"
|
2019-12-11 19:18:37 +00:00
|
|
|
credKerb "github.com/hashicorp/vault-plugin-auth-kerberos"
|
2018-11-07 01:21:24 +00:00
|
|
|
credKube "github.com/hashicorp/vault-plugin-auth-kubernetes"
|
2019-09-05 20:50:12 +00:00
|
|
|
credOCI "github.com/hashicorp/vault-plugin-auth-oci"
|
2020-10-22 21:43:19 +00:00
|
|
|
|
2020-10-22 23:20:17 +00:00
|
|
|
dbCouchbase "github.com/hashicorp/vault-plugin-database-couchbase"
|
|
|
|
dbElastic "github.com/hashicorp/vault-plugin-database-elasticsearch"
|
|
|
|
dbMongoAtlas "github.com/hashicorp/vault-plugin-database-mongodbatlas"
|
2018-11-07 01:21:24 +00:00
|
|
|
credAppId "github.com/hashicorp/vault/builtin/credential/app-id"
|
|
|
|
credAppRole "github.com/hashicorp/vault/builtin/credential/approle"
|
|
|
|
credAws "github.com/hashicorp/vault/builtin/credential/aws"
|
|
|
|
credCert "github.com/hashicorp/vault/builtin/credential/cert"
|
|
|
|
credGitHub "github.com/hashicorp/vault/builtin/credential/github"
|
|
|
|
credLdap "github.com/hashicorp/vault/builtin/credential/ldap"
|
|
|
|
credOkta "github.com/hashicorp/vault/builtin/credential/okta"
|
|
|
|
credRadius "github.com/hashicorp/vault/builtin/credential/radius"
|
|
|
|
credUserpass "github.com/hashicorp/vault/builtin/credential/userpass"
|
|
|
|
dbCass "github.com/hashicorp/vault/plugins/database/cassandra"
|
|
|
|
dbHana "github.com/hashicorp/vault/plugins/database/hana"
|
2019-01-09 01:26:16 +00:00
|
|
|
dbInflux "github.com/hashicorp/vault/plugins/database/influxdb"
|
2018-11-07 01:21:24 +00:00
|
|
|
dbMongo "github.com/hashicorp/vault/plugins/database/mongodb"
|
|
|
|
dbMssql "github.com/hashicorp/vault/plugins/database/mssql"
|
|
|
|
dbMysql "github.com/hashicorp/vault/plugins/database/mysql"
|
|
|
|
dbPostgres "github.com/hashicorp/vault/plugins/database/postgresql"
|
2020-02-13 17:42:30 +00:00
|
|
|
dbRedshift "github.com/hashicorp/vault/plugins/database/redshift"
|
2020-02-07 22:09:39 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/consts"
|
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2018-11-07 01:21:24 +00:00
|
|
|
|
|
|
|
logicalAd "github.com/hashicorp/vault-plugin-secrets-ad/plugin"
|
|
|
|
logicalAlicloud "github.com/hashicorp/vault-plugin-secrets-alicloud"
|
|
|
|
logicalAzure "github.com/hashicorp/vault-plugin-secrets-azure"
|
|
|
|
logicalGcp "github.com/hashicorp/vault-plugin-secrets-gcp/plugin"
|
|
|
|
logicalGcpKms "github.com/hashicorp/vault-plugin-secrets-gcpkms"
|
|
|
|
logicalKv "github.com/hashicorp/vault-plugin-secrets-kv"
|
2020-02-07 22:09:39 +00:00
|
|
|
logicalMongoAtlas "github.com/hashicorp/vault-plugin-secrets-mongodbatlas"
|
2020-05-14 13:19:27 +00:00
|
|
|
logicalOpenLDAP "github.com/hashicorp/vault-plugin-secrets-openldap"
|
2018-11-07 01:21:24 +00:00
|
|
|
logicalAws "github.com/hashicorp/vault/builtin/logical/aws"
|
|
|
|
logicalCass "github.com/hashicorp/vault/builtin/logical/cassandra"
|
|
|
|
logicalConsul "github.com/hashicorp/vault/builtin/logical/consul"
|
|
|
|
logicalMongo "github.com/hashicorp/vault/builtin/logical/mongodb"
|
|
|
|
logicalMssql "github.com/hashicorp/vault/builtin/logical/mssql"
|
|
|
|
logicalMysql "github.com/hashicorp/vault/builtin/logical/mysql"
|
|
|
|
logicalNomad "github.com/hashicorp/vault/builtin/logical/nomad"
|
|
|
|
logicalPki "github.com/hashicorp/vault/builtin/logical/pki"
|
|
|
|
logicalPostgres "github.com/hashicorp/vault/builtin/logical/postgresql"
|
|
|
|
logicalRabbit "github.com/hashicorp/vault/builtin/logical/rabbitmq"
|
|
|
|
logicalSsh "github.com/hashicorp/vault/builtin/logical/ssh"
|
|
|
|
logicalTotp "github.com/hashicorp/vault/builtin/logical/totp"
|
|
|
|
logicalTransit "github.com/hashicorp/vault/builtin/logical/transit"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Registry is inherently thread-safe because it's immutable.
|
|
|
|
// Thus, rather than creating multiple instances of it, we only need one.
|
|
|
|
var Registry = newRegistry()
|
|
|
|
|
2019-07-22 17:14:53 +00:00
|
|
|
var addExternalPlugins = addExtPluginsImpl
|
|
|
|
|
2018-11-07 01:21:24 +00:00
|
|
|
// BuiltinFactory is the func signature that should be returned by
|
|
|
|
// the plugin's New() func.
|
|
|
|
type BuiltinFactory func() (interface{}, error)
|
|
|
|
|
|
|
|
func newRegistry() *registry {
|
2019-07-22 17:14:53 +00:00
|
|
|
reg := ®istry{
|
2018-11-07 01:21:24 +00:00
|
|
|
credentialBackends: map[string]logical.Factory{
|
|
|
|
"alicloud": credAliCloud.Factory,
|
|
|
|
"app-id": credAppId.Factory,
|
|
|
|
"approle": credAppRole.Factory,
|
|
|
|
"aws": credAws.Factory,
|
|
|
|
"azure": credAzure.Factory,
|
|
|
|
"centrify": credCentrify.Factory,
|
|
|
|
"cert": credCert.Factory,
|
2019-08-26 16:55:08 +00:00
|
|
|
"cf": credCF.Factory,
|
2018-11-07 01:21:24 +00:00
|
|
|
"gcp": credGcp.Factory,
|
|
|
|
"github": credGitHub.Factory,
|
|
|
|
"jwt": credJWT.Factory,
|
2019-12-11 19:18:37 +00:00
|
|
|
"kerberos": credKerb.Factory,
|
2018-11-07 01:21:24 +00:00
|
|
|
"kubernetes": credKube.Factory,
|
|
|
|
"ldap": credLdap.Factory,
|
2019-09-05 20:50:12 +00:00
|
|
|
"oci": credOCI.Factory,
|
2019-02-11 21:37:55 +00:00
|
|
|
"oidc": credJWT.Factory,
|
2018-11-07 01:21:24 +00:00
|
|
|
"okta": credOkta.Factory,
|
2019-08-26 16:55:08 +00:00
|
|
|
"pcf": credCF.Factory, // Deprecated.
|
2018-11-07 01:21:24 +00:00
|
|
|
"radius": credRadius.Factory,
|
|
|
|
"userpass": credUserpass.Factory,
|
|
|
|
},
|
|
|
|
databasePlugins: map[string]BuiltinFactory{
|
|
|
|
// These four plugins all use the same mysql implementation but with
|
|
|
|
// different username settings passed by the constructor.
|
2020-10-09 17:32:38 +00:00
|
|
|
"mysql-database-plugin": dbMysql.New(false),
|
|
|
|
"mysql-aurora-database-plugin": dbMysql.New(true),
|
|
|
|
"mysql-rds-database-plugin": dbMysql.New(true),
|
|
|
|
"mysql-legacy-database-plugin": dbMysql.New(true),
|
2018-11-07 01:21:24 +00:00
|
|
|
|
2020-10-22 23:20:17 +00:00
|
|
|
"cassandra-database-plugin": dbCass.New,
|
|
|
|
"couchbase-database-plugin": dbCouchbase.New,
|
|
|
|
"elasticsearch-database-plugin": dbElastic.New,
|
|
|
|
"hana-database-plugin": dbHana.New,
|
|
|
|
"influxdb-database-plugin": dbInflux.New,
|
|
|
|
"mongodb-database-plugin": dbMongo.New,
|
|
|
|
"mongodbatlas-database-plugin": dbMongoAtlas.New,
|
|
|
|
"mssql-database-plugin": dbMssql.New,
|
|
|
|
"postgresql-database-plugin": dbPostgres.New,
|
|
|
|
"redshift-database-plugin": dbRedshift.New(true),
|
2018-11-07 01:21:24 +00:00
|
|
|
},
|
|
|
|
logicalBackends: map[string]logical.Factory{
|
2020-02-07 22:09:39 +00:00
|
|
|
"ad": logicalAd.Factory,
|
|
|
|
"alicloud": logicalAlicloud.Factory,
|
|
|
|
"aws": logicalAws.Factory,
|
|
|
|
"azure": logicalAzure.Factory,
|
2020-02-13 22:54:00 +00:00
|
|
|
"cassandra": logicalCass.Factory, // Deprecated
|
2020-02-07 22:09:39 +00:00
|
|
|
"consul": logicalConsul.Factory,
|
|
|
|
"gcp": logicalGcp.Factory,
|
|
|
|
"gcpkms": logicalGcpKms.Factory,
|
|
|
|
"kv": logicalKv.Factory,
|
2020-02-13 22:54:00 +00:00
|
|
|
"mongodb": logicalMongo.Factory, // Deprecated
|
2020-02-07 22:09:39 +00:00
|
|
|
"mongodbatlas": logicalMongoAtlas.Factory,
|
2020-02-13 22:54:00 +00:00
|
|
|
"mssql": logicalMssql.Factory, // Deprecated
|
|
|
|
"mysql": logicalMysql.Factory, // Deprecated
|
2020-02-07 22:09:39 +00:00
|
|
|
"nomad": logicalNomad.Factory,
|
2020-02-15 18:21:07 +00:00
|
|
|
"openldap": logicalOpenLDAP.Factory,
|
2020-02-07 22:09:39 +00:00
|
|
|
"pki": logicalPki.Factory,
|
2020-02-13 22:54:00 +00:00
|
|
|
"postgresql": logicalPostgres.Factory, // Deprecated
|
2020-02-07 22:09:39 +00:00
|
|
|
"rabbitmq": logicalRabbit.Factory,
|
|
|
|
"ssh": logicalSsh.Factory,
|
|
|
|
"totp": logicalTotp.Factory,
|
|
|
|
"transit": logicalTransit.Factory,
|
2018-11-07 01:21:24 +00:00
|
|
|
},
|
|
|
|
}
|
2019-07-22 17:14:53 +00:00
|
|
|
|
|
|
|
addExternalPlugins(reg)
|
|
|
|
|
|
|
|
return reg
|
2018-11-07 01:21:24 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 17:14:53 +00:00
|
|
|
func addExtPluginsImpl(r *registry) {}
|
|
|
|
|
2018-11-07 01:21:24 +00:00
|
|
|
type registry struct {
|
|
|
|
credentialBackends map[string]logical.Factory
|
|
|
|
databasePlugins map[string]BuiltinFactory
|
|
|
|
logicalBackends map[string]logical.Factory
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get returns the BuiltinFactory func for a particular backend plugin
|
|
|
|
// from the plugins map.
|
|
|
|
func (r *registry) Get(name string, pluginType consts.PluginType) (func() (interface{}, error), bool) {
|
|
|
|
switch pluginType {
|
|
|
|
case consts.PluginTypeCredential:
|
|
|
|
f, ok := r.credentialBackends[name]
|
|
|
|
return toFunc(f), ok
|
|
|
|
case consts.PluginTypeSecrets:
|
|
|
|
f, ok := r.logicalBackends[name]
|
|
|
|
return toFunc(f), ok
|
|
|
|
case consts.PluginTypeDatabase:
|
|
|
|
f, ok := r.databasePlugins[name]
|
|
|
|
return f, ok
|
|
|
|
default:
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keys returns the list of plugin names that are considered builtin plugins.
|
|
|
|
func (r *registry) Keys(pluginType consts.PluginType) []string {
|
|
|
|
var keys []string
|
|
|
|
switch pluginType {
|
|
|
|
case consts.PluginTypeDatabase:
|
|
|
|
for key := range r.databasePlugins {
|
|
|
|
keys = append(keys, key)
|
|
|
|
}
|
|
|
|
case consts.PluginTypeCredential:
|
|
|
|
for key := range r.credentialBackends {
|
|
|
|
keys = append(keys, key)
|
|
|
|
}
|
|
|
|
case consts.PluginTypeSecrets:
|
|
|
|
for key := range r.logicalBackends {
|
|
|
|
keys = append(keys, key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return keys
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *registry) Contains(name string, pluginType consts.PluginType) bool {
|
|
|
|
for _, key := range r.Keys(pluginType) {
|
|
|
|
if key == name {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func toFunc(ifc interface{}) func() (interface{}, error) {
|
|
|
|
return func() (interface{}, error) {
|
|
|
|
return ifc, nil
|
|
|
|
}
|
|
|
|
}
|