Skip to content

Commit e4a0943

Browse files
authored
perf: add session cache to improve tls efficiency (#332)
To improve efficiency in tls mode, session cache allows to reuse tls session. The default session cache is an LRU version, capacity has been defaulted to 64 (as implemented in official tls package). Signed-off-by: Nicolas Sterchele <nicolas@sterchelen.net>
1 parent e89fba3 commit e4a0943

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

vault/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package vault
1717
import (
1818
"context"
1919
"crypto/sha256"
20+
"crypto/tls"
2021
"fmt"
2122
"net/http"
2223
"os"
@@ -35,7 +36,8 @@ import (
3536
)
3637

3738
const (
38-
defaultJWTFile = "/var/run/secrets/kubernetes.io/serviceaccount/token"
39+
defaultJWTFile = "/var/run/secrets/kubernetes.io/serviceaccount/token"
40+
sessionCacheCapacity = 64
3941
)
4042

4143
// NewData is a helper function for Vault KV Version two secret data creation
@@ -573,6 +575,7 @@ func NewInsecureRawClient() (*vaultapi.Client, error) {
573575

574576
config.HttpClient.Transport.(*http.Transport).TLSHandshakeTimeout = 5 * time.Second
575577
config.HttpClient.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify = true
578+
config.HttpClient.Transport.(*http.Transport).TLSClientConfig.ClientSessionCache = tls.NewLRUClientSessionCache(sessionCacheCapacity)
576579

577580
return vaultapi.NewClient(config)
578581
}

0 commit comments

Comments
 (0)