Skip to content

Change route sorting order to Exact > RegularExpression > PathPrefix#2579

Merged
arkodg merged 4 commits intoenvoyproxy:mainfrom
vixns:routeprecedence
Apr 5, 2024
Merged

Change route sorting order to Exact > RegularExpression > PathPrefix#2579
arkodg merged 4 commits intoenvoyproxy:mainfrom
vixns:routeprecedence

Conversation

@vixns
Copy link
Copy Markdown
Contributor

@vixns vixns commented Feb 8, 2024

What type of PR is this?

fix

What this PR does / why we need it:

Like kubernetes-sigs/gateway-api#1770, I've encountered a case when converting the following ingress definition:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: sentry
  namespace: sentry
spec:
  tls:
    - hosts:
        - sentry.selfhosted.tld
  rules:
    - host: sentry.selfhosted.tld
      http:
        paths:
          - path: /api/store
            pathType: ImplementationSpecific
            backend:
              service:
                name: sentry-relay
                port:
                  number: 3000
          - path: /api/[1-9][0-9]*/(.*)
            pathType: ImplementationSpecific
            backend:
              service:
                name: sentry-relay
                port:
                  number: 3000
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: sentry-web
                port:
                  number: 9000

to

apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: sentry
  namespace: sentry
spec:
  hostnames:
    - sentry.selfhosted.tld
  parentRefs:
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: eg
      sectionName: https
  rules:
    - backendRefs:
        - group: ''
          kind: Service
          name: sentry-relay
          port: 3000
          weight: 1
      matches:
        - path:
            type: PathPrefix
            value: /api/store
        - path:
            type: RegularExpression
            value: ^/api/[1-9][0-9]*/.*$
    - backendRefs:
        - group: ''
          kind: Service
          name: sentry-web
          port: 9000
          weight: 1
      matches:
        - path:
            type: PathPrefix
            value: /

The RegularExpression is never matched because the PathPrefixes takes precedence

Based on Note: The precedence of RegularExpression path matches are implementation-specific. (kubernetes-sigs/gateway-api#1855), I propose in this PR to changes the route precedence order from Exact > PathPrefix > RegularExpression to Exact > RegularExpression > PathPrefix

@vixns vixns requested a review from a team as a code owner February 8, 2024 11:24
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 10, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 66.47%. Comparing base (dd034a0) to head (ac71a96).

Files Patch % Lines
internal/gatewayapi/sort.go 70.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2579      +/-   ##
==========================================
+ Coverage   66.45%   66.47%   +0.02%     
==========================================
  Files         161      161              
  Lines       22650    22650              
==========================================
+ Hits        15051    15057       +6     
+ Misses       6723     6720       -3     
+ Partials      876      873       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vixns vixns force-pushed the routeprecedence branch 8 times, most recently from ea0eae2 to 8eda561 Compare February 23, 2024 09:06
@vixns vixns force-pushed the routeprecedence branch 2 times, most recently from c55b35a to 751fabd Compare February 27, 2024 07:33
@vixns vixns force-pushed the routeprecedence branch 4 times, most recently from 5a89705 to 669573f Compare March 10, 2024 07:06
@vixns vixns force-pushed the routeprecedence branch 2 times, most recently from 48872a2 to a473d17 Compare March 16, 2024 09:19
@vixns vixns force-pushed the routeprecedence branch from a473d17 to c883718 Compare March 23, 2024 12:49
@vixns
Copy link
Copy Markdown
Contributor Author

vixns commented Mar 23, 2024

/retest

@zirain
Copy link
Copy Markdown
Member

zirain commented Mar 24, 2024

@arkodg I recall we discussed offline, should EG provide an API about matching order?

@arkodg
Copy link
Copy Markdown
Contributor

arkodg commented Mar 24, 2024

met @vixns at Kubecon EU who brought this up in person :)
Lets gather some more info on why ingress-nginx and contour prioritize regex over prefix
@AliceProxy curious to know what Emissary does ?
@zirain do you know what Istio does ?

@arkodg
Copy link
Copy Markdown
Contributor

arkodg commented Mar 26, 2024

finally took a look at the config in the PR where PathPrefix

            type: PathPrefix
            value: /

is used as a fallback

This implies that if EG wants to promote or allow this usage of PathPrefix, we need to change the precendance ordering to Exact > RegularExpression > PathPrefix and ask users to build very strict and scoped regex matches

@arkodg
Copy link
Copy Markdown
Contributor

arkodg commented Mar 26, 2024

hey @vixns added some suggestions, mainly around code style for this function

@arkodg
Copy link
Copy Markdown
Contributor

arkodg commented Mar 26, 2024

should we also consider cherrypicking this into v1.0 ?
cc @envoyproxy/gateway-maintainers

