support relative paths for KMS_SECRET_KEY_FILE (#20264)

fixes #20251
This commit is contained in:
Harshavardhana 2024-08-15 04:46:39 -07:00 committed by GitHub
parent d96798ae7b
commit 3b1aa40372
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,6 +26,7 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"sync/atomic"
"syscall"
@ -254,6 +255,13 @@ func Connect(ctx context.Context, opts *ConnectionOptions) (*KMS, error) {
var s string
if lookup(EnvKMSSecretKeyFile) {
b, err := os.ReadFile(env.Get(EnvKMSSecretKeyFile, ""))
if err != nil && !os.IsNotExist(err) {
return nil, err
}
if os.IsNotExist(err) {
// Relative path where "/run/secrets" is the default docker path for secrets
b, err = os.ReadFile(filepath.Join("/run/secrets", env.Get(EnvKMSSecretKeyFile, "")))
}
if err != nil {
return nil, err
}