0

目前我们正在使用 EnvoyFilter 来添加身份验证检查。这个过滤器使用了 envoyext_authz过滤器。

我们有一个用于匿名和授权调用的 GraphQL 端点。由于公共呼叫不需要身份验证检查/过滤器,我希望能够基于 cookie 跳过此过滤器。我尝试在网上搜索解决方案,但找不到。

请参阅下面的过滤器配置:

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: oathkeeper
  namespace: istio-system
spec:
  workloadSelector:
    labels:
      istio: ingressgateway
  configPatches:
    - applyTo: HTTP_FILTER
      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: envoy.filters.http.ext_authz
          typed_config:
            '@type': type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthz
            failure_mode_allow: false
            http_service:
              path_prefix: /decisions
              server_uri:
                uri: http://oathkeeper-api.default.svc.cluster.local:4456
                cluster: outbound|4456||oathkeeper-api.default.svc.cluster.local
                timeout: 10s
              authorization_request:
                allowed_headers:
                  patterns:
                  - exact: accept
                  - exact: authorization
                  - exact: cookie
                  - exact: content-type
                  - exact: x-forwarded-for
                  - exact: x-forwarded-proto
                  - exact: x-forwarded-host
              authorization_response:
                allowed_upstream_headers:
                  patterns:
                  - exact: authorization
4

1 回答 1

0

VirtualService您可以为缺少 cookie 的端点配置第二条路由

[...]
  http:
  - name: secured-graph-ql-endpoint
    match:
    - headers:
        cookie:
          regex: <some-regex>
      uri:
        prefix: /graph-ql-endpoint
    route:
    - destination:
        host: graph-ql-endpoint
        port:
          number: 8000
  - name: public-graph-ql-endpoint
    match:
    - uri:
        prefix: /graph-ql-endpoint
    route:
    - destination:
        host: graph-ql-endpoint
        port:
          number: 8000

使用正则表达式 ( <some-regex>) 取决于您的 cookie。你也可以有一个类似authenticated: true和匹配的标题,而不是(丢失的)cookie。

创建一个EnvoyFilter以禁用该ExtAuthz路由。

apiVersion​: ​networking.istio.io/v1alpha3 
kind​: ​EnvoyFilter 
metadata​: 
 ​ name​: bypass-ext-authz 
 ​ namespace​: ​istio-system 
spec​: 
  workloadSelector​: 
 ​   labels​: 
 ​     istio​: ​ingressgateway 
 ​ configPatches​: 
 ​  - ​applyTo​: ​HTTP_ROUTE 
 ​    ​match​: 
 ​      ​routeConfiguration​: 
 ​        vhost​: 
 ​          route​: 
 ​            #​from virtual service http route name 
 ​            name​: public-graph-ql-endpoint
 ​    ​patch​: 
 ​      ​operation​: ​MERGE 
 ​      ​value​: 
         ​name​: ​custom.bypass_extauthz 
 ​        ​typed_per_filter_config​: 
 ​          ​envoy.ext_authz​: 
 ​            ​&quot;​@type​&quot;​: ​type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute 
 ​            ​disabled​: ​true

您还可以configPatchEnvoyFilter.

话说回来:

从设计/安全的角度来看,我宁愿有一个不同的应用程序,它是公开的,并为匿名用户查询安全的 GraphQL 端点。这使您可以更好地控制流量,例如外部用户的速率限制、更容易的 dos 保护等。

于 2021-12-04T20:54:51.167 回答