Repository navigation
Annotations: Use dedicated regular expression for proxy-cookie-domain. - #14536
Conversation
|
Welcome @mhbahmani! |
|
Hi @mhbahmani. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Gacko
left a comment
There was a problem hiding this comment.
Your change currently breaks existing tests, please check why this is the case (ideally without changing those tests, as we otherwise risk a regression).
It's fixed now. I would be happy to get your opinion and improve the validations if it worth it. |
| // This combination can also be used on fields that may contain characters like / (as ns/name) | ||
| BasicCharsRegex = regexp.MustCompile("^[/" + alphaNumericChars + "]*$") | ||
| // CookieDomainRegex validates proxy cookie domain: either "off" or two space-separated tokens (e.g. domain replacement) | ||
| CookieDomainRegex = regexp.MustCompile("^(off|[/" + alphaNumericChars + "]+\\s[" + alphaNumericChars + "]+)$") |
There was a problem hiding this comment.
This is a regular expression specific to a single annotation, while the other regular expressions are more generic. So please place this one close to the actual annotation instead.
Also please consider the documentation of this directive: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cookie_domain.
There it states you could even use a regular expression as a value. But yes, overall it should be either off or domain replacement and I don't think NGINX really cares about the amount of whitespaces, so I'd be rather safe than sorry and allow multiple of them.
What makes me wonder: alphaNumericChars does not contain whitespaces. I assume this only works because of the removeSpace parameter in parser.ValidateRegex, right?
There was a problem hiding this comment.
Since I was using alphaNumericChars, I defined CookieDomainRegex here. Your'e right, I move it to somewhere near the usage.
Yes this config accepts regex values in nginx, but currently ingress doesn't support regex values. Using regex fails the validation here:
ingress-nginx/internal/ingress/annotations/parser/validators.go
Lines 241 to 244 in 26549c1
And silently sets
off here:ingress-nginx/internal/ingress/annotations/proxy/main.go
Lines 314 to 317 in 26549c1
As this behaivour (not rejecting the ingress crd and setting a default value in nginx config) is being used in multiple scenarios, it seems that it's a design desicion and I don't know if it's a good idea to change it here, even though as an ingress user I prefer to get rejected at CRD apply step :) (At least for simple cases this. For more complicated scenarios like snippets it faces some challenges that maybe they are out of the scope of ingress) and I would happy to work on this.
And yes, it works in current version because of removeSpace being set to true.
The main reason that I made this PR is for supporting cases where a value for proxy_cookie_domain is not valid to nginx and leads to breaking the nginx, but it passes the ingress validation. But if you think It should prevent the ingress being applied, I can work on it and come up with some more resilient and comprehensive changes.
There was a problem hiding this comment.
No, no, all good. I just wanted to make sure your change is not restricting anyone. But since any other value other than these allowed by your regular expression would either have been rejected or broke NGINX configuration before, it's fine. 🙂
There was a problem hiding this comment.
Got it. Thanks.
Just to clarify, do you see incompatibilities like these with nginx, or the permissiveness in Ingress validation on ingress CRDs, as an area for improvement? Or do these fallbacks to default values tend to be the way they are by design? I think instead of falling back to default values, Ingress could reject or show a warning when applying such configurations.
Just want to know if it's worth putting time into or not :)
There was a problem hiding this comment.
I don't think it's worth it. This project is going to get retired end of month, so I'd rather not introduce such a change in behavior anymore.
Gacko
left a comment
There was a problem hiding this comment.
Still please move the new regular expression to where it's being used and maybe consider allowing multiple whitespaces (if NGINX would also tolerate that) including a test case. Everything else looks fine!
|
/retitle Annotations: Use dedicated regular expression for |
proxy-cookie-domain.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Gacko, mhbahmani The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/ok-to-test |
|
/cherry-pick release-1.14 |
|
/cherry-pick release-1.13 |
|
@Gacko: new pull request created: #14550 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@Gacko: new pull request created: #14551 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
What this PR does / why we need it:
Now, proxy-cookie-domain accepts values like "example.com" (only one domain) which brokes nginx and blocks nginx reloading. This would lead to ingress not getting reloaded and configurations doesn't get applied.
This PR tightens validation for the proxy-cookie-domain annotation so it only allows:
Types of changes
Which issue/s this PR fixes
I did not find a related issue.
Checklist: