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

Use peer's wireguard port, not our own #2200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

euank
Copy link

@euank euank commented Mar 10, 2025

Description

Before this change, the wireguard code constructed a peer endpoint via "PeerIP + n.dev.listenPort", i.e. we used the peer's IP, but our port.

This works fine if every k8s node has the same ListenPort, which is admittedly the common setup...

However, some people may desire to use different ports for some cases, and in that case, we should respect that different port.

I've manually tested that this works in my cluster, where 1 node has different ports for wireguard from all the others.

After deploying this diff to each node, I get a working pod network.

Note: I believe this is a bugfix which shouldn't break any properly configured setups, so I didn't add an opt-in or opt-out to it. I'm happy to add an opt-in flag if we can think of any reasonable setup this would break.

Release Note

None required

Before this change, the wireguard code constructed a peer endpoint via
"PeerIP + n.dev.listenPort", i.e. we used the peer's IP, but our port.

This works fine if every k8s node has the same ListenPort, which is
admittedly the common setup...

However, some people may desire to use different ports for some cases,
and in that case, we should respect that different port.

I've manually tested that this works in my cluster, where 1 node has
different ports for wireguard from all the others.

After deploying this diff to each node, I get a working pod network.
if n.mode == Ipv4 {
publicEndpoint = fmt.Sprintf("%s:%d", event.Lease.Attrs.PublicIP.String(), n.dev.attrs.listenPort)
} else if n.mode == Ipv6 {
publicEndpoint = fmt.Sprintf("[%s]:%d", event.Lease.Attrs.PublicIPv6.String(), n.dev.attrs.listenPort)
Copy link
Author

Choose a reason for hiding this comment

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

This line had an additional bug of using the ipv6 IP + ipv4 port, so I think this probably wouldn't generally work.

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.

1 participant