What happened:
When attempting to activate annotation validation, we realised that the permanent-redirect annotation has been broken due to a lack of support for capture groups.
We are attempting to redirect to a new domain but keep the existing path. I expect this to work by having a nginx config something along these lines:
server {
. . .
server_name domain1.com;
rewrite ^/(.*)$ http://domain2.com/$1 permanent;
. . .
}
We've tried a few different variations of this, but can't find a documented way to achieve this, however the following should work based on my understanding:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-redirect
annotations:
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/permanent-redirect: https://domain2\.com/$1
spec:
rules:
- host: domain1.com
http:
paths:
- path: /(.*)
pathType: ImplementationSpecific
backend:
...
This gets denied by the admission controller as the permanent-redirect annotation contains an invalid word (or value if the . isn't escaped). Though even this leaves open the case of no path existing, which we'd also need redirected tbh.
What you expected to happen:
I'd expect capture groups and just in general regexes to work as intended for permanent-redirect.
I guess part of the issue lies in this line: Validator: parser.ValidateRegex(parser.URLIsValidRegex, false),, which isn't passing capture groups to the validator (https://github.com/kubernetes/ingress-nginx/blob/45f8262d052ee0da6133d886ec90f1fbd7a19e3b/internal/ingress/annotations/redirect/redirect.go#L64C29-L64C29 as comparted to redirect's https://github.com/kubernetes/ingress-nginx/blob/main/internal/ingress/annotations/rewrite/main.go#L43C1-L43C1).
NGINX Ingress controller version (exec into the pod and run nginx-ingress-controller --version.): 1.9.4 chroot
Kubernetes version (use kubectl version): 1.27.7
Environment: Azure AKS w/ FluxCD gitops deployment
How to reproduce this issue:
- Install the ingress controller with annotation validation active
- Create an ingress with an example domain1 -> domain2 redirect like above
What happened:
When attempting to activate annotation validation, we realised that the permanent-redirect annotation has been broken due to a lack of support for capture groups.
We are attempting to redirect to a new domain but keep the existing path. I expect this to work by having a nginx config something along these lines:
We've tried a few different variations of this, but can't find a documented way to achieve this, however the following should work based on my understanding:
This gets denied by the admission controller as the permanent-redirect annotation contains an invalid word (or value if the
.isn't escaped). Though even this leaves open the case of no path existing, which we'd also need redirected tbh.What you expected to happen:
I'd expect capture groups and just in general regexes to work as intended for
permanent-redirect.I guess part of the issue lies in this line:
Validator: parser.ValidateRegex(parser.URLIsValidRegex, false),, which isn't passing capture groups to the validator (https://github.com/kubernetes/ingress-nginx/blob/45f8262d052ee0da6133d886ec90f1fbd7a19e3b/internal/ingress/annotations/redirect/redirect.go#L64C29-L64C29 as comparted toredirect's https://github.com/kubernetes/ingress-nginx/blob/main/internal/ingress/annotations/rewrite/main.go#L43C1-L43C1).NGINX Ingress controller version (exec into the pod and run nginx-ingress-controller --version.): 1.9.4 chroot
Kubernetes version (use
kubectl version): 1.27.7Environment: Azure AKS w/ FluxCD gitops deployment
Cloud provider or hardware configuration: Azure
How was the ingress-nginx-controller installed:
How to reproduce this issue: