mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 01:32:33 +00:00
Add stack trace to audit logging panic recovery (#18121)
This commit is contained in:
3
changelog/18121.txt
Normal file
3
changelog/18121.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
```release-note:improvement
|
||||
audit: Include stack trace when audit logging recovers from a panic.
|
||||
```
|
||||
@@ -3,6 +3,7 @@ package vault
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -105,7 +106,7 @@ func (a *AuditBroker) LogRequest(ctx context.Context, in *logical.LogInput, head
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
a.logger.Error("panic during logging", "request_path", in.Request.Path, "error", r)
|
||||
a.logger.Error("panic during logging", "request_path", in.Request.Path, "error", r, "stacktrace", string(debug.Stack()))
|
||||
retErr = multierror.Append(retErr, fmt.Errorf("panic generating audit log"))
|
||||
}
|
||||
|
||||
@@ -176,7 +177,7 @@ func (a *AuditBroker) LogResponse(ctx context.Context, in *logical.LogInput, hea
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
a.logger.Error("panic during logging", "request_path", in.Request.Path, "error", r)
|
||||
a.logger.Error("panic during logging", "request_path", in.Request.Path, "error", r, "stacktrace", string(debug.Stack()))
|
||||
retErr = multierror.Append(retErr, fmt.Errorf("panic generating audit log"))
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@@ -41,12 +41,8 @@ func (s *forwardedRequestRPCServer) ForwardRequest(ctx context.Context, freq *fo
|
||||
|
||||
runRequest := func() {
|
||||
defer func() {
|
||||
// Logic here comes mostly from the Go source code
|
||||
if err := recover(); err != nil {
|
||||
const size = 64 << 10
|
||||
buf := make([]byte, size)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
s.core.logger.Error("panic serving forwarded request", "path", req.URL.Path, "error", err, "stacktrace", string(buf))
|
||||
s.core.logger.Error("panic serving forwarded request", "path", req.URL.Path, "error", err, "stacktrace", string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
s.handler.ServeHTTP(w, req)
|
||||
|
||||
Reference in New Issue
Block a user