istio envoy 过滤器在 minikube 中不起作用

istio envoy filter not working in minikube

大家好,我在本地节点 minikube 和 istio 上设置外部身份验证系统时遇到问题。我已经在 helloworld 和 auther 上设置了两个部署。我想要的是通过将请求发送到 /auther 路由来授权对 /hello 路由的所有请求,该路由将连接到 auther 服务,如果设置了特定 headers(如授权中的 jwt 令牌),则 return 200 状态或 401 状态,如果没有设置。 我尝试使用这个使用 envoy ext auth 过滤器的配置文件,但没有任何效果。尽管所有传递给 /hello 的请求都得到 403,但它没有向我的 auther 服务发送任何请求。 这是我对 envoy ext-auth 过滤器的配置:

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: ext-auth
  # namespace: istio-system
  namespace: default
spec:
  workloadSelector:
    labels:
      app: helloworld
  configPatches:
    - applyTo: HTTP_FILTER
      match:
        context: SIDECAR_INBOUND
        listener:
          portNumber: 5000
          filterChain:
            filter:
              name: "envoy.http_connection_manager"
              subFilter:
                name: "envoy.router"
      patch:
        operation: INSERT_BEFORE
        value:
          #name: envoy.filters.http.ext_authz
          name: envoy.ext_authz
          typed_config:
            "@type": type.googleapis.com/envoy.config.filter.http.ext_authz.v2.ExtAuthz
            http_service:
              server_uri:
                uri: http://auther.default.svc.cluster.local:3000
                cluster: outbound|3000||auther.default.svc.cluster.local
                timeout: 3s
              # authorizationRequest:
              #   allowedHeaders:
              #     patterns:
              #     - exact: "cookie"

您的配置适用于每个 sidecar,包括 auther 的 sidecar。因此来自 helloworld 的转发流量也被拒绝。

只需将过滤器设置为仅应用于您的网关。将 context 设置为 GATEWAY 并为请求和响应设置 allowedHeaders,以便授权请求可以通过。

这里是一个示例配置:

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: authn-filter
  namespace: istio-system
spec:
  workloadSelector:
    labels:
      istio: ingressgateway
  configPatches:
    - applyTo: HTTP_FILTER
      match:
        context: GATEWAY
        listener:
          filterChain:
            filter:
              name: "envoy.http_connection_manager"
              subFilter:
                name: "envoy.router"
      patch:
        operation: INSERT_BEFORE
        value:
          name: envoy.ext_authz
          typed_config:
            "@type": "type.googleapis.com/envoy.config.filter.http.ext_authz.v2.ExtAuthz"
            http_service:
              server_uri:
                uri: http://auther.default.svc.cluster.local
                cluster: outbound|4180||auther.default.svc.cluster.local
                timeout: 1.5s
              authorizationRequest:
                allowedHeaders:
                  patterns:
                    - exact: "cookie"
                    - exact: "authorization"
                    - ....
              authorizationResponse:
                allowedClientHeaders:
                  patterns:
                    - exact: "set-cookie"
                    - exact: "authorization"
                    - ....
                allowedUpstreamHeaders:
                  patterns:"
                    - exact: "set-cookie"
                    - exact: "authorization"
                    - ....

如果您需要进一步的帮助,请告诉我!