From 435824c26c21b160ab9de45915ab26e86dacb6e1 Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-vault-core <82990506+hc-github-team-secure-vault-core@users.noreply.github.com> Date: Mon, 20 Mar 2023 09:27:45 -0400 Subject: [PATCH] backport of commit e6427b2b30d99191e8dfb177f830254db28c81f6 (#19620) Co-authored-by: Tom Proctor --- changelog/19593.txt | 4 ++++ sdk/plugin/grpc_events.go | 4 ++++ vault/auth.go | 15 +++++++++------ vault/mount.go | 15 +++++++++------ 4 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 changelog/19593.txt diff --git a/changelog/19593.txt b/changelog/19593.txt new file mode 100644 index 000000000000..8f170578ec07 --- /dev/null +++ b/changelog/19593.txt @@ -0,0 +1,4 @@ +```release-note:improvement +events: Suppress log warnings triggered when events are sent but the events system is not enabled. +``` + diff --git a/sdk/plugin/grpc_events.go b/sdk/plugin/grpc_events.go index 14fad9491e50..d1d9fc02634a 100644 --- a/sdk/plugin/grpc_events.go +++ b/sdk/plugin/grpc_events.go @@ -34,6 +34,10 @@ type GRPCEventsServer struct { } func (s *GRPCEventsServer) SendEvent(ctx context.Context, req *pb.SendEventRequest) (*pb.Empty, error) { + if s.impl == nil { + return &pb.Empty{}, nil + } + err := s.impl.Send(ctx, logical.EventType(req.EventType), req.Event) if err != nil { return nil, err diff --git a/vault/auth.go b/vault/auth.go index 5632142aa87f..6200e03a6dfc 100644 --- a/vault/auth.go +++ b/vault/auth.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/go-secure-stdlib/strutil" "github.com/hashicorp/go-uuid" "github.com/hashicorp/vault/builtin/plugin" + "github.com/hashicorp/vault/helper/experiments" "github.com/hashicorp/vault/helper/namespace" "github.com/hashicorp/vault/helper/versions" "github.com/hashicorp/vault/sdk/helper/consts" @@ -1001,12 +1002,14 @@ func (c *Core) newCredentialBackend(ctx context.Context, entry *MountEntry, sysV } config := &logical.BackendConfig{ - StorageView: view, - Logger: authLogger, - Config: conf, - System: sysView, - BackendUUID: entry.BackendAwareUUID, - EventsSender: pluginEventSender, + StorageView: view, + Logger: authLogger, + Config: conf, + System: sysView, + BackendUUID: entry.BackendAwareUUID, + } + if c.IsExperimentEnabled(experiments.VaultExperimentEventsAlpha1) { + config.EventsSender = pluginEventSender } b, err := f(ctx, config) diff --git a/vault/mount.go b/vault/mount.go index 2f545fa87966..e1298b2e8949 100644 --- a/vault/mount.go +++ b/vault/mount.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/go-secure-stdlib/strutil" "github.com/hashicorp/go-uuid" "github.com/hashicorp/vault/builtin/plugin" + "github.com/hashicorp/vault/helper/experiments" "github.com/hashicorp/vault/helper/metricsutil" "github.com/hashicorp/vault/helper/namespace" "github.com/hashicorp/vault/helper/versions" @@ -1660,12 +1661,14 @@ func (c *Core) newLogicalBackend(ctx context.Context, entry *MountEntry, sysView return nil, "", err } config := &logical.BackendConfig{ - StorageView: view, - Logger: backendLogger, - Config: conf, - System: sysView, - BackendUUID: entry.BackendAwareUUID, - EventsSender: pluginEventSender, + StorageView: view, + Logger: backendLogger, + Config: conf, + System: sysView, + BackendUUID: entry.BackendAwareUUID, + } + if c.IsExperimentEnabled(experiments.VaultExperimentEventsAlpha1) { + config.EventsSender = pluginEventSender } ctx = context.WithValue(ctx, "core_number", c.coreNumber)