【问题标题】:EnvoyFilter: Apply ExtAuthz filter followed by Lua filterEnvoyFilter:应用 ExtAuthz 过滤器,然后是 Lua 过滤器
【发布时间】:2021-08-02 10:58:07
【问题描述】:

我正在尝试构建一个 EnvoyFilter(使用 v3 API)以与 Istio 和 OAuth2-Proxy(作为外部 Authz 服务)结合使用。

基本上,我需要一个调用ExtAuthz 的设置来进行身份验证,并检索标题x-auth-request-email 并将其重命名为kubeflow-userid。我很难理解 Envoy 链是如何过滤的。

我目前的尝试如下:

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: istio-ingressgateway
  namespace: istio-system
spec:
  filters:
  - applyTo: HTTP_FILTER
    match:
      context: GATEWAY
      listener:
        filterChain:
          filter:
            name: envoy.filters.network.http_connection_manager
            subFilter:
              name: envoy.filters.http.jwt_authn
    patch:
      operation: INSERT_BEFORE
      value:
        name: envoy.filters.http.ext_authz
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthz
          http_service:
            server_uri:
              uri: http://oauth2-proxy.oauth2-proxy.svc.cluster.local:4180
              cluster: outbound|4180||oauth2-proxy.oauth2-proxy.svc.cluster.local
              timeout: 10s              
            authorizationRequest:
              allowedHeaders:
                patterns:
                - exact: cookie
              authorizationResponse:
                allowedUpstreamHeaders:
                  patterns:
                    # - exact: "kubeflow-userid"
                    - exact: "authorization"
                    - exact: "x-auth-request-email"    
  - applyTo: HTTP_FILTER # should this be NETWORK_FILTER instead?
    match: # how do I define the context here?
      #context: GATEWAY
      listener:
        filterChain:
          filter:
            name: envoy.filters.network.http_connection_manager
            subFilter:
              name: envoy.filters.http.jwt_authn
    patch:
      operation: MERGE # what should this be?
      value:
        name: envoy.filters.http.lua
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
          inline_code: |
            function envoy_on_request(request_handle)
              headers = request_handle:headers()
              request_handle:headers():add("kubeflow-userid", headers:get("x-auth-request-email))
            end

【问题讨论】:

    标签: kubernetes lua istio envoyproxy


    【解决方案1】:

    在您的情况下,过滤器链由

    定义
    • 您在匹配部分定义的 subFilter.name
    • 补丁部分中过滤器的名称

    我发现将其作为两个单独的过滤器更容易理解(我调整了名称):

    您的ExtAuthz 过滤器插入到名称为custom.ext_authz 的过滤器envoy.filters.http.router 之前。

    [...]
        match:
          context: GATEWAY
          listener:
            filterChain:
              filter:
                name: envoy.filters.network.http_connection_manager
                subFilter:
                  name: envoy.filters.http.router
        patch:
          operation: INSERT_BEFORE
          value:
            name: custom.ext_authz
    

    lua 过滤器插入到 custom.ext_authz 过滤器之后,名称为 custom.lua

        match: 
          context: GATEWAY
          listener:
            filterChain:
              filter:
                name: envoy.filters.network.http_connection_manager
                subFilter:
                  name: custom.ext_authz
        patch:
          operation: INSERT_AFTER
          value:
            name: custom.lua
    [...]
    

    所以过滤器链看起来像:

    ~ -> custom.ext_authz -> custom.lua -> envoy.filters.http.router -> ~

    您可以使用 envoy 仪表板验证您的设置:

    • 运行istioctl dashboard envoy ingress-gateway-<id>.istio-system
    • 如果浏览器没有自动打开,请在 url 上打开浏览器
    • config_dump

    显示所有过滤器(按名称搜索),因此您可以验证您的设置和顺序。

    【讨论】:

      猜你喜欢
      • 2014-05-24
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-01
      • 1970-01-01
      • 2019-12-31
      相关资源
      最近更新 更多