Kong / kubernetes-ingress-controller

:gorilla: Kong for Kubernetes: The official Ingress Controller for Kubernetes.
https://docs.konghq.com/kubernetes-ingress-controller/
Apache License 2.0
2.22k stars 592 forks source link

With Gateway API HttpRoute cannot use `UrlRewrite` and request-transformer plugin together #6390

Open zsedem opened 2 months ago

zsedem commented 2 months ago

Is there an existing issue for this?

Current Behavior

Adding plugin with request-transformer type to an HTTPRoute with Rewrite will make one of the rules not take effect. Either

---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: for-testing-header-transform
  namespace: rewrite-test
plugin: request-transformer
config:
  add:
    headers:
    - X-for-testing:ForTesting

---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: httpbin-post
  namespace: rewrite-test
  annotations:
    konghq.com/plugins: "for-testing-header-transform"
spec:
  parentRefs:
    - group: gateway.networking.k8s.io
      kind: Gateway
      name: rewrite-test
  rules:
    - matches:
      - path:
          type: Exact
          value: /post-rewrite
      filters:
      - type: URLRewrite
        urlRewrite:
          path:
            type: ReplaceFullPath
            replaceFullPath: /post

      backendRefs:
        - name: httpbin
          kind: Service
          port: 8000

Expected Behavior

Have the route both the additional header applied to it and the urlrewrite rule

Steps To Reproduce

I reproduced it in KinD, with the above config and everything left on default

Kong Ingress Controller version

2.3.0

Kubernetes version

kubectl version -o json
{
  "clientVersion": {
    "major": "1",
    "minor": "30",
    "gitVersion": "v1.30.2",
    "gitCommit": "39683505b630ff2121012f3c5b16215a1449d5ed",
    "gitTreeState": "archive",
    "buildDate": "1980-01-01T00:00:00Z",
    "goVersion": "go1.22.5",
    "compiler": "gc",
    "platform": "linux/amd64"
  },
  "kustomizeVersion": "v5.0.4-0.20230601165947-6ce0bf390ce3",
  "serverVersion": {
    "major": "1",
    "minor": "30",
    "gitVersion": "v1.30.0",
    "gitCommit": "7c48c2bd72b9bf5c44d21d7338cc7bea77d0ad2a",
    "gitTreeState": "clean",
    "buildDate": "2024-05-13T22:00:36Z",
    "goVersion": "go1.22.2",
    "compiler": "gc",
    "platform": "linux/amd64"
  }
}

Anything else?

In the proposed solution for the support of UrlRewrite here: https://github.com/Kong/kubernetes-ingress-controller/issues/5853 They mention using a Kong request-transformer plugin, is it possible that because of this, we cannot use UrlRewrite and request-transformer plugin together?

czeslavo commented 2 months ago

Hey @zsedem, thanks for the report. The short answer is: yes, this is an unexpected implicit limitation - we cannot create multiple instances of request-transformer Plugin associated with a single Kong Route.

I agree it's a bug and we should solve it either by:

I'm adding this issue preliminary to 3.4 milestone and we will discuss how this should be fixed.

zsedem commented 2 months ago

For the time being, a reasonable workaround is creating a custom plugin, which does the request transformation.