nginx.ingress.kubernetes.io/rewrite-target can't regex capture url parameters

1/27/2021

Recently I have setup an EKS cluster to run an application through ingress-nginx. I am trying to use regex capturing and nginx.ingress.kubernetes.io/rewrite-target to change my url parameters but it is not behaving as I'd expect it to behave. Here is my configuration which is

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    meta.helm.sh/release-name: sandbox1
    meta.helm.sh/release-namespace: sandbox1
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /\$1?\$2
    nginx.ingress.kubernetes.io/enable-rewrite-log: "true"
  labels:
    app.kubernetes.io/component: api-gateway
    app.kubernetes.io/instance: sandbox1
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: api-gateway
    app.kubernetes.io/part-of: fusion
    app.kubernetes.io/version: "5"
    helm.sh/chart: api-gateway-1.8.0
  name: sandbox1-api-gateway
  namespace: sandbox1
spec:
  rules:
  - host: app.example.com
    http:
      paths:
      - backend:
          serviceName: proxy
          servicePort: 6764
        path: /(.*)\?(.*)

If I do:

curl -i -k https://app.example.com/something/bla1/bla2?param1=a&param2=b

Rewrite logs show

"Basic.*" does not match ""

Something odd is going on here because if I change the configuration with path: /(.*)bla1(.*) and do the same curl request again the regex matches and the redirect occurs properly (as silly as this example is).

  • I wonder is the ? character not being matched properly ?
  • Is it not possible to manipulate url parameters using nginx.ingress.kubernetes.io/rewrite-target ?
  • Maybe I am missing something ?

Any help is welcomed, thanks.

-- nabello
ingress-nginx
kubernetes
kubernetes-ingress
regex

0 Answers