Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions pkg/annotations/ingress/basicAuth.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ingress

import (
"bytes"
"fmt"
"strings"
"unicode"

"github.com/haproxytech/kubernetes-ingress/pkg/annotations/common"
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/rules"
Expand Down Expand Up @@ -76,15 +78,14 @@ func (a ReqAuthAnn) Process(k store.K8s, annotations ...map[string]string) (err
}
a.parent.authRule.Credentials = make(map[string][]byte)
for u, pwd := range secret.Data {
// If the pwd length is 0, we do not create the user in the userlist
pwd = bytes.TrimSpace(pwd)
// If the pwd is empty or has spaces, we do not create the user in the userlist
// This is not a valid setting
if len(pwd) > 0 {
if pwd[len(pwd)-1] == '\n' {
// logger.Warningf("Ingress %s/%s: basic-auth: password for user %s ends with '\\n'. Ignoring last character.", ingress.Namespace, ingress.Name, u)
pwd = pwd[:len(pwd)-1]
}
a.parent.authRule.Credentials[u] = pwd
if len(pwd) < 1 || bytes.ContainsFunc(pwd, unicode.IsSpace) {
logger.Warningf("Ingress %s/%s: basic-auth: password for user %s is empty or has spaces. Ignoring it.", a.parent.ingress.Namespace, a.parent.ingress.Name, u)
continue
}
a.parent.authRule.Credentials[u] = pwd
}
default:
err = fmt.Errorf("unknown auth-type annotation '%s'", a.name)
Expand Down