Description
I added CORS annotations to my chart, but the CORS headers are only being returned from OPTIONS requests. GET requests are missing the headers, which causes errors in the browser.
Annotations added:
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "*"
nginx.ingress.kubernetes.io/cors-allow-credentials: "false"
nginx.ingress.kubernetes.io/cors-allow-headers: (...headers)
OPTIONS requests to (my API URL) are working as I expect, with the CORS headers being returned.
GET requests to (my API URL) are not behaving as expected, with no CORS headers in the response at all.
I was expecting that all allowed request methods would be returned with CORS response headers e.g.:
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: (...headers)
Access-Control-Allow-Methods: ...
Etc.
Without these on the GET request the browser seems to give a CORS error for every request, making the API unusable.
I considered applying the individual headers I want manually using snippets but it seems like this configuration should be possible using the CORS annotations? Any help much appreciated.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Activity
k8s-ci-robot commentedon Aug 1, 2023
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.
simplyzee commentedon Aug 3, 2023
I dealt with the same problem yesterday with
Access-Control-Allow-Origin: *
always returning based on the backend logic that NGINX generates for service via thenginx.conf
as soon as I specified the annotation:nginx.ingress.kubernetes.io/cors-allow-origin: <host>
I had to take an alternative approach using the
nginx.ingress.kubernetes.io/configuration-snippet
annotation, setting headers with themore_set_headers
function.Here's what works for me - I updated the logic to support multiple origins - https://serverfault.com/a/1036160 (Thank you Marcel!)
This is a temporary workaround for me until the annotation logic works again.
strongjz commentedon Aug 3, 2023
Can provide the nginx.conf? The version of the controller, deployment and other logs that might be helpful, and the ingress resource you are using to test?
-James
benosmond commentedon Aug 3, 2023
I opted for a similar workaround in the end, but it's still disappointing to not be able to use the annotation.
@strongjz can I ask what you mean by 'the ingress resource you are using to test'?
github-actions commentedon Sep 3, 2023
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.sinacek commentedon Apr 5, 2024
Hi @strongjz,
I have similar question problem.
TLDR: This configuration send cors headers only when origin is equal https://mysite.com. In all other case it sends no cors, so the source doesn't say to browser for which origin is intended.
Image: registry.k8s.io/ingress-nginx/controller:v1.10.0
Logs: doesn't contains any error.
Nginx.conf
Ingess
Related code rows:
patog commentedon Aug 1, 2024
same problem in 1.9.4, is anything new with this issue?
elizabeth-dev commentedon Nov 21, 2024
@benosmond @patog could you share the yaml for the Ingress resource that is causing your issue? I've just tried to reproduce it with this config:
and I got this response on a GET request (note the
Access-Control-Allow-Headers
header present in the response):elizabeth-dev commentedon Nov 21, 2024
/triage not-reproducible
17 remaining items