2018-01-18 21:49:20 +00:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2018-01-18 21:49:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// backendPluginClient implements logical.Backend and is the
|
|
|
|
// go-plugin client.
|
2022-08-30 02:42:26 +00:00
|
|
|
type BackendTracingMiddleware struct {
|
2018-04-03 00:46:59 +00:00
|
|
|
logger log.Logger
|
2018-01-18 21:49:20 +00:00
|
|
|
|
|
|
|
next logical.Backend
|
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
// Validate the backendTracingMiddle object satisfies the backend interface
|
2022-08-30 02:42:26 +00:00
|
|
|
var _ logical.Backend = &BackendTracingMiddleware{}
|
2018-01-19 06:44:44 +00:00
|
|
|
|
2022-08-30 02:42:26 +00:00
|
|
|
func (b *BackendTracingMiddleware) Initialize(ctx context.Context, req *logical.InitializationRequest) (err error) {
|
2019-07-05 23:55:40 +00:00
|
|
|
defer func(then time.Time) {
|
|
|
|
b.logger.Trace("initialize", "status", "finished", "err", err, "took", time.Since(then))
|
|
|
|
}(time.Now())
|
|
|
|
|
|
|
|
b.logger.Trace("initialize", "status", "started")
|
|
|
|
return b.next.Initialize(ctx, req)
|
|
|
|
}
|
|
|
|
|
2022-08-30 02:42:26 +00:00
|
|
|
func (b *BackendTracingMiddleware) HandleRequest(ctx context.Context, req *logical.Request) (resp *logical.Response, err error) {
|
2018-01-18 21:49:20 +00:00
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("handle request", "path", req.Path, "status", "finished", "err", err, "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("handle request", "path", req.Path, "status", "started")
|
2018-01-18 21:49:20 +00:00
|
|
|
return b.next.HandleRequest(ctx, req)
|
|
|
|
}
|
|
|
|
|
2022-08-30 02:42:26 +00:00
|
|
|
func (b *BackendTracingMiddleware) SpecialPaths() *logical.Paths {
|
2018-01-18 21:49:20 +00:00
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("special paths", "status", "finished", "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("special paths", "status", "started")
|
2018-01-18 21:49:20 +00:00
|
|
|
return b.next.SpecialPaths()
|
|
|
|
}
|
|
|
|
|
2022-08-30 02:42:26 +00:00
|
|
|
func (b *BackendTracingMiddleware) System() logical.SystemView {
|
2018-01-18 21:49:20 +00:00
|
|
|
return b.next.System()
|
|
|
|
}
|
|
|
|
|
2022-08-30 02:42:26 +00:00
|
|
|
func (b *BackendTracingMiddleware) Logger() log.Logger {
|
2018-01-18 21:49:20 +00:00
|
|
|
return b.next.Logger()
|
|
|
|
}
|
|
|
|
|
2022-08-30 02:42:26 +00:00
|
|
|
func (b *BackendTracingMiddleware) HandleExistenceCheck(ctx context.Context, req *logical.Request) (found bool, exists bool, err error) {
|
2018-01-18 21:49:20 +00:00
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("handle existence check", "path", req.Path, "status", "finished", "err", err, "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("handle existence check", "path", req.Path, "status", "started")
|
2018-01-18 21:49:20 +00:00
|
|
|
return b.next.HandleExistenceCheck(ctx, req)
|
|
|
|
}
|
|
|
|
|
2022-08-30 02:42:26 +00:00
|
|
|
func (b *BackendTracingMiddleware) Cleanup(ctx context.Context) {
|
2018-01-18 21:49:20 +00:00
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("cleanup", "status", "finished", "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("cleanup", "status", "started")
|
2018-01-19 06:44:44 +00:00
|
|
|
b.next.Cleanup(ctx)
|
2018-01-18 21:49:20 +00:00
|
|
|
}
|
|
|
|
|
2022-08-30 02:42:26 +00:00
|
|
|
func (b *BackendTracingMiddleware) InvalidateKey(ctx context.Context, key string) {
|
2018-01-18 21:49:20 +00:00
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("invalidate key", "key", key, "status", "finished", "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("invalidate key", "key", key, "status", "started")
|
2018-01-19 06:44:44 +00:00
|
|
|
b.next.InvalidateKey(ctx, key)
|
2018-01-18 21:49:20 +00:00
|
|
|
}
|
|
|
|
|
2022-08-30 02:42:26 +00:00
|
|
|
func (b *BackendTracingMiddleware) Setup(ctx context.Context, config *logical.BackendConfig) (err error) {
|
2018-01-18 21:49:20 +00:00
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("setup", "status", "finished", "err", err, "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("setup", "status", "started")
|
2018-01-19 06:44:44 +00:00
|
|
|
return b.next.Setup(ctx, config)
|
2018-01-18 21:49:20 +00:00
|
|
|
}
|
|
|
|
|
2022-08-30 02:42:26 +00:00
|
|
|
func (b *BackendTracingMiddleware) Type() logical.BackendType {
|
2018-01-18 21:49:20 +00:00
|
|
|
defer func(then time.Time) {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("type", "status", "finished", "took", time.Since(then))
|
2018-01-18 21:49:20 +00:00
|
|
|
}(time.Now())
|
|
|
|
|
2018-04-03 00:46:59 +00:00
|
|
|
b.logger.Trace("type", "status", "started")
|
2018-01-18 21:49:20 +00:00
|
|
|
return b.next.Type()
|
|
|
|
}
|
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.
2022-09-15 23:37:59 +00:00
|
|
|
|
|
|
|
func (b *BackendTracingMiddleware) PluginVersion() logical.PluginVersion {
|
|
|
|
defer func(then time.Time) {
|
|
|
|
b.logger.Trace("version", "status", "finished", "took", time.Since(then))
|
|
|
|
}(time.Now())
|
|
|
|
|
|
|
|
b.logger.Trace("version", "status", "started")
|
|
|
|
if versioner, ok := b.next.(logical.PluginVersioner); ok {
|
|
|
|
return versioner.PluginVersion()
|
|
|
|
}
|
|
|
|
return logical.EmptyPluginVersion
|
|
|
|
}
|