mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 10:12:35 +00:00
backport of commit 3976217420 (#24241)
Co-authored-by: Peter Wilson <peter.wilson@hashicorp.com>
This commit is contained in:
committed by
GitHub
parent
e155227314
commit
25a4d1a00d
3
changelog/24238.txt
Normal file
3
changelog/24238.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:bug
|
||||||
|
core/audit: Audit logging a Vault response will now use a 5 second context timeout, separate from the original request.
|
||||||
|
```
|
||||||
@@ -10,6 +10,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/vault/helper/namespace"
|
||||||
|
|
||||||
"github.com/hashicorp/vault/internal/observability/event"
|
"github.com/hashicorp/vault/internal/observability/event"
|
||||||
|
|
||||||
metrics "github.com/armon/go-metrics"
|
metrics "github.com/armon/go-metrics"
|
||||||
@@ -297,7 +299,22 @@ func (a *AuditBroker) LogResponse(ctx context.Context, in *logical.LogInput, hea
|
|||||||
|
|
||||||
e.Data = in
|
e.Data = in
|
||||||
|
|
||||||
status, err := a.broker.Send(ctx, eventlogger.EventType(event.AuditType.String()), e)
|
// In cases where we are trying to audit the response, we detach
|
||||||
|
// ourselves from the original context (keeping only the namespace).
|
||||||
|
// This is so that we get a fair run at writing audit entries if Vault
|
||||||
|
// Took up a lot of time handling the request before audit (response)
|
||||||
|
// is triggered. Pipeline nodes may check for a cancelled context and
|
||||||
|
// refuse to process the nodes further.
|
||||||
|
ns, err := namespace.FromContext(ctx)
|
||||||
|
if err != nil {
|
||||||
|
retErr = multierror.Append(retErr, fmt.Errorf("namespace missing from context: %w", err))
|
||||||
|
return retErr.ErrorOrNil()
|
||||||
|
}
|
||||||
|
|
||||||
|
auditContext, auditCancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer auditCancel()
|
||||||
|
auditContext = namespace.ContextWithNamespace(auditContext, ns)
|
||||||
|
status, err := a.broker.Send(auditContext, eventlogger.EventType(event.AuditType.String()), e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
retErr = multierror.Append(retErr, multierror.Append(err, status.Warnings...))
|
retErr = multierror.Append(retErr, multierror.Append(err, status.Warnings...))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user