如何将负条件应用于Istio URI正则表达式模式?

huangapple go评论118阅读模式
英文:

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 Request403 Forbidden404 Not Found之一)来注入一个中断故障,这样做会更容易。

该规则必须在处理有效路径的规则之前匹配。

英文:

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.

huangapple
  • 本文由 发表于 2022年11月30日 03:37:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/74619382.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定