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

Install iptables rules to allow wireguard packets #7030

Merged
merged 1 commit into from
Mar 4, 2025

Conversation

wenyingd
Copy link
Contributor

@wenyingd wenyingd commented Feb 26, 2025

This change is to actively configure the iptables rules wireguard.port when wireguard is used as the encryption mode. This can fix traffic issues if the Node is configured with iptables default DROP policy.

Fix: #7009

@wenyingd
Copy link
Contributor Author

/test-all
/test-windows-all

@wenyingd
Copy link
Contributor Author

/test-windows-all

2 similar comments
@XinShuYang
Copy link
Contributor

/test-windows-all

@XinShuYang
Copy link
Contributor

/test-windows-all

Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

cc @Dhruv-J who is working on something similar for NodeLatencyMonitor (ICMP filter rules)

@wenyingd wenyingd changed the title Install iptables rules to allow packets to wireguard port Install iptables rules to allow wireguard packets Feb 27, 2025
@wenyingd
Copy link
Contributor Author

/test-all
/test-windows-all

},
},
{
name: "encap,wireguard,egress=true,multicastEnabled=true,proxyAll=true,nodeNetworkPolicy=true,nodeSNATRandomFully=true",
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make the tests a bit less verbose if we removed multicast and proxyAll?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I will update.

Copy link
Contributor

Choose a reason for hiding this comment

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

I saw the change for the second test case but not this one, was it intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this case is for the case to test all features enabled. hmm, maybe I should remove the previous one ""encap,egress=true,multicastEnabled=true,proxyAll=true,nodeNetworkPolicy=true,nodeSNATRandomFully=true"?

Copy link
Contributor

@luolanzone luolanzone left a comment

Choose a reason for hiding this comment

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

a few nits

Comment on lines 162 to 165
// wireguardIPTablesIPv4 caches all existing IPv4 iptables chains and rules for Wireguard.
wireguardIPTablesIPv4 sync.Map
// wireguardIPTablesIPv6 caches all existing IPv6 iptables chains and rules for Wireguard.
wireguardIPTablesIPv6 sync.Map
Copy link
Contributor

Choose a reason for hiding this comment

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

s/Wireguard/WireGuard
please check other occurrences.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a comment in this doc https://github.com/antrea-io/antrea/blob/main/docs/network-requirements.md to remind users about this change?
@antoninbas any suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, good idea, let's mention it in that doc
we should also mention in the table that most of these ports are configurable (right now we only mention it for the BGP server port)

@@ -244,7 +244,9 @@ func run(o *Options) error {
multicastEnabled,
o.config.SNATFullyRandomPorts,
*o.config.Egress.SNATFullyRandomPorts,
serviceCIDRProvider)
serviceCIDRProvider,
wireguardConfig.Port,
Copy link
Contributor

Choose a reason for hiding this comment

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

Another concern is about the WireGuard port check, looks like we didn't check the range before:

	if o.config.WireGuard.Port == 0 {
		o.config.WireGuard.Port = apis.WireGuardListenPort
	}

I suppose we should go through and update the validation to make sure it's a valid port? @antoninbas

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds good to me but we should do it in a separate PR, we have other ports that we could validate as well, e.g. the tunnelPort. Can you open an issue to track this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Issue created: #7035, I will take a look at it later today.

@wenyingd wenyingd force-pushed the issue_7009 branch 2 times, most recently from 71afced to a209673 Compare February 28, 2025 06:55
@wenyingd
Copy link
Contributor Author

/test-all
/test-windows-all

@wenyingd
Copy link
Contributor Author

/test-windows-all

| Antrea with feature BGPPolicy enabled | Selected by user-provided BGPPolicies | TCP 179<sup>[1]</sup> | |
| All | Kube-apiserver host | TCP 443 or 6443<sup>[2]</sup> | |
| All | All | TCP 10349, 10350, 10351, UDP 10351 | |
| Configuration | Host(s) | Protocols/Ports | Configurable | Other |
Copy link
Member

@tnqn tnqn Feb 28, 2025

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

Comment on lines 736 to 738
addFilterRulesToChain(iptablesFilterRulesByChainV4, &c.nodeNetworkPolicyIPTablesIPv4)
addFilterRulesToChain(iptablesFilterRulesByChainV4, &c.wireguardIPTablesIPv4)
Copy link
Member

Choose a reason for hiding this comment

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

should static rule (wireguard) be installed before the dynamic rules (NodeNetworkPolicy)? this should be slightly more efficient as wireguard traffic will be the majority of node traffic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated accordingly.

@wenyingd wenyingd force-pushed the issue_7009 branch 2 times, most recently from 2e80f16 to fa0e05a Compare March 3, 2025 01:58
@wenyingd
Copy link
Contributor Author

wenyingd commented Mar 3, 2025

/test-all
/test-windows-all

@wenyingd
Copy link
Contributor Author

wenyingd commented Mar 3, 2025

/test-windows-conformance

1 similar comment
@XinShuYang
Copy link
Contributor

/test-windows-conformance

@@ -100,7 +100,7 @@ type routeClientOptions struct {
}

func newTestRouteClient(networkConfig *config.NetworkConfig, options routeClientOptions) (*route.Client, error) {
return route.NewClient(networkConfig, options.noSNAT, false, false, false, false, options.nodeSNATRandomFully, false, nil)
return route.NewClient(networkConfig, options.noSNAT, false, false, false, false, options.nodeSNATRandomFully, false, nil, 51820)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe use the WireGuardListenPort constant from pkg/apis to make the code more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

},
},
{
name: "encap,wireguard,egress=true,multicastEnabled=true,proxyAll=true,nodeNetworkPolicy=true,nodeSNATRandomFully=true",
Copy link
Contributor

Choose a reason for hiding this comment

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

I saw the change for the second test case but not this one, was it intentional?

}

