mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2026-10-17 20:17:03 +02:00
SecretSource.Value should be plain text in memory
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -235,7 +234,7 @@ func getBasicAuthHeader(preferEmailToUser bool, basicAuthPassword string) Header
|
||||
Claim: claim,
|
||||
Prefix: "Basic ",
|
||||
BasicAuthPassword: &SecretSource{
|
||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte(basicAuthPassword))),
|
||||
Value: []byte(basicAuthPassword),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
@@ -332,7 +331,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
Claim: "user",
|
||||
Prefix: "Basic ",
|
||||
BasicAuthPassword: &SecretSource{
|
||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte(basicAuthSecret))),
|
||||
Value: []byte(basicAuthSecret),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -372,7 +371,7 @@ var _ = Describe("Legacy Options", func() {
|
||||
Claim: "email",
|
||||
Prefix: "Basic ",
|
||||
BasicAuthPassword: &SecretSource{
|
||||
Value: []byte(base64.StdEncoding.EncodeToString([]byte(basicAuthSecret))),
|
||||
Value: []byte(basicAuthSecret),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -13,9 +12,7 @@ import (
|
||||
func GetSecretValue(source *options.SecretSource) ([]byte, error) {
|
||||
switch {
|
||||
case len(source.Value) > 0 && source.FromEnv == "" && source.FromFile == "":
|
||||
value := make([]byte, base64.StdEncoding.DecodedLen(len(source.Value)))
|
||||
decoded, err := base64.StdEncoding.Decode(value, source.Value)
|
||||
return value[:decoded], err
|
||||
return source.Value, nil
|
||||
case len(source.Value) == 0 && source.FromEnv != "" && source.FromFile == "":
|
||||
return []byte(os.Getenv(source.FromEnv)), nil
|
||||
case len(source.Value) == 0 && source.FromEnv == "" && source.FromFile != "":
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
@@ -31,20 +30,12 @@ var _ = Describe("GetSecretValue", func() {
|
||||
os.RemoveAll(fileDir)
|
||||
})
|
||||
|
||||
It("returns the correct value from base64", 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))))
|
||||
|
||||
It("returns the correct value from the string value", func() {
|
||||
value, err := GetSecretValue(&options.SecretSource{
|
||||
Value: []byte(b64Value),
|
||||
Value: []byte("secret-value-1"),
|
||||
})
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user