Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kong router prefix matching different behavior due to regex_priority #7687

Closed
jiachinzhao opened this issue Aug 9, 2021 · 2 comments · Fixed by #7695
Closed

kong router prefix matching different behavior due to regex_priority #7687

jiachinzhao opened this issue Aug 9, 2021 · 2 comments · Fixed by #7695

Comments

@jiachinzhao
Copy link
Contributor

there are 2 route rule.

route1:
{ "hosts": ["foo.com"], "paths": ["/"], "regex_priority": 1 }

route2:
{ "hosts": ["foo.com"] "paths": ["/v1"], "regex_priority": 0 }

the following request will route to route2, correct behavior due to prefix matching choosing longest length.

GET /v1/xxx   HTTP/1.1
Host: foo.com

however, after adding another route things changed.
route3:
{ "hosts": ["bar.com"], "paths": ["/.*"], "regex_priority": 0 }

the same request will route to route1, which is an unexpected route behavior.

when I remove regex_priority from route1 and route2, the behavior is corret。

I think regex_priority cannot be used for routing rule sorting when using prefix matching which will sometimes make a mistake.

tested on Kong version 2.1.4
the behavior still exists on the latest version

@javierguerragiraldez javierguerragiraldez added core/router task/needs-investigation Requires investigation and reproduction before classifying it as a bug or not. labels Aug 9, 2021
@kikito kikito added pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc... and removed task/needs-investigation Requires investigation and reproduction before classifying it as a bug or not. labels Aug 9, 2021
@kikito
Copy link
Member

kikito commented Aug 9, 2021

when I remove regex_priority from route1 and route2, the behavior is corret。

That ... doesn't seem to be correct. ´regex_priority´ is used to disambiguate between two requests that both have regexes. In your example only one of them (route3) has regexes, so regex_priority should play no role.

Could you please provide a full list of the calls you are using, so we can reproduce?

Related:

@jiachinzhao
Copy link
Contributor Author

it can be easily reproduce on k8s
kong ingress controller 0.9.0
kong 2.1.4
apply 2 service and 3 ingress rules.

apiVersion: v1
kind: Service
metadata:
  name: my-service1
spec:
  selector:
    app: MyApp
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: my-service2
spec:
  selector:
    app: MyApp
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: route1
  annotations:
    kubernetes.io/ingress.class: kong-test
    konghq.com/regex-priority: "1"
spec:
  rules:
    - host: foo.com
      http:
        paths:
          - path: /
            backend:
              serviceName: my-service1
              servicePort: 8080
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: route2
  annotations:
    kubernetes.io/ingress.class: kong-test
    konghq.com/regex-priority: "0"
spec:
  rules:
    - host: foo.com
      http:
        paths:
          - path: /v1
            backend:
              serviceName: my-service1
              servicePort: 8080
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: route3
  annotations:
    kubernetes.io/ingress.class: kong-test
spec:
  rules:
    - host: bar.com
      http:
        paths:
          - path: /.*
            backend:
              serviceName: my-service2
              servicePort: 8080

http request with kong_debug

curl -I -H 'kong_debug: true'  -H 'host: foo.com'  ${kong_pod_ip}:8080/v1/pong 
the  route_id will be different in response_header  between ingress route3 apply or not。
ingress route3 apply:   route_id belong to route1
ingress route3 delete:  route_id belong to route2

@kikito kikito removed the pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc... label Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants