Skip to content

wgengine/router,util/linuxfw: don't attempt to configure IPv6 firewall rules with ip6tables that don't support filter table - #11546

Merged
irbekrm merged 1 commit into
mainfrom
irbekrm/router
Mar 29, 2024
Merged

irbekrm merged 1 commit into
mainfrom
irbekrm/router

Conversation

@irbekrm

@irbekrm irbekrm commented Mar 28, 2024 •

Copy link
Copy Markdown
Contributor

However, netfilter can also be off during a regular Linux client router setup, so this resulted in a buggy sequence:

  1. wgengine starts, netfilter is set to off
  2. UpdateMagicSockPort runs with port for IPv6 and because netfilter is off + our changed logic, it determines that linuxRouter.magicsockPortv6 needs to be set (here)
  3. router gets reconfigured for the linux client and the netfilter is turned on
  4. linuxRouter.setNetfilterMode runs with a netfilter mode change false -> true, so we hit this path and because linuxRouter.magicsockPortv6 is still set and we use the current netfilter mode (off) in the IPv6 availability check, we end up attempting to set the IPv6 firewall rules, error out and the rest of the router config remains unset, resulting in a broken client

This PR attempts to ensure that:

  • if the host supports IPv6 we always set routing policy rules (To preserve IPv6 routing support in Synology)
  • if the firewall is in iptables mode, but ip6tables filter table was not found, we don't attempt to configure any IPv6 firewall rules

I have tested this with an IPv4 host (container) with no IPv6 filter table support:

  • on host:
Details / # env | grep TS_DEBUG_FIREWALL TS_DEBUG_FIREWALL_MODE=iptables / # ip -6 rule list 0: from all lookup local 5210: from all fwmark 0x80000/0xff0000 lookup main 5230: from all fwmark 0x80000/0xff0000 lookup default 5250: from all fwmark 0x80000/0xff0000 unreachable 5270: from all lookup 52 32766: from all lookup main / # ip6tables -t filter -L modprobe: can't change directory to '/lib/modules': No such file or directory ip6tables v1.8.9 (legacy): can't initialize ip6tables table `filter': Table does not exist (do you need to insmod?) Perhaps ip6tables or your kernel needs to be upgraded.
  • logs:
Details ... boot: 2024/03/28 19:09:27 [v1] kernel supports IPv6 policy routing (found 6 rules) boot: 2024/03/28 19:09:27 ip6tables filtering is not supported on this host: running [/sbin/ip6tables -t filter -S --wait]: exit status 3: modprobe: can't change directory to '/lib/modules': No such file or directory ip6tables v1.8.9 (legacy): can't initialize ip6tables table `filter': Table does not exist (do you need to insmod?) Perhaps ip6tables or your kernel needs to be upgraded. boot: 2024/03/28 19:09:27 v6 = true, v6filter = false, v6nat = false ...

I have also tested it on an IPv6 host (container) with firewall in iptables mode:

  • host
Details # env | grep TS_DEBUG_FIRE TS_DEBUG_FIREWALL_MODE=iptables / # ip -6 rule list 0: from all lookup local 5210: from all fwmark 0x80000/0xff0000 lookup main 5230: from all fwmark 0x80000/0xff0000 lookup default 5250: from all fwmark 0x80000/0xff0000 unreachable 5270: from all lookup 52 32766: from all lookup main / # ip6tables -t filter -L Chain INPUT (policy ACCEPT) target prot opt source destination ts-input all -- anywhere anywhere

Chain FORWARD (policy ACCEPT)
target prot opt source destination
ts-forward all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Chain ts-forward (1 references)
target prot opt source destination
MARK all -- anywhere anywhere MARK xset 0x40000/0xff0000
ACCEPT all -- anywhere anywhere mark match 0x40000/0xff0000
ACCEPT all -- anywhere anywhere

Chain ts-input (1 references)
target prot opt source destination
ACCEPT all -- fd7a:115c:a1e0::8f01:5e37 anywhere
ACCEPT all -- anywhere anywhere
ACCEPT udp -- anywhere anywhere udp dpt:53101

  • logs
Details ... boot: 2024/03/28 19:51:09 [v1] kernel supports IPv6 policy routing (found 6 rules) 2024/03/28 19:51:09 magicsock: derp-8 connected; connGen=1 2024/03/28 19:51:09 health("overall"): ok boot: 2024/03/28 19:51:09 v6 = true, v6filter = true, v6nat = true ...

When/if it merges, we'd still have to test with Synology.

Updates #11540

@irbekrm
irbekrm marked this pull request as draft March 28, 2024 14:58
@irbekrm
irbekrm force-pushed the irbekrm/router branch 3 times, most recently from aa59e43 to b2501b2 Compare March 28, 2024 18:02
@irbekrm irbekrm changed the title wgengine/router: don't set the magicsock IPv6 port if the system does not support IPv6 wgengine/router,util/linuxfw: don't attempt to configure IPv6 firewall rules with ip6tables that don't support filter table Mar 28, 2024
@irbekrm
irbekrm marked this pull request as ready for review March 28, 2024 18:45
@irbekrm
irbekrm requested review from KevinLiang10 and raggi March 28, 2024 18:46
Comment thread util/linuxfw/fake.go
ipt6 := newFakeIPTables()

iptr := &iptablesRunner{ipt4, ipt6, true, true}
iptr := &iptablesRunner{ipt4, ipt6, true, true, true}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could you add field labels to this constructor? it probably needed them before but 3 bools is definitely getting to a lot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread wgengine/router/router_linux.go Outdated
for cidr := range r.addrs {
if err := r.addLoopbackRule(cidr.Addr()); err != nil {
return err
return fmt.Errorf("error adding loopback rule: %v", err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

%w rather than %v when wrapping, then errors.Is and friends work

…tial iptables mode

We have hosts that support IPv6, but not IPv6 firewall configuration
in iptables mode.
We also have hosts that have some support for IPv6 firewall
configuration in iptables mode, but do not have iptables filter table.
We should:
- configure ip rules for all hosts that support IPv6
- only configure firewall rules in iptables mode if the host
has iptables filter table.

Updates #11540

Signed-off-by: Irbe Krumina <[email protected]>
@irbekrm
irbekrm merged commit 5fb721d into main Mar 29, 2024
@irbekrm
irbekrm deleted the irbekrm/router branch March 29, 2024 05:23
chen8945 pushed a commit to Ckid-Home/tailscale that referenced this pull request Jul 31, 2024
…tial iptables mode (tailscale#11546)

We have hosts that support IPv6, but not IPv6 firewall configuration
in iptables mode.
We also have hosts that have some support for IPv6 firewall
configuration in iptables mode, but do not have iptables filter table.
We should:
- configure ip rules for all hosts that support IPv6
- only configure firewall rules in iptables mode if the host
has iptables filter table.

Updates tailscale#11540

Signed-off-by: Irbe Krumina <[email protected]>
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.

2 participants