mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Add plugin version to GRPC interface (#17088)
Add plugin version to GRPC interface Added a version interface in the sdk/logical so that it can be shared between all plugin types, and then wired it up to RunningVersion in the mounts, auth list, and database systems. I've tested that this works with auth, database, and secrets plugin types, with the following logic to populate RunningVersion: If a plugin has a PluginVersion() method implemented, then that is used If not, and the plugin is built into the Vault binary, then the go.mod version is used Otherwise, the it will be the empty string. My apologies for the length of this PR. * Placeholder backend should be external We use a placeholder backend (previously a framework.Backend) before a GRPC plugin is lazy-loaded. This makes us later think the plugin is a builtin plugin. So we added a `placeholderBackend` type that overrides the `IsExternal()` method so that later we know that the plugin is external, and don't give it a default builtin version.
This commit is contained in:
committed by
GitHub
parent
b4e9ee8742
commit
70278c2787
@@ -6,15 +6,14 @@ import (
|
||||
"math"
|
||||
"sync/atomic"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
plugin "github.com/hashicorp/go-plugin"
|
||||
"github.com/hashicorp/go-plugin"
|
||||
"github.com/hashicorp/vault/sdk/helper/pluginutil"
|
||||
"github.com/hashicorp/vault/sdk/logical"
|
||||
"github.com/hashicorp/vault/sdk/plugin/pb"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -28,9 +27,10 @@ var _ logical.Backend = &backendGRPCPluginClient{}
|
||||
// backendPluginClient implements logical.Backend and is the
|
||||
// go-plugin client.
|
||||
type backendGRPCPluginClient struct {
|
||||
broker *plugin.GRPCBroker
|
||||
client pb.BackendClient
|
||||
metadataMode bool
|
||||
broker *plugin.GRPCBroker
|
||||
client pb.BackendClient
|
||||
versionClient logical.PluginVersionClient
|
||||
metadataMode bool
|
||||
|
||||
system logical.SystemView
|
||||
logger log.Logger
|
||||
@@ -280,3 +280,23 @@ func (b *backendGRPCPluginClient) Type() logical.BackendType {
|
||||
|
||||
return logical.BackendType(reply.Type)
|
||||
}
|
||||
|
||||
func (b *backendGRPCPluginClient) PluginVersion() logical.PluginVersion {
|
||||
reply, err := b.versionClient.Version(b.doneCtx, &logical.Empty{})
|
||||
if err != nil {
|
||||
if stErr, ok := status.FromError(err); ok {
|
||||
if stErr.Code() == codes.Unimplemented {
|
||||
return logical.EmptyPluginVersion
|
||||
}
|
||||
}
|
||||
b.Logger().Warn("Unknown error getting plugin version", "err", err)
|
||||
return logical.EmptyPluginVersion
|
||||
}
|
||||
return logical.PluginVersion{
|
||||
Version: reply.GetPluginVersion(),
|
||||
}
|
||||
}
|
||||
|
||||
func (b *backendGRPCPluginClient) IsExternal() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user