SecretSource.Value should be plain text in memory
This commit is contained in:
parent
d587030019
commit
5b003a5657
|
|
@ -515,7 +515,7 @@ func TestBasicAuthPassword(t *testing.T) {
|
||||||
ClaimSource: &options.ClaimSource{
|
ClaimSource: &options.ClaimSource{
|
||||||
Claim: "email",
|
Claim: "email",
|
||||||
BasicAuthPassword: &options.SecretSource{
|
BasicAuthPassword: &options.SecretSource{
|
||||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte(basicAuthPassword))),
|
Value: []byte(basicAuthPassword),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -1408,7 +1408,7 @@ func TestAuthOnlyEndpointSetBasicAuthTrueRequestHeaders(t *testing.T) {
|
||||||
ClaimSource: &options.ClaimSource{
|
ClaimSource: &options.ClaimSource{
|
||||||
Claim: "user",
|
Claim: "user",
|
||||||
BasicAuthPassword: &options.SecretSource{
|
BasicAuthPassword: &options.SecretSource{
|
||||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte("This is a secure password"))),
|
Value: []byte("This is a secure password"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package options
|
package options
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
@ -235,7 +234,7 @@ func getBasicAuthHeader(preferEmailToUser bool, basicAuthPassword string) Header
|
||||||
Claim: claim,
|
Claim: claim,
|
||||||
Prefix: "Basic ",
|
Prefix: "Basic ",
|
||||||
BasicAuthPassword: &SecretSource{
|
BasicAuthPassword: &SecretSource{
|
||||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte(basicAuthPassword))),
|
Value: []byte(basicAuthPassword),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package options
|
package options
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
|
|
@ -332,7 +331,7 @@ var _ = Describe("Legacy Options", func() {
|
||||||
Claim: "user",
|
Claim: "user",
|
||||||
Prefix: "Basic ",
|
Prefix: "Basic ",
|
||||||
BasicAuthPassword: &SecretSource{
|
BasicAuthPassword: &SecretSource{
|
||||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte(basicAuthSecret))),
|
Value: []byte(basicAuthSecret),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -372,7 +371,7 @@ var _ = Describe("Legacy Options", func() {
|
||||||
Claim: "email",
|
Claim: "email",
|
||||||
Prefix: "Basic ",
|
Prefix: "Basic ",
|
||||||
BasicAuthPassword: &SecretSource{
|
BasicAuthPassword: &SecretSource{
|
||||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte(basicAuthSecret))),
|
Value: []byte(basicAuthSecret),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -13,9 +12,7 @@ import (
|
||||||
func GetSecretValue(source *options.SecretSource) ([]byte, error) {
|
func GetSecretValue(source *options.SecretSource) ([]byte, error) {
|
||||||
switch {
|
switch {
|
||||||
case len(source.Value) > 0 && source.FromEnv == "" && source.FromFile == "":
|
case len(source.Value) > 0 && source.FromEnv == "" && source.FromFile == "":
|
||||||
value := make([]byte, base64.StdEncoding.DecodedLen(len(source.Value)))
|
return source.Value, nil
|
||||||
decoded, err := base64.StdEncoding.Decode(value, source.Value)
|
|
||||||
return value[:decoded], err
|
|
||||||
case len(source.Value) == 0 && source.FromEnv != "" && source.FromFile == "":
|
case len(source.Value) == 0 && source.FromEnv != "" && source.FromFile == "":
|
||||||
return []byte(os.Getenv(source.FromEnv)), nil
|
return []byte(os.Getenv(source.FromEnv)), nil
|
||||||
case len(source.Value) == 0 && source.FromEnv == "" && source.FromFile != "":
|
case len(source.Value) == 0 && source.FromEnv == "" && source.FromFile != "":
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -31,20 +30,12 @@ var _ = Describe("GetSecretValue", func() {
|
||||||
os.RemoveAll(fileDir)
|
os.RemoveAll(fileDir)
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns the correct value from base64", func() {
|
It("returns the correct value from the string value", func() {
|
||||||
originalValue := []byte("secret-value-1")
|
|
||||||
b64Value := base64.StdEncoding.EncodeToString((originalValue))
|
|
||||||
|
|
||||||
// Once encoded, the originalValue could have a decoded length longer than
|
|
||||||
// its actual length, ensure we trim this.
|
|
||||||
// This assertion ensures we are testing the triming
|
|
||||||
Expect(len(originalValue)).To(BeNumerically("<", base64.StdEncoding.DecodedLen(len(b64Value))))
|
|
||||||
|
|
||||||
value, err := GetSecretValue(&options.SecretSource{
|
value, err := GetSecretValue(&options.SecretSource{
|
||||||
Value: []byte(b64Value),
|
Value: []byte("secret-value-1"),
|
||||||
})
|
})
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(value).To(Equal(originalValue))
|
Expect(string(value)).To(Equal("secret-value-1"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns the correct value from the environment", func() {
|
It("returns the correct value from the environment", func() {
|
||||||
|
|
|
||||||
|
|
@ -49,14 +49,14 @@ var _ = Describe("Injector Suite", func() {
|
||||||
},
|
},
|
||||||
expectedErr: nil,
|
expectedErr: nil,
|
||||||
}),
|
}),
|
||||||
Entry("with a static valued header from base64", newInjectorTableInput{
|
Entry("with a static valued header from string", newInjectorTableInput{
|
||||||
headers: []options.Header{
|
headers: []options.Header{
|
||||||
{
|
{
|
||||||
Name: "Secret",
|
Name: "Secret",
|
||||||
Values: []options.HeaderValue{
|
Values: []options.HeaderValue{
|
||||||
{
|
{
|
||||||
SecretSource: &options.SecretSource{
|
SecretSource: &options.SecretSource{
|
||||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte("super-secret"))),
|
Value: []byte("super-secret"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -200,7 +200,7 @@ var _ = Describe("Injector Suite", func() {
|
||||||
ClaimSource: &options.ClaimSource{
|
ClaimSource: &options.ClaimSource{
|
||||||
Claim: "user",
|
Claim: "user",
|
||||||
BasicAuthPassword: &options.SecretSource{
|
BasicAuthPassword: &options.SecretSource{
|
||||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte("basic-password"))),
|
Value: []byte("basic-password"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -349,7 +349,7 @@ var _ = Describe("Injector Suite", func() {
|
||||||
ClaimSource: &options.ClaimSource{
|
ClaimSource: &options.ClaimSource{
|
||||||
Claim: "user",
|
Claim: "user",
|
||||||
BasicAuthPassword: &options.SecretSource{
|
BasicAuthPassword: &options.SecretSource{
|
||||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte("basic-password"))),
|
Value: []byte("basic-password"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -380,17 +380,17 @@ var _ = Describe("Injector Suite", func() {
|
||||||
Values: []options.HeaderValue{
|
Values: []options.HeaderValue{
|
||||||
{
|
{
|
||||||
SecretSource: &options.SecretSource{
|
SecretSource: &options.SecretSource{
|
||||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte("major=1"))),
|
Value: []byte("major=1"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
SecretSource: &options.SecretSource{
|
SecretSource: &options.SecretSource{
|
||||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte("minor=2"))),
|
Value: []byte("minor=2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
SecretSource: &options.SecretSource{
|
SecretSource: &options.SecretSource{
|
||||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte("patch=3"))),
|
Value: []byte("patch=3"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package validation
|
package validation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
|
@ -13,7 +12,7 @@ const multipleValuesForSecretSource = "multiple values specified for secret sour
|
||||||
func validateSecretSource(source options.SecretSource) string {
|
func validateSecretSource(source options.SecretSource) string {
|
||||||
switch {
|
switch {
|
||||||
case len(source.Value) > 0 && source.FromEnv == "" && source.FromFile == "":
|
case len(source.Value) > 0 && source.FromEnv == "" && source.FromFile == "":
|
||||||
return validateSecretSourceValue(source.Value)
|
return ""
|
||||||
case len(source.Value) == 0 && source.FromEnv != "" && source.FromFile == "":
|
case len(source.Value) == 0 && source.FromEnv != "" && source.FromFile == "":
|
||||||
return validateSecretSourceEnv(source.FromEnv)
|
return validateSecretSourceEnv(source.FromEnv)
|
||||||
case len(source.Value) == 0 && source.FromEnv == "" && source.FromFile != "":
|
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 {
|
func validateSecretSourceEnv(key string) string {
|
||||||
if value := os.Getenv(key); value == "" {
|
if value := os.Getenv(key); value == "" {
|
||||||
return fmt.Sprintf("error loading secret from environent: no value for for key %q", key)
|
return fmt.Sprintf("error loading secret from environent: no value for for key %q", key)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package validation
|
package validation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
|
@ -17,7 +16,7 @@ var _ = Describe("Common", func() {
|
||||||
var validSecretSourceFile string
|
var validSecretSourceFile string
|
||||||
|
|
||||||
BeforeEach(func() {
|
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())
|
Expect(os.Setenv(validSecretSourceEnv, "This is a secret source env")).To(Succeed())
|
||||||
tmp, err := ioutil.TempFile("", "oauth2-proxy-secret-source-test")
|
tmp, err := ioutil.TempFile("", "oauth2-proxy-secret-source-test")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
@ -110,14 +109,6 @@ var _ = Describe("Common", func() {
|
||||||
},
|
},
|
||||||
expectedMsg: "",
|
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{
|
Entry("with an invalid FromEnv", validateSecretSourceTableInput{
|
||||||
source: func() options.SecretSource {
|
source: func() options.SecretSource {
|
||||||
return options.SecretSource{
|
return options.SecretSource{
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ var _ = Describe("Headers", func() {
|
||||||
ClaimSource: &options.ClaimSource{
|
ClaimSource: &options.ClaimSource{
|
||||||
Claim: "user",
|
Claim: "user",
|
||||||
BasicAuthPassword: &options.SecretSource{
|
BasicAuthPassword: &options.SecretSource{
|
||||||
Value: []byte("secret"),
|
FromEnv: "UNKNOWN_ENV",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -157,7 +157,7 @@ var _ = Describe("Headers", func() {
|
||||||
validHeader1,
|
validHeader1,
|
||||||
},
|
},
|
||||||
expectedMsgs: []string{
|
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\"",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue