ingress-nginx icon indicating copy to clipboard operation
ingress-nginx copied to clipboard

Rewrite Rules Not Working in NGINX Ingress Controller v1.9.0+

Open sandeepkumar4-fractal opened this issue 7 months ago • 1 comments

Description After upgrading from NGINX Ingress Controller v1.8.5 to v1.9.0+, the configuration-snippet no longer applies rewrite rules or sub_filter modifications. This behavior worked correctly in v1.8.5 and earlier versions, but after v1.9.0, the snippet is ignored

Ingress File:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    meta.helm.sh/release-name: app-test
    meta.helm.sh/release-namespace: test
    nginx.ingress.kubernetes.io/configuration-snippet: |
      sub_filter "/openapi.json'"/backend/openapi.json';
      sub_filter_once off;
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/health-check-fails: "2"
    nginx.ingress.kubernetes.io/health-check-interval: "10"
    nginx.ingress.kubernetes.io/health-check-path: /api/v1/health
    nginx.ingress.kubernetes.io/health-check-retries: "3"
    nginx.ingress.kubernetes.io/health-check-succeeds: "2"
    nginx.ingress.kubernetes.io/health-check-timeout: "5"
    nginx.ingress.kubernetes.io/proxy-body-size: 500m
    nginx.ingress.kubernetes.io/proxy-buffering: "off"
  name: ingress-test
  namespace: test
spec:
  ingressClassName: nginx
  rules:
  - host: test.demo.com
    http:
      paths:
      - backend:
          service:
            name: <service-name>
            port:
              number: 8000
        path: /backend(/|$)(.*)
        pathType: ImplementationSpecific
  tls:
  - hosts:
    - test.demo.com
    secretName: <secret-name>

Actual Behaviour We want the endpoints to work as below: https://test.demo.com/backend/docs --> swagger ui page (this is not working as the next call goes to /openapi.json where it is dropping "/backend" from the call and the call is not able to complete) https://test.demo.com/backend/api/v1/health --> health check page working fine

Expected Behaviour: The configuration-snippet with sub_filter should correctly modify the response body in NGINX, as it did in versions 1.8.5 and earlier

Troubleshooting Done Verified that the snippet is applied in the generated nginx.conf file (kubectl exec -it -- cat /etc/nginx/nginx.conf). Confirmed that the issue occurs only in v1.9.0+. Tested with server-snippet instead of configuration-snippet, but the issue persists. Checked logs (kubectl logs -n kube-system -l app.kubernetes.io/name=ingress-nginx), but no errors related to sub_filter were found.

Request for Assistance Can the NGINX Ingress team confirm if this is an intentional change or a regression bug? If intentional, what is the new recommended way to apply sub_filter transformations in v1.9.0+?

sandeepkumar4-fractal avatar Mar 26 '25 10:03 sandeepkumar4-fractal