Simplify tracking of external plugins (#20009)

This commit is contained in:
Tom Proctor 2023-04-12 17:34:35 +00:00 committed by GitHub
parent 2310e13cf1
commit 9aa9686c81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 12 additions and 65 deletions

View File

@ -86,23 +86,15 @@ func Backend(ctx context.Context, conf *logical.BackendConfig) (*PluginBackend,
runningVersion = versioner.PluginVersion().Version
}
external := false
if externaler, ok := raw.(logical.Externaler); ok {
external = externaler.IsExternal()
}
// Cleanup meta plugin backend
raw.Cleanup(ctx)
// Initialize b.Backend with placeholder backend since plugin
// backends will need to be lazy loaded.
b.Backend = &placeholderBackend{
Backend: framework.Backend{
b.Backend = &framework.Backend{
PathsSpecial: paths,
BackendType: btype,
RunningVersion: runningVersion,
},
external: external,
}
b.config = conf
@ -110,23 +102,6 @@ func Backend(ctx context.Context, conf *logical.BackendConfig) (*PluginBackend,
return &b, nil
}
// placeholderBackend is used a placeholder before a backend is lazy-loaded.
// It is mostly used to mark that the backend is an external backend.
type placeholderBackend struct {
framework.Backend
external bool
}
func (p *placeholderBackend) IsExternal() bool {
return p.external
}
var (
_ logical.Externaler = (*placeholderBackend)(nil)
_ logical.PluginVersioner = (*placeholderBackend)(nil)
)
// PluginBackend is a thin wrapper around plugin.BackendPluginClient
type PluginBackend struct {
Backend logical.Backend
@ -326,14 +301,4 @@ func (b *PluginBackend) PluginVersion() logical.PluginVersion {
return logical.EmptyPluginVersion
}
func (b *PluginBackend) IsExternal() bool {
if externaler, ok := b.Backend.(logical.Externaler); ok {
return externaler.IsExternal()
}
return false
}
var (
_ logical.PluginVersioner = (*PluginBackend)(nil)
_ logical.Externaler = (*PluginBackend)(nil)
)
var _ logical.PluginVersioner = (*PluginBackend)(nil)

View File

@ -166,11 +166,6 @@ type Auditor interface {
AuditResponse(ctx context.Context, input *LogInput) error
}
// Externaler allows us to check if a backend is running externally (i.e., over GRPC)
type Externaler interface {
IsExternal() bool
}
type PluginVersion struct {
Version string
}

View File

@ -154,14 +154,4 @@ func (b *BackendPluginClient) PluginVersion() logical.PluginVersion {
return logical.EmptyPluginVersion
}
func (b *BackendPluginClient) IsExternal() bool {
if externaler, ok := b.Backend.(logical.Externaler); ok {
return externaler.IsExternal()
}
return true // default to true since this is only used for GRPC plugins
}
var (
_ logical.PluginVersioner = (*BackendPluginClient)(nil)
_ logical.Externaler = (*BackendPluginClient)(nil)
)
var _ logical.PluginVersioner = (*BackendPluginClient)(nil)

View File

@ -55,10 +55,7 @@ func (b *BackendPluginClientV5) PluginVersion() logical.PluginVersion {
return logical.EmptyPluginVersion
}
var (
_ logical.PluginVersioner = (*BackendPluginClientV5)(nil)
_ logical.Externaler = (*BackendPluginClientV5)(nil)
)
var _ logical.PluginVersioner = (*BackendPluginClientV5)(nil)
// NewBackendV5 will return an instance of an RPC-based client implementation of
// the backend for external plugins, or a concrete implementation of the

View File

@ -192,7 +192,7 @@ func (c *Core) enableCredentialInternal(ctx context.Context, entry *MountEntry,
entry.RunningVersion = entry.Version
if entry.RunningVersion == "" {
// don't set the running version to a builtin if it is running as an external plugin
if externaler, ok := backend.(logical.Externaler); !ok || !externaler.IsExternal() {
if entry.RunningSha256 == "" {
entry.RunningVersion = versions.GetBuiltinVersion(consts.PluginTypeCredential, entry.Type)
}
}
@ -819,7 +819,7 @@ func (c *Core) setupCredentials(ctx context.Context) error {
entry.RunningVersion = entry.Version
if entry.RunningVersion == "" {
// don't set the running version to a builtin if it is running as an external plugin
if externaler, ok := backend.(logical.Externaler); !ok || !externaler.IsExternal() {
if entry.RunningSha256 == "" {
entry.RunningVersion = versions.GetBuiltinVersion(consts.PluginTypeCredential, entry.Type)
}
}

View File

@ -698,7 +698,7 @@ func (c *Core) mountInternal(ctx context.Context, entry *MountEntry, updateStora
entry.RunningVersion = entry.Version
if entry.RunningVersion == "" {
// don't set the running version to a builtin if it is running as an external plugin
if externaler, ok := backend.(logical.Externaler); !ok || !externaler.IsExternal() {
if entry.RunningSha256 == "" {
entry.RunningVersion = versions.GetBuiltinVersion(consts.PluginTypeSecrets, entry.Type)
}
}
@ -1512,7 +1512,7 @@ func (c *Core) setupMounts(ctx context.Context) error {
entry.RunningVersion = entry.Version
if entry.RunningVersion == "" {
// don't set the running version to a builtin if it is running as an external plugin
if externaler, ok := backend.(logical.Externaler); !ok || !externaler.IsExternal() {
if entry.RunningSha256 == "" {
entry.RunningVersion = versions.GetBuiltinVersion(consts.PluginTypeSecrets, entry.Type)
}
}

View File

@ -197,7 +197,7 @@ func (c *Core) reloadBackendCommon(ctx context.Context, entry *MountEntry, isAut
entry.RunningVersion = entry.Version
if entry.RunningVersion == "" {
// don't set the running version to a builtin if it is running as an external plugin
if externaler, ok := backend.(logical.Externaler); !ok || !externaler.IsExternal() {
if entry.RunningSha256 == "" {
if isAuth {
entry.RunningVersion = versions.GetBuiltinVersion(consts.PluginTypeCredential, entry.Type)
} else {