kubernetes / ingress-nginx

Ingress NGINX Controller for Kubernetes
https://kubernetes.github.io/ingress-nginx/
Apache License 2.0
17.33k stars 8.22k forks source link

custom HTTP response body for error response from auth-url #11561

Open grinish21 opened 3 months ago

grinish21 commented 3 months ago

What happened:

Need to send a custom response body when there is an error in auth service response like 401. This previous issue is closed https://github.com/kubernetes/ingress-nginx/issues/4314 but i could not find the answer.

My annotations

    nginx.ingress.kubernetes.io/auth-cache-duration: 200 30m
    nginx.ingress.kubernetes.io/auth-response-headers: X-Roles
    nginx.ingress.kubernetes.io/auth-url: http://ingress-auth.default.svc.cluster.local:80/auth
    nginx.ingress.kubernetes.io/rewrite-target: /$3
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/use-regex: "true"

The auth-url responds with a json body but i always get the html back.

<html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx</center>
</body>
</html>

What you expected to happen:

to respond back with a custom response body than default 401 html page.

NGINX Ingress controller version (exec into the pod and run nginx-ingress-controller --version.):

  NGINX Ingress controller
    Release:       v1.8.1
    Build:         dc88dce9ea5e700f3301d16f971fa17c6cfe757d
    Repository:    https://github.com/kubernetes/ingress-nginx
    nginx version: nginx/1.21.6

Kubernetes version (use kubectl version):

    Client Version: v1.29.2
    Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
    Server Version: v1.30.0

How to reproduce this issue:

using the example here -> https://kubernetes.github.io/ingress-nginx/examples/auth/external-auth/ if httpbin auth api responds with a json body with some content for 401 it wont show up rather the caller will see the default html page

Anything else we need to know:

k8s-ci-robot commented 3 months ago

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](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
longwuyuan commented 3 months ago

/remove-kind bug /kind support

Can you test if this example helps in any ways https://kubernetes.github.io/ingress-nginx/examples/customization/custom-errors/

grinish21 commented 3 months ago

let me try that and get back.

longwuyuan commented 3 months ago

/riage needs-information

github-actions[bot] commented 2 months ago

This is stale, but we won't close it automatically, just bare in mind the maintainers may be busy with other tasks and will reach your issue ASAP. If you have any question or request to prioritize this, please reach #ingress-nginx-dev on Kubernetes Slack.