@zirain
Copy link
Copy Markdown
Member

zirain commented Mar 26, 2024

met @vixns at Kubecon EU who brought this up in person :) Lets gather some more info on why ingress-nginx and contour prioritize regex over prefix @AliceProxy curious to know what Emissary does ? @zirain do you know what Istio does ?

I found istio may has an issue when converting this, let me double check first.

@zirain
Copy link
Copy Markdown
Member

zirain commented Mar 26, 2024

@arkodg
Copy link
Copy Markdown
Contributor

arkodg commented Apr 4, 2024

@zirain imo RegularExpression > PathPrefix because users tend to use PathPrefix as a catchall

@vixns vixns force-pushed the routeprecedence branch from c883718 to 71dc110 Compare April 4, 2024 14:30
@vixns
Copy link
Copy Markdown
Contributor Author

vixns commented Apr 4, 2024

Hi @arkodg, it was nice to met in Paris.
I've updated the code style as asked.

Yes this precedence change is mainly for catchalls, which are a very common and imo should be easy to read and write.
To illustrate this PR's motivation, how would you write the catchall from the HTTProute in this PR's description without changing the precedence order ?

@vixns vixns force-pushed the routeprecedence branch 2 times, most recently from b694eba to 2d4a4da Compare April 4, 2024 14:50
arkodg
arkodg previously approved these changes Apr 4, 2024
Copy link
Copy Markdown
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks !

@arkodg arkodg requested review from a team April 4, 2024 15:01
@arkodg
Copy link
Copy Markdown
Contributor

arkodg commented Apr 4, 2024

@envoyproxy/gateway-maintainers should we back port this to v1.0 ?

@vixns
Copy link
Copy Markdown
Contributor Author

vixns commented Apr 4, 2024

/retest

@arkodg arkodg requested review from a team April 5, 2024 10:52
vixns added 4 commits April 5, 2024 14:25
Signed-off-by: Stéphane Cottin <stephane.cottin@vixns.com>
Signed-off-by: Stéphane Cottin <stephane.cottin@vixns.com>
Signed-off-by: Stéphane Cottin <stephane.cottin@vixns.com>
@vixns vixns force-pushed the routeprecedence branch from c3440b9 to ac71a96 Compare April 5, 2024 12:25
@zirain
Copy link
Copy Markdown
Member

zirain commented Apr 5, 2024

@zirain imo RegularExpression > PathPrefix because users tend to use PathPrefix as a catchall

istio had a special handler about catchall.

@arkodg
Copy link
Copy Markdown
Contributor

arkodg commented Apr 5, 2024

The client timeout e2e test seems to be failing

@arkodg arkodg merged commit 11f56fd into envoyproxy:main Apr 5, 2024
@zirain
Copy link
Copy Markdown
Member

zirain commented Apr 6, 2024

The client timeout e2e test seems to be failing

maybe we should disable it first, I can find out a way to make it stable now.

@arkodg
Copy link
Copy Markdown
Contributor

arkodg commented Apr 6, 2024

The client timeout e2e test seems to be failing

maybe we should disable it first, I can find out a way to make it stable now.

+1, thanks @zirain !

arkodg pushed a commit to arkodg/gateway that referenced this pull request Apr 8, 2024
…nvoyproxy#2579)

* Change route sorting order to Exact > RegularExpression > PathPrefix

kubernetes-sigs/gateway-api#1770
kubernetes-sigs/gateway-api#1855

