Skip to content
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

vault: limit token delay to not exceed token TTL #504

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22.7
check-latest: true
go-version: 1.23.0
id: go
- name: Check out code
uses: actions/checkout@v4
Expand All @@ -34,7 +33,7 @@ jobs:
- name: "Set up Go"
uses: actions/setup-go@v5
with:
go-version: 1.22.7
go-version: 1.23.0
id: go
- name: Check out code
uses: actions/checkout@v4
Expand All @@ -54,8 +53,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22.7
check-latest: true
go-version: 1.23.0
id: go
- name: Check out code
uses: actions/checkout@v4
Expand All @@ -68,14 +66,11 @@ jobs:
vulncheck:
name: Vulncheck ${{ matrix.go-version }}
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.22.7, 1.23.1]
steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
go-version: 1.23.0
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Get govulncheck
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.22.7
check-latest: true
go-version: 1.23.0
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/minio/kes

go 1.21

toolchain go1.23.5

require (
aead.dev/mem v0.2.0
aead.dev/minisign v0.2.1
Expand Down
13 changes: 10 additions & 3 deletions internal/keystore/vault/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ func (c *client) RenewToken(ctx context.Context, authenticate authFunc, secret *
continue
}

renewIn := 80 * (ttl / 100) // Renew token after 80% of its TTL has passed
ttl = 0 // Set TTL to zero to trigger an immediate re-authentication in case of auth failure
renewIn := 80 * (ttl / 100) // Renew token after 80% of its TTL has passed
delay := min((ttl-renewIn)/2, Delay) // Delay usage of renewed token but not beyond expiry
ttl = 0

select {
case <-ctx.Done():
return
Expand All @@ -210,6 +212,9 @@ func (c *client) RenewToken(ctx context.Context, authenticate authFunc, secret *
if err == nil {
break
}
if resp, ok := err.(*vaultapi.ResponseError); ok && resp.StatusCode >= 400 && resp.StatusCode < 500 {
break // Don't retry when we receive a 4xx response
}
}
if s == nil {
s, _ = authenticate(ctx)
Expand All @@ -225,10 +230,12 @@ func (c *client) RenewToken(ctx context.Context, authenticate authFunc, secret *
// Wait before we use the new auth. token. This accounts
// for replication lag between the Vault nodes and allows
// them to sync the token across the entire cluster.
// However, we must not wait longer than the remaining lifetime
// of the currently used token.
select {
case <-ctx.Done():
return
case <-time.After(Delay):
case <-time.After(delay):
}
c.SetToken(token) // SetToken is safe to call from different go routines
}
Expand Down
Loading