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

Request Transformer with path regex in Kong Ingress Controller not working #9664

Closed
1 task done
drpdishant opened this issue Nov 2, 2022 · 3 comments
Closed
1 task done
Labels
area/ingress-controller Issues where Kong is running as a Kubernetes Ingress Controller area/kubernetes Issues where Kong is running on top of Kubernetes

Comments

@drpdishant
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Kong version ($ kong version)

3.0

Current Behavior

Following deployment with request transformer applied returns no routes found.

#default-backend.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: default-backend
spec:
  selector:
    matchLabels:
      app: default-backend
  replicas: 1
  template:
    metadata:
      labels:
        app: default-backend
    spec:
      containers:
      - name: default-backend
        image: mendhak/http-https-echo:23
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: default-backend
spec:
  selector:
    app: default-backend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: ClusterIP
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: stripper
  namespace: default
config: 
  replace:
    uri: /$(uri_captures[1])
plugin: request-transformer
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    konghq.com/plugins: stripper
    kubernetes.io/ingress.class: "kong"
    # konghq.com/strip-path: "true"
  name: default-backend
spec:
  # ingressClassName: kong
  rules:
  - http:
      paths:
      - backend:
          service:
            name: default-backend
            port:
              number: 80
        path: /api/(debug.*|kyc-debug.*|trigger-.*)
        pathType: ImplementationSpecific

Curl Test Corresponding to Path Regex

#Request
curl --location --request GET 'http://172.16.15.0/api/kyc-debug'
#Response
{
    "message": "no Route matched with those values"
}
#More paths
curl --location --request GET 'http://172.16.15.0/api/debug'
curl --location --request GET 'http://172.16.15.0/api/trigger-debug'

Expected Behavior

As per the configuration the curl requests matching the path regex, should be transformed by request transformer plugin using the capture group, and appropriate response returned. it has been tested and working with kong:2.7 but not with kong:3.0

Steps To Reproduce

1. Install kong version 3.0 using helm chart

helm upgrade --install kong kong/kong -n kong --create-namespace
  1. Deploy default-backend.yaml
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: default-backend
spec:
  selector:
    matchLabels:
      app: default-backend
  replicas: 1
  template:
    metadata:
      labels:
        app: default-backend
    spec:
      containers:
      - name: default-backend
        image: mendhak/http-https-echo:23
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: default-backend
spec:
  selector:
    app: default-backend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: ClusterIP
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: stripper
  namespace: default
config: 
  replace:
    uri: /$(uri_captures[1])
plugin: request-transformer
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    konghq.com/plugins: stripper
    kubernetes.io/ingress.class: "kong"
    # konghq.com/strip-path: "true"
  name: default-backend
spec:
  # ingressClassName: kong
  rules:
  - http:
      paths:
      - backend:
          service:
            name: default-backend
            port:
              number: 80
        path: /api/(debug.*|kyc-debug.*|trigger-.*)
        pathType: ImplementationSpecific
EOF

Execute Curl Requests Matching the path Regex.

curl --location --request GET "${PROXY_URL}/api/kyc-debug"


### Anything else?

It works as expected with kong version 2.7, verify by installing kong helm chart with version 2.7

```bash
helm upgrade --install kong kong/kong -n kong --create-namespace --version 2.7

Deploy the Ingress App

cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: default-backend
spec:
  selector:
    matchLabels:
      app: default-backend
  replicas: 1
  template:
    metadata:
      labels:
        app: default-backend
    spec:
      containers:
      - name: default-backend
        image: mendhak/http-https-echo:23
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: default-backend
spec:
  selector:
    app: default-backend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: ClusterIP
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: stripper
  namespace: default
config: 
  replace:
    uri: /$(uri_captures[1])
plugin: request-transformer
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    konghq.com/plugins: stripper
    kubernetes.io/ingress.class: "kong"
    # konghq.com/strip-path: "true"
  name: default-backend
spec:
  # ingressClassName: kong
  rules:
  - http:
      paths:
      - backend:
          service:
            name: default-backend
            port:
              number: 80
        path: /api/(debug.*|kyc-debug.*|trigger-.*)
        pathType: ImplementationSpecific
EOF

Test with curl

curl --location --request GET 'http://172.16.15.0/api/kyc-debug'
@hbagdi hbagdi added area/kubernetes Issues where Kong is running on top of Kubernetes area/ingress-controller Issues where Kong is running as a Kubernetes Ingress Controller labels Nov 2, 2022
@hbagdi
Copy link
Member

hbagdi commented Nov 2, 2022

cc @kong/team-k8s

@czeslavo
Copy link

czeslavo commented Nov 2, 2022

Hi @drpdishant 👋

The regex path handling has changed in Kong 3.0. Here's the migration guide that should help you migrate properly.

In short, you should be fine changing your regex paths to start with /~ (i.e. path: /~/api/(debug.*|kyc-debug.*|trigger-.*). If you wanna keep the paths as they are, you can configure IngressClassParameters with enableLegacyRegexDetection: true to make KIC handle legacy regex paths for you as before to make the migration from Kong 2.x to 3.x smooth. Please note that it's an option just for migration purposes and is not expected to be supported in the future so it's better to migrate paths sooner than later.

@drpdishant
Copy link
Author

thanks! @czeslavo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ingress-controller Issues where Kong is running as a Kubernetes Ingress Controller area/kubernetes Issues where Kong is running on top of Kubernetes
Projects
None yet
Development

No branches or pull requests

3 participants