gloo icon indicating copy to clipboard operation
gloo copied to clipboard

Can't add both a PathPrefix matcher and Header matcher on route that uses URLRewrite ReplacePrefixMatch filter

Open DuncanDoyle opened this issue 2 years ago • 1 comments

Gloo Edge Product

Open Source

Gloo Edge Version

Gloo Gateway v2 2.0.0-beta1

Kubernetes Version

v1.27.8

Describe the bug

When I configure a K8S Gateway API HTTPRoute, in which I use both a PathPrefix matcher, a Header matcher and URLRewrite ReplacePrefixMatch filter, the HTTPRoute gets rejected:

The HTTPRoute "api-example-com-route" is invalid: spec.rules[0]: Invalid value: "object": When using URLRewrite filter with path.replacePrefixMatch, exactly one PathPrefix match must be specified

HTTPRoute CR:

apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: api-example-com-route
  namespace: default
  labels:
    app: apis
spec:
  parentRefs:
    - name: http
      namespace: gloo-system
  hostnames:
    - "api.example.com"
  rules:
    - matches:  
      - path:
          type: PathPrefix
          value: /httpbin/
      - headers:
        - name: version
          value: v2
          type: Exact
      filters:
        - type: URLRewrite
          urlRewrite:
            path:
              type: ReplacePrefixMatch
              replacePrefixMatch: /
      backendRefs:
        - name: httpbin
          namespace: httpbin
          port: 8000

Note that the HTTPRoute works when I remove the header matcher, or when I remove the URLRewrite ReplacePrefixMatch filter (in the latter case, obviously the request to the upstream does not work because of the missing rewrite, but the HTTPRoute gets accepted and routes requests to upstream).

Expected Behavior

The HTTPRoute gets accepted and I can match requests both and path and header.

Steps to reproduce the bug

  1. Deploy the httpbin service / upstream as described here: https://docs.solo.io/gloo-gateway/v2/quickstart/
  2. Deploy the HTTPRoute CR from the description of this issue.
  3. Observe the error that is returned when trying to apply the given HTTPRoute CR: The HTTPRoute "api-example-com-route" is invalid: spec.rules[0]: Invalid value: "object": When using URLRewrite filter with path.replacePrefixMatch, exactly one PathPrefix match must be specified

Additional Environment Detail

No response

Additional Context

No response

DuncanDoyle avatar Nov 21 '23 11:11 DuncanDoyle

Closing. Matches rule was incorrectly specified. Route should look as such. Notice that we removed the dash on the headers field. With the dash, we were defining 2 matching rules instead a single one with a path and a header matcher.

apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: api-example-com-route
  namespace: default
  labels:
    app: apis
spec:
  parentRefs:
    - name: http
      namespace: gloo-system
  hostnames:
    - "api.example.com"
  rules:
    - matches:  
      - path:
          type: PathPrefix
          value: /httpbin/
        headers:
        - name: version
          value: v2
          type: Exact
      filters:
        - type: URLRewrite
          urlRewrite:
            path:
              type: ReplacePrefixMatch
              replacePrefixMatch: /
      backendRefs:
        - name: httpbin
          namespace: httpbin
          port: 8000

DuncanDoyle avatar May 13 '24 13:05 DuncanDoyle