我正在尝试使用 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"
我也在使用这个在线休息客户端来测试端点,如果我使用 http 前缀,我会得到不同的响应
我得到<ingress ip>/mypath
403 Forbidden 错误,而http://<ingress ip>/mypath
我没有启用通用 CORS。如果我从 Postman 执行 api 一切正常,但不会返回 CORS 标头。我还尝试直接从 Flask 应用程序设置 CORS,但没有任何改变。
关于如何解决的任何想法?
谢谢