Skip to content

Commit 9f2be64

Browse files
committed
Log failed Vault authentication attempts
1 parent 2599d7e commit 9f2be64

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

internal/keystore/vault/vault.go

+25
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"encoding/base64"
1818
"errors"
1919
"fmt"
20+
"log/slog"
2021
"net/http"
2122
"os"
2223
"path"
@@ -139,6 +140,30 @@ func Connect(ctx context.Context, c *Config) (*Store, error) {
139140
authenticate = client.AuthenticateWithK8S(c.K8S)
140141
}
141142

143+
// log authentication events
144+
lastAuthSuccess := false
145+
authenticate = func(ctx context.Context) (*vaultapi.Secret, error) {
146+
secret, err := authenticate(ctx)
147+
if err != nil {
148+
if lastAuthSuccess {
149+
slog.Info("Authentication failed (not logged anymore until next successful authentication)", slog.String("error", err.Error()))
150+
lastAuthSuccess = false
151+
}
152+
} else {
153+
if c.Verbose {
154+
obfuscatedToken := secret.Auth.ClientToken
155+
if len(obfuscatedToken) > 10 {
156+
obfuscatedToken = obfuscatedToken[:2] + "***" + obfuscatedToken[len(obfuscatedToken)-4:]
157+
} else {
158+
obfuscatedToken = "***"
159+
}
160+
slog.Info("Authentication successful", slog.String("token", obfuscatedToken))
161+
}
162+
lastAuthSuccess = true
163+
}
164+
return secret, err
165+
}
166+
142167
auth, err := authenticate(ctx)
143168
if err != nil {
144169
return nil, err

kesconf/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ type ymlFile struct {
122122
Ping env[time.Duration] `yaml:"ping"`
123123
} `yaml:"status"`
124124

125-
Verbose bool `yaml:"verbose"`
125+
Verbose env[bool] `yaml:"verbose"`
126126
} `yaml:"vault"`
127127

128128
Fortanix *struct {

0 commit comments

Comments
 (0)