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

handling requests, with path terminated with and without forward-slash

Open jonenst opened this issue 3 years ago • 5 comments

Host a normal app at /app with minimal fuss. Currently the docs https://kubernetes.github.io/ingress-nginx/examples/rewrite/#rewrite-target have the example:

$ echo '
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - path: /something(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: http-svc
            port: 
              number: 80
' | kubectl create -f -

But:

  • sending both /something and /something/ to '/' doesn't work by default for web things with relative links (because for /something, links point to /other; but for /something/, links point to /something/other). So the container sending relative links must know if the client uses /something or /something/. A workaround is simply to never send requests to /something to the container and redirect them to /something/ on the client (Is there a simpler way than resorting to configuration-snippets ? Adding a second ingress with https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#permanent-redirect ? Something else ?):
    nginx.ingress.kubernetes.io/configuration-snippet: |
      rewrite ^/something$ /something/ permanent;
  • by default the ingress sets X-Forwarded-{For, Host, Port, Proto, Scheme}, but not X-Forwarded-Prefix. Maybe just add x-forwarded-prefix annotation in the docs example ?
  • the path requires a moderatly complex regex, the backreference requires $2. Could it be simpler for the user ?
  • when you don' want url normalization (for example to avoid decoding properly encoded slashes), you needed even more complex configuration snippets to avoid using the nginx rewrite directive.

NO

NO

jonenst avatar Sep 12 '22 10:09 jonenst

@jonenst: This issue is currently awaiting triage.

If Ingress contributors determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Sep 12 '22 10:09 k8s-ci-robot

/retitle handling path in request terminated with forward-slash and without forward-slash

longwuyuan avatar Sep 15 '22 05:09 longwuyuan

/retitle handling request with path terminated without or without forward-slash

longwuyuan avatar Sep 15 '22 05:09 longwuyuan

/retitle handling requests, with path terminated with and without forward-slash

longwuyuan avatar Sep 15 '22 05:09 longwuyuan

seems related discussion is here as well https://github.com/kubernetes/ingress-nginx/issues/8047

longwuyuan avatar Sep 15 '22 05:09 longwuyuan

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Dec 14 '22 05:12 k8s-triage-robot

/remove-lifecycle stale

jonenst avatar Dec 16 '22 07:12 jonenst

Doing a little necro here, but has this been addressed elsewhere? It comes up as a search result and it Open without staleness, but hasn't been touched in about a year. Anything we can do to update this, even if it's a link to another resolved issue?

AndyVulhop avatar Dec 11 '23 20:12 AndyVulhop

To me it doesn't seem like the docs are any simpler, or that they address the concerns I raised. If you just follow the simple rewrite docs, your app won't know if the empty path had a slash or not (breaks relative links), won't know the x-forwarded-prefix (as an example this breaks typical swagger usage with springboot), will decode encoded slashes by default (breaks most rest APIs when resource ids are in the path and contain a properly escaped slash). You don't even get to have "simple" configuration in exchange for these weird defaults, you need a precise regex with the two capturing groups. To me, it feels like improving on these aspects is a low hanging fruit to reap the huge benefits of this awesome project !

jonenst avatar Dec 12 '23 15:12 jonenst