Signed-off-by: Stéphane Cottin <stephane.cottin@vixns.com>
(cherry picked from commit 11f56fd)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>
Xunzhuo added a commit that referenced this pull request Apr 8, 2024
* Run certgen when upgrading (#2934)

run certgen when upgrading

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
(cherry picked from commit 62ecf15)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* Fix: nil secret in resourceversiontable (#2982)

* fix nil secret in resourceversiontable

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* check secrets in the xds result

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

---------

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
(cherry picked from commit e880439)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* fix: add missing http filters to the http filter chain (#2970)

* fix: add missing http filters to the http filter chain

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* refactor

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* fix lint

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* add comments

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* remove refactor

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* remove refactor

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* fix gen

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* fix lint

Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>

---------

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
(cherry picked from commit f699edf)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* fix: allow websockets in url rewrite (#3022)

allow websockets in url rewrite

Signed-off-by: Jesse Haka <haka.jesse@gmail.com>
Co-authored-by: zirain <zirain2009@gmail.com>
(cherry picked from commit 3d51933)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* Set host for http health checker explicitly to avoid using the cluster name as host header for http health checking request. (#3057)

* Set host for http health checker explictly to avoid using the cluster name as host header for http health checking request

Signed-off-by: lemonlinger <lemonlinger@gmail.com>

* fix broken tests

Signed-off-by: lemonlinger <lemonlinger@gmail.com>

* fix health-check test case in xds translation

Signed-off-by: lemonlinger <lemonlinger@gmail.com>

* Simplify code and concise comments

Signed-off-by: lemonlinger <lemonlinger@gmail.com>

---------

Signed-off-by: lemonlinger <lemonlinger@gmail.com>
(cherry picked from commit 8f450a9)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* fix: do not create infra resources when missing translated listeners (#3043)

* fix: do not create infra resources when missing translated listeners

Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>

* remove empty line

Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>

* skip infra creation on empty listeners and log it

Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>

---------

Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>
(cherry picked from commit 36d7141)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* Fix: double slashes in redirect URL (#2998)

* fix: double trailing splashs in redirect URL

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* add e2e tests

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* fix lint

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* fix test

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* fix test

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* fix test

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* fix test

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* add e2e tests

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* fix test

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* revert

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* use regex rewrite to generate the redirect url

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* use regex rewrite to generate the redirect url

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* use regex rewrite to generate the redirect url

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* remove comments

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* extract method

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* address comments

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

---------

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
(cherry picked from commit ceb697f)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* fix: Allow Policy to attach to multiple http listeners  (#2967)

* Fixing the clienttrafficpolicy validation.

Signed-off-by: Lior Okman <lior.okman@sap.com>

* Make SecurityPolicy validate correctly.

Signed-off-by: Lior Okman <lior.okman@sap.com>

* Reverted the SecurityPolicy validation - handled differently via
another feature.

Signed-off-by: Lior Okman <lior.okman@sap.com>

* Updated the tests to reflect that this validation isn't required for SecurityPolicy

Signed-off-by: Lior Okman <lior.okman@sap.com>

* Added some comments to explain the validation being performed.

Signed-off-by: Lior Okman <lior.okman@sap.com>

* Updated the error message as requested in the review.

Signed-off-by: Lior Okman <lior.okman@sap.com>

---------

Signed-off-by: Lior Okman <lior.okman@sap.com>
(cherry picked from commit f9409e4)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* fix: set path prefix for http ext auth service (#3018)

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
(cherry picked from commit 2882b7c)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* Change route sorting order to Exact > RegularExpression > PathPrefix (#2579)

* Change route sorting order to Exact > RegularExpression > PathPrefix

kubernetes-sigs/gateway-api#1770
kubernetes-sigs/gateway-api#1855

Signed-off-by: Stéphane Cottin <stephane.cottin@vixns.com>
(cherry picked from commit 11f56fd)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* fix: infraIR duplicate port translation for merged gateways (#3061)

* fix: duplicate port translation for merged gateways

Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>

* refactor to map

Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>

* rename map

Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>

* add seperate testcase

Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>

---------

Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>
(cherry picked from commit 29946b0)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* translator: set SpawnUpstreamSpan to true (#3102)

* translator: set SpawnUpstreamSpan to true

Signed-off-by: zirain <zirain2009@gmail.com>

* update

Signed-off-by: zirain <zirain2009@gmail.com>

---------

Signed-off-by: zirain <zirain2009@gmail.com>
(cherry picked from commit 635ebfc)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* fix: rate limit doesn't work with two(and more) listeners (#3085)

* fix: rate limit doesn't work with two listeners

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* add e2e test for rate limit on multiple listeners

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

* address comments

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>

---------

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
Co-authored-by: Xunzhuo <bitliu@tencent.com>
(cherry picked from commit a5bedbc)
Signed-off-by: Arko Dasgupta <arko@tetrate.io>

* rerun make testdata

Signed-off-by: Arko Dasgupta <arko@tetrate.io>

---------

Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
Signed-off-by: Arko Dasgupta <arko@tetrate.io>
Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Signed-off-by: Jesse Haka <haka.jesse@gmail.com>
Signed-off-by: lemonlinger <lemonlinger@gmail.com>
Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>
Signed-off-by: Lior Okman <lior.okman@sap.com>
Signed-off-by: Stéphane Cottin <stephane.cottin@vixns.com>
Signed-off-by: zirain <zirain2009@gmail.com>
Co-authored-by: Huabing Zhao <zhaohuabing@gmail.com>
Co-authored-by: Jesse Haka <haka.jesse@gmail.com>
Co-authored-by: zirain <zirain2009@gmail.com>
Co-authored-by: Meng <lemonlinger@gmail.com>
Co-authored-by: Karol Szwaj <karol.szwaj@gmail.com>
Co-authored-by: Lior Okman <lior.okman@sap.com>
Co-authored-by: vixns <stephane.cottin@vixns.com>
Co-authored-by: Xunzhuo <bitliu@tencent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants