kubernetes - CORS 规则 nginx-ingress 规则

标签 kubernetes cors kubernetes-ingress

我需要在 nginx-ingress 版本上允许来自多个来源的请求:http://localhost:4200http://localhost:4242 等1.7.1.但我无法对多个来源执行此操作,因为 nginx.ingress.kubernetes.io/cors-allow-credentials: true 不适用于 nginx.ingress.kubernetes.io/cors-allow-origin: "*"。它会导致浏览器生成 CORS 错误。也许有人有避免此错误的解决方案?

这是我的配置

 annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "*"
nginx.ingress.kubernetes.io/cors-allow-methods: "PUT, GET, POST, OPTIONS, DELETE"
nginx.ingress.kubernetes.io/cors-allow-headers: "DNT,X-CustomHeader,X-LANG,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,X-Api-Key,X-Device-Id,Access-Control-Allow-Origin"

Access to XMLHttpRequest at 'https://stage.site.com/api/session' from origin 'http://localhost:4200' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

最佳答案

添加注释以启用CORS:

nginx.ingress.kubernetes.io/enable-cors: "true"

请注意,字符串“*”不能用于支持凭据的资源 ( https://www.w3.org/TR/cors/#resource-requests ),请尝试使用您的域列表(逗号分隔)而不是 *

关于kubernetes - CORS 规则 nginx-ingress 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51744536/

相关文章:

kubernetes - Openshift 中的 Cron Job 不是有效模板,而是带有 yml 的 *batch.CronJob

http - CORS Access-Control-Allow-Headers 通配符被忽略?

Kubernetes 从另一个 Pod 中查找 Pod IP

kubernetes - 使用静态IP公开Ladbalancer

kubernetes - 如何使用自定义配置在 kubernetes 上部署 keycloak?

go - 如何强制对自定义 Controller 中的 SharedIndexInformer 进行完全重新同步

bash - 如何从 kubectl 转发 psql shell

javascript - 从源 '...' 访问位于 'http://localhost' 的 XMLHttpRequest 已被 CORS 策略阻止

azure - Azure 搜索基本中是否禁止 OPTIONS 请求?

kubernetes - 如何使用 443/80 在 prem 上公开 kubernetes 服务