Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix netstack to forward TCP sessions to local addresses #62

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

spikecurtis
Copy link

@spikecurtis spikecurtis commented Oct 2, 2024

relates to: coder/coder#14715

For CoderVPN, we need Agents to operate on a separate Unique Local Address (ULA) prefix than Tailscale, so that CoderVPN and Tailscale can both run on the same computer.

This PR fixes an issue in the Tailscale netstack, where it uses the hardcoded Tailscale ULA to decide whether to forward TCP connections to localhost (127.0.0.1), rather than just checking whether the destination is an address assigned to the node.

Pretty sure this is just a bug / another case of assumptions that are true for Tailscale but not for us. acceptTCP() makes a call to removeSubnetAddress() in a defer. This was originally conditional on isTailscaleIP, but the check for addSubnetAddress() on line 311 uses isLocalIP(). Stepping thru the code, if we accept a TCP connection for an address that is local, but not in the Tailscale service prefix (i.e. one in our new Coder service prefix), we call removeSubnetAddress() without ever having called addSubnetAddress(), and decrement the connection count on that address to -1, which is almost certainly incorrect. It worked fine for Tailscale because they could safely assume that all local addresses were also Tailscale IPs, but we can't anymore.

Note also that UDP forwarding already uses isLocalIP() to decide whether to forward.

This change passes the local netstack unit tests, but the real tests will be in coder/coder when we show that we can successfully make TCP connections.

Copy link
Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @spikecurtis and the rest of your teammates on Graphite Graphite

@spikecurtis spikecurtis marked this pull request as ready for review October 2, 2024 10:10
Copy link
Member

@ethanndickson ethanndickson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I can confirm it at least doesn't break any existing coder/coder tests.

Copy link
Author

spikecurtis commented Oct 3, 2024

Merge activity

@spikecurtis spikecurtis merged commit 02286e5 into main Oct 3, 2024
7 of 36 checks passed
spikecurtis added a commit to coder/coder that referenced this pull request Oct 4, 2024
fixes #14715

Configures agents to use an address both in the Tailscale service prefix and the new Coder service prefix. Also modifies the Coordinator auth to allow the new prefix.

Updates `coder/tailscale` to include coder/tailscale#62 which fixes a bug around forwarding TCP connections to localhost.  This functionality is tested in the modifications to `TestAgent_Dial`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants