我正在尝试使用Istio入口网关在GKE集群上使用1.8启用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前缀或不使用http前缀,则会得到不同的响应
使用<ingress ip>/mypath,我得到了403个禁止错误,而在http://<ingress ip>/mypath中,我得到了一个未启用的通用CORS。如果我从Postman执行api,所有工作正常,但CORS头不返回。我还试图直接从Flask应用程序中设置CORS,但是没有什么改变。
知道怎么解决吗?
谢谢
发布于 2020-12-19 12:03:19
这应该能行,我刚刚测试过。
allowOrigins:
- exact: "*"根据我的经验,Istio CORS选项是泛型CORS功能的一个非常薄的包装器,所以我想真正的问题不是关于Istio,而是CORS的配置。
也许allowCredentials或allowHeaders有问题。另外,如果您有一个Istio AuthorizationPolicy,那么可能应该允许对航班前请求进行OPTIONS调用。
https://stackoverflow.com/questions/65345255
复制相似问题