Skip to content

Commit

Permalink
fix: conditions to retrieve bindPassword adn cacheKey from secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
thpiron committed Aug 23, 2023
1 parent 74d2293 commit a28a99d
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions ldapauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/gorilla/sessions"
)

const defaultCacheKey = "super-secret-key"

// nolint
var (
store *sessions.CookieStore
Expand Down Expand Up @@ -79,7 +81,7 @@ func CreateConfig() *Config {
CacheCookieName: "ldapAuth_session_token",
CacheCookiePath: "",
CacheCookieSecure: false,
CacheKey: "super-secret-key",
CacheKey: defaultCacheKey,
CacheKeyLabel: "LDAP_AUTH_CACHE_KEY",
StartTLS: false,
CertificateAuthority: "",
Expand Down Expand Up @@ -117,19 +119,16 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
LoggerINFO.Printf("Starting %s Middleware...", name)

if config.BindDN != "" && config.BindPassword == "" {
bindPasswordLabel := "LDAP_AUTH_BIND_PASSWORD"
if config.BindPasswordLabel != "" {
bindPasswordLabel = config.BindPasswordLabel
}
config.BindPassword = getSecret(bindPasswordLabel)
config.BindPassword = getSecret(config.BindPasswordLabel)
}

if config.CacheKey != "" {
cacheKeyLabel := "LDAP_AUTH_CACHE_KEY"
if config.CacheKeyLabel != "" {
cacheKeyLabel = config.CacheKeyLabel
// if CacheKey is the default value we try to set it from secret
if config.CacheKey == defaultCacheKey {
cacheKey := getSecret(config.CacheKeyLabel)
// we could not retrieve the secret, so we keep the default value
if cacheKey != "" {
config.CacheKey = cacheKey
}
config.CacheKey = getSecret(cacheKeyLabel)
}

LogConfigParams(config)
Expand Down

0 comments on commit a28a99d

Please sign in to comment.