Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

istio: VirtualService rewrite to the root url

I have an Istio 1.4.6 VirtualService with a match and a url rewrite defined as follows:

    match:
    - authority:
        prefix: example.com
      uri:
        prefix: /foo/bar
    rewrite:
      uri: /
    route:
    - destination:
        host: some-service
        port:
          number: 80

I would like a rewrite like follows:

Traffic directed to /foo/bar or any subpath of that should be rewritten to / plus any subpath on some-service.

i.e.
example.com/foo/bar -> some-service
example.com/foo/bar/subpath -> some-service/subpath
example.com/foo/bar/subpath/anothersubpath -> some-service/subpath/anothersubpath

However, when I sysdig the traffic coming into some-service, I see that Istio has rewritten the path to:

GET //subpath/anothersubpath HTTP/1.1

Notice the two slashes in the GET request. In the VirtualService spec rewrite.uri field, I can't seem to leave that field empty or add an empty string there. Doing so causes the resource not to validate.

I.e. I can NOT do this:

    rewrite:
      uri: ""

And can NOT do this

    rewrite:
      uri:

How can I define a VirtualService rewrite to send traffic to the root of the destination service? Any help is much appreciated.

like image 719
Joe J Avatar asked Dec 23 '22 18:12

Joe J


2 Answers

There is a github issue about this.

The simplest fix is to add whitespace in the uri as long as You are not running .net core application.

    rewrite:
      uri: " "

Other workaround can be found here,

Hope it helps.

like image 72
Piotr Malec Avatar answered Jan 04 '23 02:01

Piotr Malec


another way of doing this is:

    - match:
        - uri:
            prefix: "/v2/my-service/"
        - uri:
            exact: "/v2/my-service"
      rewrite:
        uri: "/"
      route:
        - destination:
            host: my-internal-service
            port:
              number: 6666
like image 25
Hitmands Avatar answered Jan 04 '23 00:01

Hitmands