Anthos Service Mesh/Istio CORS not enabled



我正试图使用Istio入口网关在带有Anthos Service Mesh 1.8的GKE集群上启用CORS,但CORS标头没有正确返回。

这里是服务配置

apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: ClusterIP
selector:
app: my-service
ports:
- name: http
port: 8080
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-service
spec:
selector:
matchLabels:
app: my-service
template:
metadata:
labels:
app: my-service
spec:
serviceAccountName: ksa
containers:
- name: my-service
image: <my image>
ports:
- name: http-server
containerPort: 8080

和入口配置

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
name: istio-gateway
spec:
selector:
istio: ingressgateway 
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: istio-ingress
spec:
hosts:
- "*"
gateways:
- istio-gateway
http:
- name: default-public-route
route:
- destination:
host: my-service
corsPolicy:
allowOrigins:
- exact: "*"
allowMethods:
- GET
- POST
- PATCH
- PUT
- DELETE
- OPTIONS
allowCredentials: false
allowHeaders:
- authorization
maxAge: "24h"

我还使用这个在线rest客户端来测试端点,如果我使用http前缀或不使用,我会得到不同的响应

对于<ingress ip>/mypath,我得到403禁止错误,而对于http://<ingress ip>/mypath,我得到未启用的通用CORS。如果我执行Postman的api,所有操作都正常,但不会返回CORS头。我还尝试直接从Flask应用程序设置CORS,但没有任何改变。

你知道怎么解决吗?

感谢

这应该可以工作,我刚刚测试过。

allowOrigins:
- exact: "*"

根据我的经验,Istio CORS选项是一个相当薄的通用CORS功能包装器,所以我想真正的问题不在于Istio,而在于CORS配置。

也许allowCredentialsallowHeaders出了问题。此外,如果您有IstioAuthorizationPolicy,那么飞行前请求可能应该允许HTTPOPTIONS调用。

最新更新