英文:
How to apply negative condition to istio URI regex pattern
问题
我正在尝试在 Istio 网关中应用否定条件和允许的 URI。
允许的 URI:
- /guest/*
- /guest/profile
- /guest/address
不允许的 URI:
- /guest/v2 [任何以 guest 后面跟着 v2 的内容]
- /guest/v2/profile
- /guest/v2/address
问题
我们如何在 Istio 虚拟服务中指定它不应转发任何 v2 流量,只转发其他流量?我尝试了类似于 guest/(?:[^v\W]|v[^2\W])\w*
的正则表达式,它确实避免了 guest/v2
前缀,但无法处理其他情况,比如 /guest/address/list
。
http:
- match:
- uri:
regex: guest/(?:[^v\W]|v[^2\W])\w*
route:
- destination:
port:
number: 8080
host: my-guest.svc
英文:
I'm trying to apply a negate condition along with allowed URIs through Istio gateway.
Allowed:
- /guest/*
- /guest/profile
- /guest/address
Not Allowed:
- /guest/v2 [anything that goes v2 after guest]
- /guest/v2/profile
- /guest/v2/address
Question
How exactly do we specify in the istio virtual service that it should not forward any v2 traffic but just others? I tried something like this guest/(?:[^v\W]|v[^2\W])\w*
this for sure avoids the guest/v2
prefix but not working others like /guest/address/list
http:
- match:
- uri:
regex: guest/(?:[^v\W]|v[^2\W])\w*
route:
- destination:
port:
number: 8080
host: my-guest.svc
答案1
得分: 1
如果您正在使用Istio,那么添加一个路由规则来匹配任何/guest/v2(/.*)?
路径,并通过注入适当的HTTP状态(400 Bad Request
、403 Forbidden
或404 Not Found
之一)来注入一个中断故障,这样做会更容易。
该规则必须在处理有效路径的规则之前匹配。
-
参考链接:https://istio.io/latest/docs/tasks/traffic-management/fault-injection/
-
参考链接:https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPFaultInjection
英文:
If you're using Istio, wouldn't it be easier to add a routing rule that matches any /guest/v2(/.*)?
paths, and fails the request by injecting an abort fault with an appropriate HTTP status (one of 400 Bad Request
, 403 Forbidden
, or 404 Not Found
) by injecting an abort fault?
That rule would have to match before the rule that handles the valid paths.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论