如何解决istio使节过滤器在minikube中不起作用
大家好,我在本地节点minikube和istio上设置和外部身份验证系统遇到问题。我已经在helloworld上设置了两个部署,另一个是auther。我想要的是通过将请求发送到/ auther路由来将所有请求授权到/ hello路由,该请求将连接到auther服务,并且如果设置了特定的标头(如授权中的jwt令牌),则返回200状态或401状态(如果没有)设置好了。 我试图使用此配置文件,该配置文件正在使用envoy ext auth过滤器,但没有任何效果。尽管所有传递给/ hello的请求都得到403,但它没有向我的auther服务发送任何请求。 这是我的特使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"
- ....
让我知道您是否需要进一步的坚持!