Skip to content

Commit

Permalink
Merge pull request #972 from jcmoraisjr/jm-not-copy-headers
Browse files Browse the repository at this point in the history
Makes auth-headers not copying on empty string
  • Loading branch information
jcmoraisjr authored Dec 10, 2022
2 parents 3e28fb2 + 742322c commit 4862b87
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/content/en/docs/configuration/keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ There are three distinct configurations to forward header names:

The first option will always be used, the second one only on succeeded requests, the last one only on failures.

These configuration keys can be defined as a comma-separated list of header names. All HTTP headers will be copied if not declared. Each header name can use wildcard.
These configuration keys can be defined as a comma-separated list of header names. All HTTP headers will be copied if not declared. Each header name can use wildcard. Using a dash `-` or an empty string instructs the controller not to copy any header.

Configuration examples:

Expand Down
18 changes: 15 additions & 3 deletions pkg/converters/ingress/annotations/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,21 @@ func (c *updater) buildBackendAuthExternal(d *backData) {
signin = ""
}

hdrRequest := strings.Split(config.Get(ingtypes.BackAuthHeadersRequest).Value, ",")
hdrSucceed := strings.Split(config.Get(ingtypes.BackAuthHeadersSucceed).Value, ",")
hdrFail := strings.Split(config.Get(ingtypes.BackAuthHeadersFail).Value, ",")
annHdrRequest := config.Get(ingtypes.BackAuthHeadersRequest).Value
if annHdrRequest == "" {
annHdrRequest = "-"
}
annHdrSucceed := config.Get(ingtypes.BackAuthHeadersSucceed).Value
if annHdrSucceed == "" {
annHdrSucceed = "-"
}
annHdrFail := config.Get(ingtypes.BackAuthHeadersFail).Value
if annHdrFail == "" {
annHdrFail = "-"
}
hdrRequest := strings.Split(annHdrRequest, ",")
hdrSucceed := strings.Split(annHdrSucceed, ",")
hdrFail := strings.Split(annHdrFail, ",")

if signin != "" {
if !reflect.DeepEqual(hdrFail, []string{"*"}) {
Expand Down
20 changes: 17 additions & 3 deletions pkg/converters/ingress/annotations/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ func TestAuthExternal(t *testing.T) {
hdrReq string
hdrSucceed string
hdrFail string
hdrEmpty bool
isExternal bool
hasLua bool
expBack hatypes.AuthExternal
Expand Down Expand Up @@ -464,6 +465,19 @@ func TestAuthExternal(t *testing.T) {
expIP: []string{"10.0.0.2:80"},
logging: `WARN invalid request method '**' on ingress 'default/ing1', using GET instead`,
},
// 27
{
url: "http://app1.local",
hdrEmpty: true,
expBack: hatypes.AuthExternal{
AuthBackendName: "_auth_4001",
AuthPath: "/",
HeadersRequest: []string{"-"},
HeadersSucceed: []string{"-"},
HeadersFail: []string{"-"},
},
expIP: []string{"10.0.0.2:80"},
},
}
source := &Source{
Namespace: "default",
Expand Down Expand Up @@ -500,13 +514,13 @@ func TestAuthExternal(t *testing.T) {
if test.method != "" {
ann["/"][ingtypes.BackAuthMethod] = test.method
}
if test.hdrReq != "" {
if test.hdrEmpty || test.hdrReq != "" {
ann["/"][ingtypes.BackAuthHeadersRequest] = test.hdrReq
}
if test.hdrSucceed != "" {
if test.hdrEmpty || test.hdrSucceed != "" {
ann["/"][ingtypes.BackAuthHeadersSucceed] = test.hdrSucceed
}
if test.hdrFail != "" {
if test.hdrEmpty || test.hdrFail != "" {
ann["/"][ingtypes.BackAuthHeadersFail] = test.hdrFail
}
defaults := map[string]string{
Expand Down

0 comments on commit 4862b87

Please sign in to comment.