mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
VAULT-24013: Audit regression attempting to recover from panic (#25605)
* Add Logger to BackendConfig * EntryFormatter use logger and recover panics * Added TODO to consider * Add 'name' to entry formatter * Add test for the panic * Fix NoopAudit with update params * emit counter metric even when 0 * Fix vault package tests * changelog * Remove old comment during test writing
This commit is contained in:
@@ -6,11 +6,13 @@ package syslog
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/eventlogger"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/go-secure-stdlib/parseutil"
|
||||
"github.com/hashicorp/vault/audit"
|
||||
"github.com/hashicorp/vault/internal/observability/event"
|
||||
@@ -43,6 +45,10 @@ func Factory(_ context.Context, conf *audit.BackendConfig, headersConfig audit.H
|
||||
return nil, fmt.Errorf("%s: nil salt view", op)
|
||||
}
|
||||
|
||||
if conf.Logger == nil || reflect.ValueOf(conf.Logger).IsNil() {
|
||||
return nil, fmt.Errorf("%s: nil logger", op)
|
||||
}
|
||||
|
||||
// Get facility or default to AUTH
|
||||
facility, ok := conf.Config["facility"]
|
||||
if !ok {
|
||||
@@ -94,7 +100,7 @@ func Factory(_ context.Context, conf *audit.BackendConfig, headersConfig audit.H
|
||||
audit.WithPrefix(conf.Config["prefix"]),
|
||||
}
|
||||
|
||||
err = b.configureFormatterNode(cfg, formatterOpts...)
|
||||
err = b.configureFormatterNode(conf.MountPath, cfg, conf.Logger, formatterOpts...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: error configuring formatter node: %w", op, err)
|
||||
}
|
||||
@@ -216,7 +222,7 @@ func (b *Backend) configureFilterNode(filter string) error {
|
||||
}
|
||||
|
||||
// configureFormatterNode is used to configure a formatter node and associated ID on the Backend.
|
||||
func (b *Backend) configureFormatterNode(formatConfig audit.FormatterConfig, opts ...audit.Option) error {
|
||||
func (b *Backend) configureFormatterNode(name string, formatConfig audit.FormatterConfig, logger hclog.Logger, opts ...audit.Option) error {
|
||||
const op = "syslog.(Backend).configureFormatterNode"
|
||||
|
||||
formatterNodeID, err := event.GenerateNodeID()
|
||||
@@ -224,7 +230,7 @@ func (b *Backend) configureFormatterNode(formatConfig audit.FormatterConfig, opt
|
||||
return fmt.Errorf("%s: error generating random NodeID for formatter node: %w", op, err)
|
||||
}
|
||||
|
||||
formatterNode, err := audit.NewEntryFormatter(formatConfig, b, opts...)
|
||||
formatterNode, err := audit.NewEntryFormatter(name, formatConfig, b, logger, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: error creating formatter: %w", op, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user