1

这是我的请求认证,

apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
  name:prod-authenticator
  namespace: prod
spec:
  selector:
    matchLabels:
      istio: ingressgateway
  jwtRules:
  - issuer: https://securetoken.google.com/<project-id>
    jwksUri: https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com

我的 AuthorizationPolicy 是这个,

apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
 name:prod-authorized-api
 namespace: prod
spec:
 action: ALLOW
 rules:
 - from:
   - source:
        requestPrincipals: ["*"]

 - to:
    - operation:
        paths: ["/user/ping"]

下面帮助我排除没有有效令牌的健康路径(/user/ping)。

我的虚拟服务是

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: user-svc-vs
  namespace: prod
spec:
  hosts:
  - gateway.xxxx.com
  gateways:
  - istio-system/prod-gateway
  http:
  - match:
    - uri:
        prefix: /pop
    route:
    - destination:
        host:user-svc.prod.svc.cluster.local 

但是当检查时我可以看到只有健康 api 得到 200 其余的都得到 404,当检查浏览器时我看到了

从源“https://<>”访问“https://”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:没有“Access-Control-Allow-Origin”标头存在于请求的资源上。

在虚拟服务中,我尝试添加“corsPolicy”,但没有任何效果。

示例虚拟服务尝试示例是

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ratings-route
spec:
  hosts:
  - ratings.prod.svc.cluster.local
  http:
  - route:
    - destination:
        host: ratings.prod.svc.cluster.local
        subset: v1
    corsPolicy:
      allowOrigins:
      - exact: https://example.com
      allowMethods:
      - POST
      - GET
      allowCredentials: false
      allowHeaders:
      - X-Foo-Bar
      maxAge: "24h"

<<上面不是我们的例子,但我已经复制了,但我应用了我当前的环境,但仍然没有运气!任何人都可以帮助,为此奋斗一整天:)

4

1 回答 1

4

CORS pre-flight 请求是OPTIONS由浏览器自动发出的 HTTP 请求,详见本站

因此,请允许OPTIONS您的呼叫AuthorizationPolicy以允许飞行前请求。

- to:
    - operation:
        methods: ["OPTIONS"]
于 2021-01-24T07:26:07.697 回答