如何解决EnvoyFilter:应用 ExtAuthz 过滤器,然后是 Lua 过滤器
我正在尝试构建一个 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
解决方法
在您的情况下,过滤器链由
定义- 您在匹配部分定义的 subFilter.name
- 补丁部分中过滤器的名称
我发现它更容易理解为两个单独的过滤器(我调整了名称):
您的 ExtAuthz
过滤器插入在过滤器 envoy.filters.http.router
之前,名称为 custom.ext_authz
。
[...]
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 -> ~
您可以使用特使仪表板验证您的设置:
- 运行
istioctl dashboard envoy ingress-gateway-<id>.istio-system
- 如果浏览器没有自动打开,请在网址上打开浏览器
- 按
config_dump
显示所有过滤器(按名称搜索它们),因此您可以验证您的设置和顺序。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。