-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verbose vault logging #502
base: master
Are you sure you want to change the base?
Changes from all commits
2fdf7fe
d86b633
8095a34
b1195b2
872b93b
2c90351
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM golang:1.21-alpine as build | ||
FROM golang:1.22-alpine as build | ||
|
||
LABEL maintainer="MinIO Inc <[email protected]>" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/minio/kes | ||
|
||
go 1.21 | ||
go 1.22 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Required upgrade because |
||
|
||
toolchain go1.23.5 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package vault | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"fmt" | ||
"log/slog" | ||
"net/http" | ||
"time" | ||
|
||
vaultapi "github.com/hashicorp/vault/api" | ||
) | ||
|
||
type loggingTransport struct { | ||
http.RoundTripper | ||
} | ||
|
||
func (lt *loggingTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
rt := lt.RoundTripper | ||
if rt == nil { | ||
rt = http.DefaultTransport | ||
} | ||
|
||
start := time.Now() | ||
resp, err := rt.RoundTrip(req) | ||
|
||
// don't log health checks | ||
if req.URL.Path != "/v1/sys/health" { | ||
auth := obfuscateToken(req.Header.Get(vaultapi.AuthHeaderName)) | ||
switch { | ||
case err != nil: | ||
slog.Debug("HTTP error", | ||
slog.String("method", req.Method), | ||
slog.String("url", req.URL.String()), | ||
slog.String("auth", auth), | ||
slog.Duration("duration", time.Since(start)), | ||
slog.String("error", err.Error())) | ||
case resp.StatusCode >= 300: | ||
slog.Debug("HTTP error response", | ||
slog.String("method", req.Method), | ||
slog.String("url", req.URL.String()), | ||
slog.String("auth", auth), | ||
slog.Duration("duration", time.Since(start)), | ||
slog.String("status", resp.Status)) | ||
default: | ||
slog.Debug("HTTP success response", | ||
slog.String("method", req.Method), | ||
slog.String("url", req.URL.String()), | ||
slog.String("auth", auth), | ||
slog.Duration("duration", time.Since(start)), | ||
slog.String("status", resp.Status)) | ||
} | ||
} | ||
|
||
return resp, err | ||
} | ||
|
||
func obfuscateToken(token string) string { | ||
if len(token) == 0 { | ||
return "" | ||
} | ||
hash := sha256.Sum256([]byte(token)) | ||
return fmt.Sprintf("%s (hashed)", hex.EncodeToString(hash[:16])) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ type ymlFile struct { | |
Log struct { | ||
Error env[string] `yaml:"error"` | ||
Audit env[string] `yaml:"audit"` | ||
Level env[string] `yaml:"level"` | ||
} `yaml:"log"` | ||
|
||
Keys []struct { | ||
|
@@ -299,6 +300,10 @@ func ymlToServerConfig(y *ymlFile) (*File, error) { | |
if err != nil { | ||
return nil, err | ||
} | ||
logLevel, err := parseLogLevel(y.Log.Level.Value) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for path, api := range y.API.Paths { | ||
if api.Timeout.Value < 0 { | ||
|
@@ -354,6 +359,7 @@ func ymlToServerConfig(y *ymlFile) (*File, error) { | |
Log: &LogConfig{ | ||
ErrLevel: errLevel, | ||
AuditLevel: auditLevel, | ||
LogLevel: logLevel, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, not needed. |
||
}, | ||
KeyStore: keystore, | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -298,6 +298,9 @@ type LogConfig struct { | |
// Audit determines whether the KES server logs audit events to STDOUT. | ||
// It does not en/disable audit logging in general. | ||
AuditLevel slog.Level | ||
|
||
// Log level for which to report KES diagnostic messages. | ||
LogLevel slog.Level | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need another log-level field. Currently you can set the
It should be sufficient to set:
|
||
} | ||
|
||
// APIConfig is a structure that holds the API configuration | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be set before calling
rawConfig.Config
.