-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CORS Annotation Not Behaving as Expected #10267
Comments
This issue is currently awaiting triage. If Ingress contributors determines this is a relevant issue, they will accept it by applying the The 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. |
I dealt with the same problem yesterday with I had to take an alternative approach using the Here's what works for me - I updated the logic to support multiple origins - https://serverfault.com/a/1036160 (Thank you Marcel!)
|
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 |
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'? |
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 |
Hi @strongjz, 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 Nginx.conf
Ingess
Related code rows: |
same problem in 1.9.4, is anything new with this issue? |
@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: apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/cors-allow-credentials: "false"
nginx.ingress.kubernetes.io/cors-allow-headers: x-forwarded-for,foo
nginx.ingress.kubernetes.io/cors-allow-origin: '*'
nginx.ingress.kubernetes.io/enable-cors: "true"
name: demo-localhost
namespace: default
spec:
ingressClassName: nginx
rules:
- host: demo.localdev.me
http:
paths:
- backend:
service:
name: demo
port:
number: 80
path: /
pathType: Prefix and I got this response on a GET request (note the
|
/triage not-reproducible |
/remove-lifecycle frozen |
/assign |
Unfortunately it's been a while and I no longer have the YAML I was using to test this. I ended up using a configuration snippet to add in the headers I wanted to every request, which worked fine at the cost of a few extra lines. From what I remember, the chart I was using looked pretty much the same as your example, so maybe this is working now. |
@benosmond yeah, sorry about that... happy to see that the issue seems to be solved though! |
I have the same problem when I have this configuration snipped also applied on my ingress (from this issue): nginx.ingress.kubernetes.io/configuration-snippet: |
set $forwarded_scheme $http_x_forwarded_proto;
if ($forwarded_scheme = "") {
set $forwarded_scheme $scheme;
}
if ($forwarded_scheme = "http") {
return 403 "This endpoint is only accessible via HTTPS. You are currently using plaintext HTTP.";
}
Full definition: apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/configuration-snippet: |-
set $forwarded_scheme $http_x_forwarded_proto;
if ($forwarded_scheme = "") {
set $forwarded_scheme $scheme;
}
if ($forwarded_scheme = "http") {
return 403 "This endpoint is only accessible via HTTPS. You are currently using plaintext HTTP.";
}
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
nginx.ingress.kubernetes.io/cors-allow-headers: DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,X-Org
nginx.ingress.kubernetes.io/cors-allow-methods: GET, POST, PUT, PATCH, DELETE,
OPTIONS
nginx.ingress.kubernetes.io/cors-allow-origin: https://toto.example.com, https://*.toto.example.com
nginx.ingress.kubernetes.io/cors-expose-headers: Location, x-pagination, Link
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/modsecurity-snippet: |-
SecRuleRemoveById 920220
name: super-ingress
spec:
ingressClassName: nginx
rules:
- host: api.toto.example.com
http:
paths:
- backend:
service:
name: toto-api
port:
number: 8080
path: /
pathType: Prefix |
@awoimbee thank you for sharing that specific case, because I've been able to pinpoint the underlying issue. basically, it seems like in any case, fix is on its way! |
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.
The text was updated successfully, but these errors were encountered: