feat: Support Vault client token renewal#201
Conversation
Pull Request Test Coverage Report for Build 22293359321Details
💛 - Coveralls |
7ce2ffd to
e6a78d1
Compare
| if p.config.VaultClient == nil || p.config.VaultClient.authMethod == nil { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
When static token is used, we don't need to perform login because it's already configured on the client.
While a static token can be renewed, we are not supporting it right now because it requires a different setup. We might want support in the future, but it's out of the scope of this PR for now.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #201 +/- ##
==========================================
- Coverage 82.87% 82.28% -0.60%
==========================================
Files 35 35
Lines 2482 2534 +52
==========================================
+ Hits 2057 2085 +28
- Misses 321 341 +20
- Partials 104 108 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
3706ca9 to
33bfc4e
Compare
| for { | ||
| select { | ||
| case <-ctx.Done(): | ||
| return | ||
| default: | ||
| if err := vc.watchTokenLifecycle(ctx, secret); err != nil { | ||
| vc.logger.Error("Failed to watch Vault token lifecycle, will retry later", zap.Error(err)) | ||
| } | ||
|
|
||
| secret = vc.loginWithRetry(ctx) | ||
| } | ||
| } |
There was a problem hiding this comment.
Currently when watchTokenLifecycle exits because the context is finished, we still try to loginWithRetry. I think we could rewrite this to avoid that
for {
if err := vc.watchTokenLifecycle(ctx, secret); err != nil {
vc.logger.Error("Failed to watch Vault token lifecycle, will retry later", zap.Error(err))
}
select {
case <-ctx.Done():
return
default:
}
secret = vc.loginWithRetry(ctx)
}There was a problem hiding this comment.
In your example, loginWithRetry returns nil secret when context is finished. Then calling watchTokenLifecycle(ctx, nilSecret) will return ErrLifetimeWatcherMissingSecret and log it as an error which could be misleading. I checked with Claude and it proposed we could do something like:
for {
if err := vc.watchTokenLifecycle(ctx, secret); err != nil {
if ctx.Err() != nil {
return
}
vc.logger.Error("Failed to watch Vault token lifecycle, will retry later", zap.Error(err))
}
secret = vc.loginWithRetry(ctx)
if ctx.Err() != nil {
return
}
}44b847b to
bf93cfe
Compare
cb1ae08 to
2656c20
Compare
Changes
VaultClienttype that wraps the Vault API client with token lifecycle management that watches token expiry, re-authenticates on failure, and retries login.SSHProxy.Start(), so we can gracefully shut down the token lifecycle loop as SSHProxy terminates.