kubernetes-ingress
kubernetes-ingress copied to clipboard
Regular expressions with "?!" are not supported in VirtualServer
Describe the bug Regular expressions that contains "?!" not supported in path or routes and subroutes in VirtualServer and VirtualServerRoute resources.
To Reproduce
- Deploy yamls:
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
name: cafe
namespace: default
spec:
host: cafe.example.com
upstreams:
- name: tea
service: tea-svc
port: 80
routes:
- path: /tea
action:
pass: tea
- path: /coffee
route: default/coffee
apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
metadata:
name: coffee
namespace: default
spec:
host: cafe.example.com
upstreams:
- name: latte
service: latte-svc
port: 80
- name: espresso
service: espresso-svc
port: 80
subroutes:
- path: ~ ^/coffee/latte$ # it's works
action:
pass: latte
- path: ~ ^/coffee/(?!.*\/latte)(?!.*\/americano)(.*) # it isn't working
action:
pass: espresso
- View logs on ingress-controller pod
- See error:
I1223 08:46:01.744934 1 controller.go:1369] Skipping invalid VirtualServerRoute default/coffee: spec.subroutes[1].path: Invalid value: "~ ^/coffee/(?!.*\/latte)(?!.*\/americano)(.*)": must be a valid regular expression: error parsing regexp: invalid or unsupported Perl syntax: `(?!`
Expected behavior All regular expressions that work in bare nginx must work in path.
Your environment
- Version of the Ingress Controller - release version or a specific commit 1.6.0
- Version of Kubernetes 1.15.3
- Kubernetes platform (e.g. Mini-kube or GCP) bare kubernetes
- Using NGINX or NGINX Plus NGINX
Aha! Link: https://nginx.aha.io/features/IC-109
Hi @LuciferInLove thanks for reporting!
The supported regex syntax is currently limited by regular expressions supported in golang https://github.com/google/re2/wiki/Syntax
We might overcome this limitation in the future.
Are there any workaround regular expressions that you could use that can cover your case?
Are there any workaround regular expressions that you could use that can cover your case?
Unfortunately, no, but now I'm using bare nginx deployed in k8s with own customizations.
Ok. We'll keep the issue open to track this limitation.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Just a comment to leave this issue open.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Just a comment to leave this issue open.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.
Just a comment to leave this issue open.
I came across this issue recently. Seems kic should implement regex libraries that more closely matches that which NGINX uses, such as go pcre2.
any updates here? or any suggestions for work arounds?
We could also leverage the following libraries:
https://pkg.go.dev/github.com/s-kozlov/goback/regexp/syntax
https://pkg.go.dev/github.com/dlclark/regexp2#section-readme
test log:
I1003 13:52:25.597291 1 event.go:298] Event(v1.ObjectReference{Kind:"VirtualServer", Namespace:"default", Name:"cafe", UID:"eb5fa829-4f39-4cd1-973a-78282d2d76d2", APIVersion:"k8s.nginx.org/v1", ResourceVersion:"277941", FieldPath:""}): type: 'Warning' reason: 'AddedOrUpdatedWithWarning' Configuration for default/cafe was added or updated with warning(s): VirtualServerRoute default/coffee doesn't exist or invalid
I1003 13:52:46.350360 1 event.go:298] Event(v1.ObjectReference{Kind:"VirtualServerRoute", Namespace:"default", Name:"coffee", UID:"d9c0f987-02e7-4554-8a8e-6ac7088afa54", APIVersion:"k8s.nginx.org/v1", ResourceVersion:"277976", FieldPath:""}): type: 'Warning' reason: 'Rejected' VirtualServerRoute default/coffee was rejected with error: spec.subroutes[1].path: Invalid value: "~ ^/coffee/(?!.*\\/latte)(?!.*\\/americano)(.*)": must be a valid regular expression: error parsing regexp: invalid or unsupported Perl syntax: `(?!`
Employing regexp2
package that uses Perl5 / .NET compatible regex implementation engine solves the path validation problem.