tailscale/wgengine
Irbe Krumina 096b090caf
cmd/containerboot,kube,util/linuxfw: configure kube egress proxies to route to 1+ tailnet targets (#13531)
* cmd/containerboot,kube,util/linuxfw: configure kube egress proxies to route to 1+ tailnet targets

This commit is first part of the work to allow running multiple
replicas of the Kubernetes operator egress proxies per tailnet service +
to allow exposing multiple tailnet services via each proxy replica.

This expands the existing iptables/nftables-based proxy configuration
mechanism.

A proxy can now be configured to route to one or more tailnet targets
via a (mounted) config file that, for each tailnet target, specifies:
- the target's tailnet IP or FQDN
- mappings of container ports to which cluster workloads will send traffic to
tailnet target ports where the traffic should be forwarded.

Example configfile contents:
{
  "some-svc": {"tailnetTarget":{"fqdn":"foo.tailnetxyz.ts.net","ports"{"tcp:4006:80":{"protocol":"tcp","matchPort":4006,"targetPort":80},"tcp:4007:443":{"protocol":"tcp","matchPort":4007,"targetPort":443}}}}
}

A proxy that is configured with this config file will configure firewall rules
to route cluster traffic to the tailnet targets. It will then watch the config file
for updates as well as monitor relevant netmap updates and reconfigure firewall
as needed.

This adds a bunch of new iptables/nftables functionality to make it easier to dynamically update
the firewall rules without needing to restart the proxy Pod as well as to make
it easier to debug/understand the rules:

- for iptables, each portmapping is a DNAT rule with a comment pointing
at the 'service',i.e:

-A PREROUTING ! -i tailscale0 -p tcp -m tcp --dport 4006 -m comment --comment "some-svc:tcp:4006 -> tcp:80" -j DNAT --to-destination 100.64.1.18:80
Additionally there is a SNAT rule for each tailnet target, to mask the source address.

- for nftables, a separate prerouting chain is created for each tailnet target
and all the portmapping rules are placed in that chain. This makes it easier
to look up rules and delete services when no longer needed.
(nftables allows hooking a custom chain to a prerouting hook, so no extra work
is needed to ensure that the rules in the service chains are evaluated).

The next steps will be to get the Kubernetes Operator to generate
the configfile and ensure it is mounted to the relevant proxy nodes.

Updates tailscale/tailscale#13406

Signed-off-by: Irbe Krumina <irbe@tailscale.com>
2024-09-29 16:30:53 +01:00
..
bench ipn/ipnlocal, all: plumb health trackers in tests 2024-05-07 22:22:10 -07:00
capture wgengine/capture: fix v6 field typo in wireshark dissector 2024-08-03 14:56:17 -07:00
filter wgengine/filter: support FilterRules matching on srcIP node caps [capver 100] 2024-06-20 12:27:04 -07:00
magicsock wgengine/magicsock: fix check for EPERM on macOS 2024-09-25 16:33:36 -07:00
netlog wgengine: add exit destination logging enable for wgengine logger (#11952) 2024-05-02 13:55:05 -04:00
netstack util/usermetrics: make usermetrics non-global 2024-09-25 15:57:00 +02:00
router cmd/containerboot,kube,util/linuxfw: configure kube egress proxies to route to 1+ tailnet targets (#13531) 2024-09-29 16:30:53 +01:00
wgcfg ipn,wgengine: remove vestigial Prefs.AllowSingleHosts 2024-05-17 20:50:19 -07:00
wgint wgengine{,/wgint}: add wgint.Peer wrapper type, add to wgengine.Engine 2024-02-28 09:50:18 -08:00
wglog all: use Go 1.22 range-over-int 2024-04-16 15:32:38 -07:00
winnet all: add test for package comments, fix, add comments as needed 2024-07-10 09:57:00 -07:00
mem_ios.go all: update copyright and license headers 2023-01-27 15:36:29 -08:00
pendopen.go net/flowtrack: optimize Tuple type for use as map key 2024-06-18 21:31:48 -07:00
userspace_ext_test.go util/usermetrics: make usermetrics non-global 2024-09-25 15:57:00 +02:00
userspace_test.go util/usermetrics: make usermetrics non-global 2024-09-25 15:57:00 +02:00
userspace.go wgengine: make opts.Metrics mandatory 2024-09-26 13:09:47 +02:00
watchdog_js.go all: update copyright and license headers 2023-01-27 15:36:29 -08:00
watchdog_test.go util/usermetrics: make usermetrics non-global 2024-09-25 15:57:00 +02:00
watchdog.go ipn/ipnlocal,net/tstun,wgengine: create and plumb jailed packet filter 2024-05-06 15:32:22 -07:00
wgengine.go all: add test for package comments, fix, add comments as needed 2024-07-10 09:57:00 -07:00