1

我正在尝试使用 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>/mypath403 Forbidden 错误,而http://<ingress ip>/mypath我没有启用通用 CORS。如果我从 Postman 执行 api 一切正常,但不会返回 CORS 标头。我还尝试直接从 Flask 应用程序设置 CORS,但没有任何改变。

关于如何解决的任何想法?

谢谢

4

1 回答 1

1

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

allowOrigins:
 - exact: "*"

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

可能有什么问题allowCredentialsor allowHeaders。此外,如果您有 Istio ,则可能应该允许AuthorizationPolicyHTTP调用用于飞行前请求。OPTIONS

于 2020-12-19T12:03:19.347 回答