Show HN: TailGuard – Bridge your WireGuard router into Tailscale via a container

github.com

40 points by juhovh 14 hours ago

My elderly parents are behind a 5G connection in rural areas, and I help them manage their network from overseas. I found a reasonably priced 5G router that can do external antennas required for it to work, but the only reasonable ways to get access to it is either through OpenVPN or WireGuard, the latter of which is much more lightweight and preferred with the memory constraints of the device.

The problem with WireGuard is that it requires handling key management oneself, and configuring the keys to every device you want to access it from. It also doesn't play nicely together with other VPNs, meaning I ended up connecting and disconnecting VPNs whenever I wanted to use them. This is especially evident on my phone, which only allows one VPN app at a time.

I was already using Tailscale as an easy way to handle homelab access with SSO, even if some computers are behind ISP CGNAT, and came up with this idea of spinning up a Docker container to connect the two. I found some suggestions for it online, but nothing ready to use. It ended up being more work than I expected to fine tune the routing, IPv6, firewall settings, re-resolving the DNS of the router on IP address changes etc.

I got it very stable eventually though, and wanted to share with everyone else. I think it's cool to have the WireGuard router looking like any other Tailscale node in my tailnet now.

Jnr 18 minutes ago

I use tailscale and wireguard and I route traffic between them, so I can't understand why are so many lines of code needed? Can't you simply enable subnet routing on the tailscale node (single argument does that) and perhaps add additional subnet to the addresses list of wireguard peer?

  • juhovh a minute ago

    You definitely don't need that many lines of code, started with just a couple. Then started coming across several issues, as an example:

    - the router is behind DDNS and changes its IP address on every connect, had to set up reresolve script and cron

    - my WireGuard was capturing the default route and I wanted to use the DNS server behind the tunnel when using it as exit node, but that initially broke the DNS reresolve

    - one WireGuard tunnel only supported IPv6, but the node I was running on had dual stack, half of the traffic ended up using IPv6 and not going through the tunnel at all

    - when routing incoming connections from the other end of the tunnel to the tailnet, I realised Tailscale does SNAT by default for connections from tailnet to the router (this can be disabled), but the WireGuard connections were coming from an unknown subnet and I had to add masquerading rules

    - Tailscale doesn't work so nicely with firewalls, it wants to either inject its chains as first or make you configure it after the startup, worked around by modifying a healthcheck to fix the firewall after startup

    - I wanted to exclude the WireGuard device from Tailscale monitoring to avoid noise, there's a patch and multiple issues for that on GitHub that haven't been merged, included the patches in my image

    I may have forgotten some other edge cases that came up, but here's a few. In addition, I wanted it to automatically parse the advertised subnets from the WG config, which added to the scripts a bit.

    In short, it started out as a hack I didn't even think would be would be worth sharing, but more things broke than I would've imagined. So wanted to share with anyone who might find it useful.

jasonriddle an hour ago

So, it looks like this might work with fly.io?

fly.io provides a way to connect to their servers via wireguard (https://fly.io/docs/blueprints/connect-private-network-wireg...), and so tailguard could connect to their wireguard instance?

  • juhovh an hour ago

    Not super familiar with fly.io, but with a quick look at that page it should work just fine.

    Just instead of dropping that camellia.conf to the WireGuard MacOS client or Linux wg-quick, spin up the TailGuard container somewhere (pretty much anywhere, but with good ping to fly.io). That way you should have the fly.io private network accessible in your Tailscale tailnet, it runs wg-quick internally alongside Tailscale anyway, just with a bit of scripting to automatically configure the network and the firewall to avoid connections leaking.

    If it doesn't work, feel free to raise an issue and I can have a look.

oe 20 minutes ago

Which 5G router do you use?

  • juhovh 12 minutes ago

    The one they ended up using was TP-Link Deco X50-5G, but honestly I'm not sure if I can fully recommend that. It has had its own share of problems...

notadeveloper 2 hours ago

What about the Subnet Router functionality that Tailscale has?

  • salviati 2 hours ago

    I had a very similar problem to the one OP was facing, and I solved it by connecting my fenced router (a router with no fixed public IP) via Wireguard to one machine in my tailscale network, and set up subnet routers so I can access it from any machine in my tailscale.

    It works great.

    I might misunderstand, but to me it looks like the solution in this post might be better than my setup because if that single node is down I won't be able to reach the fenced router.

    • juhovh an hour ago

      Cool, this sounds like a very similar setup actually!

      Even in this case, you still need to have a node somewhere to run the container and store the WireGuard keys, to be able to link the tailnet and the WireGuard endpoint. So that single point of failure still unfortunately remains.

      The benefit of having it all configured in a single container means it's pretty easy to spin up anywhere (where the fenced router is accessible), all you need is the tunnel config file.

      I also wanted to make sure it works for both IPv4 and IPv6 connections, because many ISPs in my area are starting to only give public IPv6 addresses. That way as long as the WireGuard router has IPv6 and the node running the container has IPv4/IPv6 dual stack, one can still access the Wireguard from an IPv4 only device.

  • juhovh 2 hours ago

    This is using the subnet router functionality of Tailscale. However, instead of advertising subnets of the local physical network, as explained in the Tailscale docs, it's automatically parsing the given WireGuard config and advertising the subnets at the other end of the WireGuard tunnel.

    It will also by default route traffic to the already advertised other subnets in the tailnet, but taking that into use requires a bit of manual configuration on the other end of the WireGuard tunnel. Each subnet needs to be routed through the WireGuard tunnel first to make it work.