SecretSource.Value should be plain text in memory

This commit is contained in:
Joel Speed
2020-12-01 08:56:46 +00:00
parent d587030019
commit 5b003a5657
9 changed files with 20 additions and 52 deletions
+1 -10
View File
@@ -1,7 +1,6 @@
package validation
import (
"encoding/base64"
"fmt"
"os"
@@ -13,7 +12,7 @@ const multipleValuesForSecretSource = "multiple values specified for secret sour
func validateSecretSource(source options.SecretSource) string {
switch {
case len(source.Value) > 0 && source.FromEnv == "" && source.FromFile == "":
return validateSecretSourceValue(source.Value)
return ""
case len(source.Value) == 0 && source.FromEnv != "" && source.FromFile == "":
return validateSecretSourceEnv(source.FromEnv)
case len(source.Value) == 0 && source.FromEnv == "" && source.FromFile != "":
@@ -23,14 +22,6 @@ func validateSecretSource(source options.SecretSource) string {
}
}
func validateSecretSourceValue(value []byte) string {
dst := make([]byte, len(value))
if _, err := base64.StdEncoding.Decode(dst, value); err != nil {
return fmt.Sprintf("error decoding secret value: %v", err)
}
return ""
}
func validateSecretSourceEnv(key string) string {
if value := os.Getenv(key); value == "" {
return fmt.Sprintf("error loading secret from environent: no value for for key %q", key)
+1 -10
View File
@@ -1,7 +1,6 @@
package validation
import (
"encoding/base64"
"io/ioutil"
"os"
@@ -17,7 +16,7 @@ var _ = Describe("Common", func() {
var validSecretSourceFile string
BeforeEach(func() {
validSecretSourceValue = []byte(base64.StdEncoding.EncodeToString([]byte("This is a secret source value")))
validSecretSourceValue = []byte("This is a secret source value")
Expect(os.Setenv(validSecretSourceEnv, "This is a secret source env")).To(Succeed())
tmp, err := ioutil.TempFile("", "oauth2-proxy-secret-source-test")
Expect(err).ToNot(HaveOccurred())
@@ -110,14 +109,6 @@ var _ = Describe("Common", func() {
},
expectedMsg: "",
}),
Entry("with an invalid Value", validateSecretSourceTableInput{
source: func() options.SecretSource {
return options.SecretSource{
Value: []byte("Invalid Base64 Value"),
}
},
expectedMsg: "error decoding secret value: illegal base64 data at input byte 7",
}),
Entry("with an invalid FromEnv", validateSecretSourceTableInput{
source: func() options.SecretSource {
return options.SecretSource{
+2 -2
View File
@@ -148,7 +148,7 @@ var _ = Describe("Headers", func() {
ClaimSource: &options.ClaimSource{
Claim: "user",
BasicAuthPassword: &options.SecretSource{
Value: []byte("secret"),
FromEnv: "UNKNOWN_ENV",
},
},
},
@@ -157,7 +157,7 @@ var _ = Describe("Headers", func() {
validHeader1,
},
expectedMsgs: []string{
"invalid header \"With-Invalid-Basic-Auth\": invalid values: invalid basicAuthPassword: error decoding secret value: illegal base64 data at input byte 4",
"invalid header \"With-Invalid-Basic-Auth\": invalid values: invalid basicAuthPassword: error loading secret from environent: no value for for key \"UNKNOWN_ENV\"",
},
}),
)