iptablesFilterRulesByChainV4 := make(map[string][]string)
addFilterRulesToChain(iptablesFilterRulesByChainV4, &c.wireguardIPTablesIPv4)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add a comment explaining that we are intentionally adding static iptables rules (WireGuard for now) first for performance reasons.


[1] _The default value is 179, but a user created BGPPolicy can assign a different
port number._

[2] _The value is passed to kube-apiserver `--secure-port` flag. You can find the port
number from the output of `kubectl get svc kubernetes -o yaml`._

[3] _Antrea now automatically adds the firewall rules to allow the WireGuard packets,
Copy link
Contributor

Choose a reason for hiding this comment

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

better to specify the version (starting with v2.4) instead of writing "now" IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, updated.

@wenyingd wenyingd force-pushed the issue_7009 branch 2 times, most recently from 36eea72 to 321373e Compare March 3, 2025 10:53
@wenyingd
Copy link
Contributor Author

wenyingd commented Mar 3, 2025

/test-all

| Antrea Multi-cluster with WireGuard encryption | Multi-cluster Gateway Node | UDP 51821 | Yes | |
| Antrea with feature BGPPolicy enabled | Selected by user-provided BGPPolicies | TCP 179<sup>[1]</sup> | Yes | |
| All | Kube-apiserver host | TCP 443 or 6443<sup>[2]</sup> | No | |
| All | All | TCP 10349, 10350, 10351, UDP 10351 | No | |
Copy link
Member

Choose a reason for hiding this comment

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

10349, 10350, and 10351 are all configurable.

Actually even kube-apiserver port is configurable via kube-apiserver itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

This change is to actively configure the iptables rules wireguard.port when
wireguard is used as the encryption mode. This can fix traffic issues if the
Node is configured with iptables default DROP policy.

Signed-off-by: Wenying Dong <[email protected]>
@wenyingd
Copy link
Contributor Author

wenyingd commented Mar 4, 2025

/test-all

@wenyingd wenyingd requested a review from tnqn March 4, 2025 05:26
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

Choose a reason for hiding this comment

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

we should probably try to improve this file in the future, as the configurable column is a bit generic and maybe should indicate how the port can be configured. we could also extract the kube-apiserver requirement from the table and mention it separately, as the requirement doesn't come from Antrea.

@antoninbas antoninbas merged commit 525f662 into antrea-io:main Mar 4, 2025
60 checks passed
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.

Explicitly open the wireguard.port on Nodes when using wireguard feature
6 participants