fix(settings): read PEM files but b64 env vars
- Extract base64 data from PEM files and secret files - Environment variables are not PEM encoded and only the base64 data - Affects OpenVPN certificate, key and encrypted key
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package secrets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration/sources/files"
|
||||
"github.com/qdm12/gluetun/internal/openvpn/extract"
|
||||
)
|
||||
|
||||
// getCleanedEnv returns an environment variable value with
|
||||
@@ -40,3 +42,22 @@ func readSecretFileAsString(secretPathEnvKey, defaultSecretPath string) (
|
||||
}
|
||||
return *stringPtr, nil
|
||||
}
|
||||
|
||||
func readPEMSecretFile(secretPathEnvKey, defaultSecretPath string) (
|
||||
base64Ptr *string, err error) {
|
||||
pemData, err := readSecretFileAsStringPtr(secretPathEnvKey, defaultSecretPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading secret file: %w", err)
|
||||
}
|
||||
|
||||
if pemData == nil {
|
||||
return nil, nil //nolint:nilnil
|
||||
}
|
||||
|
||||
base64Data, err := extract.PEM([]byte(*pemData))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("extracting base64 encoded data from PEM content: %w", err)
|
||||
}
|
||||
|
||||
return &base64Data, nil
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func readOpenVPN() (
|
||||
return settings, fmt.Errorf("cannot read password file: %w", err)
|
||||
}
|
||||
|
||||
settings.ClientKey, err = readSecretFileAsStringPtr(
|
||||
settings.ClientKey, err = readPEMSecretFile(
|
||||
"OPENVPN_CLIENTKEY_SECRETFILE",
|
||||
"/run/secrets/openvpn_clientkey",
|
||||
)
|
||||
@@ -32,7 +32,7 @@ func readOpenVPN() (
|
||||
return settings, fmt.Errorf("cannot read client key file: %w", err)
|
||||
}
|
||||
|
||||
settings.ClientCrt, err = readSecretFileAsStringPtr(
|
||||
settings.ClientCrt, err = readPEMSecretFile(
|
||||
"OPENVPN_CLIENTCRT_SECRETFILE",
|
||||
"/run/secrets/openvpn_clientcrt",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user