Skip to content

Commit

Permalink
Re-read JWT file for every authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
ramondeklein committed Nov 25, 2024
1 parent 60e5ae2 commit 690c558
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion internal/keystore/vault/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ package vault
import (
"context"
"errors"
"os"
"path"
"strings"
"sync/atomic"
"time"

Expand Down Expand Up @@ -104,9 +106,18 @@ func (c *client) AuthenticateWithK8S(login *Kubernetes) authFunc {
client = client.WithNamespace(login.Namespace)
}

jwt := login.JWT
if strings.ContainsRune(jwt, '/') || strings.ContainsRune(jwt, os.PathSeparator) {
jwtBytes, err := os.ReadFile(jwt)
if err != nil {
return nil, err
}
jwt = string(jwtBytes)
}

secret, err := client.Logical().WriteWithContext(ctx, path.Join("auth", login.Engine, "login"), map[string]interface{}{
"role": login.Role,
"jwt": login.JWT,
"jwt": jwt,
})
if secret == nil && err == nil {
// The Vault SDK eventually returns no error but also no
Expand Down
4 changes: 2 additions & 2 deletions kesconf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,11 @@ func ymlToKeyStore(y *ymlFile) (KeyStore, error) {
// We always check for '/' and the OS-specific one make cover cases where
// a path is specified using '/' but the underlying OS is e.g. windows.
if jwt := y.KeyStore.Vault.Kubernetes.JWT.Value; strings.ContainsRune(jwt, '/') || strings.ContainsRune(jwt, os.PathSeparator) {
b, err := os.ReadFile(y.KeyStore.Vault.Kubernetes.JWT.Value)
_, err := os.ReadFile(y.KeyStore.Vault.Kubernetes.JWT.Value)
if err != nil {
return nil, fmt.Errorf("kesconf: failed to read vault kubernetes JWT from '%s': %v", y.KeyStore.Vault.Kubernetes.JWT.Value, err)
}
y.KeyStore.Vault.Kubernetes.JWT.Value = string(b)
// postpone resolving the JWT until actually logging in
}
}
if y.KeyStore.Vault.Transit != nil {
Expand Down

0 comments on commit 690c558

Please sign in to comment.