【发布时间】:2020-08-11 10:11:26
【问题描述】:
我们正在使用 Kubernetes 和 Istio 并配置了一个虚拟服务:
http:
- match:
- uri:
prefix: /api
rewrite:
uri: /api
route:
- destination:
host: svc-api
port:
number: 80
subset: stable
weight: 0
- destination:
host: svc-api
port:
number: 80
subset: vnext
weight: 100
corsPolicy: &apiCorsPolicy
allowOrigins:
- exact: '*'
allowMethods:
- GET
- POST
- OPTIONS
allowCredentials: true
allowHeaders:
- "*"
- match:
- uri:
prefix: /
rewrite:
uri: /
route:
- destination:
host: svc-api
port:
number: 80
subset: stable
weight: 0
- destination:
host: svc-api
port:
number: 80
subset: vnext
weight: 100
corsPolicy: *apiCorsPolicy
从浏览器向https://[host]/api/* 发出请求在使用'from origin [request] has been blocked by CORS policy' 的OPTIONS 请求上失败。
在 k8 中描述服务显示了正确的配置。
根据 v 1.6.4,使用 allowOrigins 和 exact 而不是 allowOrigin 的结构是正确的。
我在这里错过了什么?
【问题讨论】:
-
您的集群中是否有某种类型的授权,例如 jwt?能否尝试将
exact: '*'更改为exact : 'example.com'并检查问题是否仍然存在?另外看看这个github issue,也许你应该添加AllowHeaders而不是使用'*'。 -
@jt97 - 感谢您的评论。我确实尝试使用像
example.com这样的特定主机,并且我还尝试添加所需的标头而不是使用通配符,但效果相同。我们确实有一个 jwt 授权,如果请求来自服务器但任何浏览器(创建 OPTIONS 请求)失败,则可以完美处理。 -
@jt97 您发布的链接仅提及使用
allowOrigins和exact而不仅仅是allowOrigin- 不幸的是,我尝试了两种设置,结果相同。 -
好像cors配置没问题,我问了授权因为403是授权码,当jwt策略针对Istio Ingress网关时cors不起作用,有一个github issue关于那,你能添加你的请求和授权策略吗?
-
另外看看这个stackoverflow question,社区成员在这里有一个工作选项,但是返回403。
标签: kubernetes cors http-status-code-403 istio