kubernetes / ingress-nginx

Ingress NGINX Controller for Kubernetes
https://kubernetes.github.io/ingress-nginx/
Apache License 2.0
17.48k stars 8.25k forks source link

Regex expression checker incorrectly flags as invalid #5377

Closed dhrp closed 4 years ago

dhrp commented 4 years ago

NGINX Ingress controller version: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0

Kubernetes version (use kubectl version): v1.15.9-gke.24 (but I also tried on kubernetes 17.2)

Environment:

What happened: My (valid) regular expression is being refused. The Ingress "myingress" is invalid: spec.rules[0].http.paths[1].path: Invalid value: "/go(?:/|$)(.*)": must be a valid regex

Here is an example ingress spec, which includes the annotations

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: netbox
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
    - host: myhost.customers.greenedge.cloud
      http:
        paths:
          - path: /(.*)
            backend:
              serviceName: netbox-nginx
              servicePort: http
          - path: /go(?:/|$)(.*)
            backend:
              serviceName: netbox-extras
              servicePort: http

What you expected to happen: I expect the regular expression to be accepted.

The issue occurs when using the non-capturing group (?:re). It also happens with some other PCRE compatible regexes.

If you look at this issue, you'd expect that the regular expression is blocked by the ingress validator because it's not in the re2 spec. But it is actually there... You can test it here: https://regex-golang.appspot.com/assets/html/index.html

Now... I understand this issue should probably be filed (also) to whatever validates ingress on k8s, but I couldn't find the correct location for that.

How to reproduce it:

Anything else we need to know:

Would be happy to file this in the right location too, if someone can point me there.

/kind bug

aledbf commented 4 years ago

But it is actually there...

@dhrp the validation code is not located in ingress-nginx but in the kubernetes repository https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/networking/validation/validation.go#L382

aledbf commented 4 years ago

Closing. This is an issue in the main Kubernetes repository. There is nothing to do in ingress-nginx