如何解决EnvoyFilter jwt_authn 没有向 istio1.9 中的 etension 服务发送请求
我正在尝试在 istio1.9 中配置自定义身份验证行为:当请求带有过期但有效的 JWT 时,有一个特殊的服务会自动刷新 jwt。 我正在尝试使用 Envoy Filter 来执行此操作,因此我创建了一个配置如下的 envoyfilter:
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: refresh-token-filter
namespace: istio-system
spec:
workloadSelector:
labels:
app: istio-ingressgateway
configPatches:
- applyTo: HTTP_FILTER
match:
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.config.filter.http.ext_authz.v2.ExtAuthz
http_service:
server_uri:
uri: http://token-mng-service.auth.svc.cluster.local:8000
cluster: outbound|8000||token-mng-service.auth.svc.cluster.local
timeout: 1s
authorizationRequest:
allowedHeaders:
patterns:
- exact: authorization
authorizationResponse:
allowedUpstreamHeaders:
patterns:
- exact: username
- exact: id_token
allowedClientHeaders:
patterns:
- exact: id_token
我希望每个请求都会被发送到命名空间 auth 中名为 token-mng-service 的服务,该服务会刷新过期的令牌,然后使用标头名称 id_token 进行响应。 token-mng-service 配置如下:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: token-mng-deployment-v1
namespace: auth
labels:
app: token-mng
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: token-mng
version: v1
strategy:
type: RollingUpdate
template:
metadata:
labels:
app: token-mng
version: v1
spec:
containers:
- name: token-mng
image: token_mng:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8000
---
apiVersion: v1
kind: Service
metadata:
name: token-mng-service
namespace: auth
spec:
ports:
- port: 8000
targetPort: 8000
name: http
selector:
app: token-mng
另外,我创建了一个 RequestAuthentication 如下:
apiVersion: "security.istio.io/v1beta1"
kind: "RequestAuthentication"
metadata:
name: authtest
namespace: istio-system
spec:
selector:
matchLabels:
istio: ingressgateway
jwtRules:
- issuer: "https://192.168.50.113:30443/oauth2/token"
jwksUri: "http://192.168.50.113:30443/oauth2/jwks"
但是,没有请求被发送到我的 tokne-mng-service。我的配置有问题吗? 非常感谢!
解决方法
我在这里猜测但检查生成的 Envoy 配置中的过滤器顺序。如果 JWT 过滤器是第一个,它将检测到过期的令牌并在 ext auth 过滤器有机会刷新它之前导致 401。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。