docs: clarify that auth-headers-* keys need to be in lowercase#1429
docs: clarify that auth-headers-* keys need to be in lowercase#1429nadiamoe wants to merge 1 commit intojcmoraisjr:masterfrom
Conversation
This is unfortunately not mentioned in https://github.com/TimWolla/haproxy-auth-request/tree/main, but after some debugging I think this is what is required. Specifying a list of headers using the case they're returned as will not work, while specifying them in lowercase will. I have verified the casing of the headers via tcpdump. Moreover Authelia, a popular authentication backend, specifies the header names in lowercase in their example [here](https://github.com/authelia/authelia/blob/c6a84aaac6eb65f2aa5cd50dcdb2a12e5a98abca/docs/content/integration/proxies/haproxy.md?plain=1#L244), despite Authelia itself returning them in Header-Case.
|
Hi, can you share if you faced some issue, and how you did your tests in a way that Camel-Case headers does not work? I'm a bit puzzled since per RFC-7230 HTTP headers are case insensitive, so it should work either way. |
|
I think headers are case insensitive, but the search that https://github.com/TimWolla/haproxy-auth-request does is not. This function here converts the comma-separated list into a lua pattern: https://github.com/TimWolla/haproxy-auth-request/blob/cdb891cf52995780bb6128c2a7495d36325e4ff2/auth-request.lua#L38 and then gmatch is used here: https://github.com/TimWolla/haproxy-auth-request/blob/cdb891cf52995780bb6128c2a7495d36325e4ff2/auth-request.lua#L86 As far as I can tell, gmatch is case sensitive. At some other point in the pipeline something must be lowercasing the headers that haproxy-auth-request is seeing (I verified that authelia returns it with Header-Case using tcpdump), I'm not sure where that may be. |
|
Ah sure, you're right. I not only misunderstood your proposal, but also ignored that Lua's From my own tests I can (almost) confirm that However, my proposal instead is to change this in the code, giving a better user experience for one expecting http headers to be case insensitive: diff --git a/pkg/converters/ingress/annotations/backend.go b/pkg/converters/ingress/annotations/backend.go
index 52768257..56cfe73d 100644
--- a/pkg/converters/ingress/annotations/backend.go
+++ b/pkg/converters/ingress/annotations/backend.go
@@ -247,9 +247,9 @@ func (c *updater) setAuthExternal(config ConfigValueGetter, auth *hatypes.AuthEx
if annHdrFail == "" {
annHdrFail = "-"
}
- hdrRequest := strings.Split(annHdrRequest, ",")
- hdrSucceed := strings.Split(annHdrSucceed, ",")
- hdrFail := strings.Split(annHdrFail, ",")
+ hdrRequest := strings.Split(strings.ToLower(annHdrRequest), ",")
+ hdrSucceed := strings.Split(strings.ToLower(annHdrSucceed), ",")
+ hdrFail := strings.Split(strings.ToLower(annHdrFail), ",")
if signin != "" {
if !reflect.DeepEqual(hdrFail, []string{"*"}) {What do you think? From my side I'll double check my findings in order to ensure that we don't have some corner cases. |
|
@jcmoraisjr Changing the code looks even better to me! 🎉 |
|
Sure, a short sentence stating that "header match is case insensitive" looks good, as a quick reminder about the http spec. |
This is unfortunately not mentioned in https://github.com/TimWolla/haproxy-auth-request/tree/main, but after some debugging I think this is what is required. Specifying a list of headers using the case they're returned as will not work, while specifying them in lowercase will.
I have verified the casing of the headers via tcpdump. Moreover Authelia, a popular authentication backend, specifies the header names in lowercase in their example here, despite Authelia itself returning them in Header-Case.