Using Tyk gateway with linkerd

I am trying to use Tyk with a linkerd backend.

I have configured linkerd correctly in the sense that I can call my backend webapp as such:

http GET my-marathon-host:4140/api/v1/hello/world Host:hello-world.sandbox

Now I am trying to get that same functionality through the gateway and API designer.

I have the target URL set to my-marathon-host:4140 and in the Endpoint Designer I add a header: Host: hello-world.sandbox

but when I inspect the incoming request I see:

GET /api/v1/hello/world HTTP/1.1
Host: my-marathon-host:4140
User-Agent: HTTPie/0.9.6
Accept: */*
Accept-Encoding: gzip, deflate
Authorization: 123456
X-Forwarded-For: x.x.x.x

Is this the right way to set the Host header so linkerd can correctly route the request on the backend?

Corresponding documentation:
https://linkerd.io/1/features/http-proxy/ (See Alternatives section)

Thanks!

This is unlikely to work - Tyk is itself a proxy and modifies the host header as it passes through the stack, in fact it will most likely overwrite your host header changes as it runs the proxy, which is why it hasn’t changed.

Is there a way to integrate Tyk with Linkerd? I have tried setting http_proxy variable in /etc/environment but I still see the same error (even after a restart of the Tyk server).

Happy Easter!

Hi,

I’d first check to make sure that the path you are targetting is actually being processed - can you add another header to it (like Foo: bar), if you see this header in your outbound request, then we can confirm it’s being captured.

Next, you could try to delete the host header first, (deletes happen before Add, so that you can substitute).

Results:

Adding another header using endpoint designer:

Host: x.x.x.x:1234
User-Agent: HTTPie/0.9.6
Accept: */*
Accept-Encoding: gzip, deflate
Authorization: abcd1234
Foo: Bar
X-Forwarded-For: x.x.x.x

I tried removing the Host header in the endpoint designer but am still seeing the Host header at linkerd input.

Hey Martin,

I found a way to resolve it in my linkerd config. By default linkerd uses the Host header for figuring out the routing, you can override it by adding the identifier property as such:

...
routers:
- protocol: http
  identifier:
    kind: io.l5d.header.token
    header: custom-header
...

I used the Endpoint Designer to then add custom-header to all of my requests with the linkerd app id and it works successfully. Maybe this could be included in the docs?

1 Like

That’s fantastic news - glad to hear that it works. Yes we should be adding this to our docs.

Sorry I couldn’t help more - I’m not that familiar with linkerd as a platform :-/

Not a problem, got me more familiar with the linkerd architecture myself.

Should I suggest an edit on this page: https://tyk.io/tyk-documentation/ensure-high-availability/service-discovery/service-discovery-examples/

Would be more than happy to contribute.

1 Like

Yes please, that would be awesome :slight_smile:

quick question, the edits are per SD example, how do I suggest an addition to the page?

Hi Shaishav,

edit suggestions are per section. Therefore you may choose any section to send us your suggestion and we will check it.

Thanks,
Kos @ Tyk Support Team

I have submitted an edit on the page with some example code and process.

Thanks!

2 Likes

Edit received and we’ll factor it into the next docs update, - thanks!

M.

Awesome. It works!
I check this (192.168.0.1 https://19216801help.com) for router issues.