From cdcf8d51cf57203bbed60418237f2779c2b4867c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 10 Jan 2025 20:20:57 -0800 Subject: [PATCH] lanscaping: omit nftables Change-Id: I5ce60ade4ec0c818ce83a08950847f7a4baaeabf Signed-off-by: Brad Fitzpatrick --- Makefile | 7 +- cmd/tailscale/depaware-minlinux.txt | 44 +++++----- cmd/tailscaled/depaware-minlinux.txt | 54 ++++++------ util/linuxfw/iptables_for_svcs.go | 2 +- util/linuxfw/nftables.go | 2 +- util/linuxfw/nftables_for_svcs.go | 13 +-- util/linuxfw/nftables_runner.go | 106 +---------------------- util/linuxfw/nftables_types.go | 2 +- util/linuxfw/omit_nftables.go | 24 ++++++ util/linuxfw/runner.go | 122 +++++++++++++++++++++++++++ 10 files changed, 199 insertions(+), 177 deletions(-) create mode 100644 util/linuxfw/omit_nftables.go create mode 100644 util/linuxfw/runner.go diff --git a/Makefile b/Makefile index 7300a2626..f445e577c 100644 --- a/Makefile +++ b/Makefile @@ -24,14 +24,15 @@ updatedeps: ## Update depaware deps tailscale.com/cmd/k8s-operator \ tailscale.com/cmd/stund -MIN_OMITS ?= ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube,ts_omit_completion,ts_omit_netstack +MIN_OMITS ?= ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube,ts_omit_completion,ts_omit_netstack,ts_omit_nftables min: ./tool/go build -o $$HOME/bin/tailscaled.min -ldflags "-w -s" --tags=${MIN_OMITS} ./cmd/tailscaled - ls -lh $$HOME/bin/tailscaled.min + GOOS=linux ./tool/go build -o $$HOME/bin/tailscaled.minlinux -ldflags "-w -s" --tags=${MIN_OMITS} ./cmd/tailscaled + ls -l $$HOME/bin/tailscaled.min{,linux} updatemindeps: min - PATH="$$(./tool/go env GOROOT)/bin:$$PATH" ./tool/go run github.com/tailscale/depaware --file=depaware-minlinux.txt --goos=linux --tags=${MIN_OMITS} --update \ + PATH="$$(./tool/go env GOROOT)/bin:$$PATH" ./tool/go run github.com/tailscale/depaware --file=depaware-minlinux.txt --goos=linux,darwin --tags=${MIN_OMITS} --update \ tailscale.com/cmd/tailscaled \ tailscale.com/cmd/tailscale diff --git a/cmd/tailscale/depaware-minlinux.txt b/cmd/tailscale/depaware-minlinux.txt index 48689852d..c063ced19 100644 --- a/cmd/tailscale/depaware-minlinux.txt +++ b/cmd/tailscale/depaware-minlinux.txt @@ -2,7 +2,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep filippo.io/edwards25519 from github.com/hdevalence/ed25519consensus filippo.io/edwards25519/field from filippo.io/edwards25519 - github.com/coreos/go-iptables/iptables from tailscale.com/util/linuxfw + L github.com/coreos/go-iptables/iptables from tailscale.com/util/linuxfw github.com/fxamacker/cbor/v2 from tailscale.com/tka github.com/go-json-experiment/json from tailscale.com/types/opt+ github.com/go-json-experiment/json/internal from github.com/go-json-experiment/json+ @@ -11,27 +11,21 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep github.com/go-json-experiment/json/internal/jsonwire from github.com/go-json-experiment/json+ github.com/go-json-experiment/json/jsontext from github.com/go-json-experiment/json+ github.com/golang/groupcache/lru from tailscale.com/net/dnscache - github.com/google/nftables from tailscale.com/util/linuxfw - 💣 github.com/google/nftables/alignedbuff from github.com/google/nftables/xt - 💣 github.com/google/nftables/binaryutil from github.com/google/nftables+ - github.com/google/nftables/expr from github.com/google/nftables+ - github.com/google/nftables/internal/parseexprfunc from github.com/google/nftables+ - github.com/google/nftables/xt from github.com/google/nftables/expr+ + D github.com/google/uuid from tailscale.com/util/quarantine github.com/gorilla/csrf from tailscale.com/client/web github.com/gorilla/securecookie from github.com/gorilla/csrf github.com/hdevalence/ed25519consensus from tailscale.com/clientupdate/distsign+ - github.com/josharian/native from github.com/mdlayher/netlink+ - 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/netmon - github.com/jsimonetti/rtnetlink/internal/unix from github.com/jsimonetti/rtnetlink + L github.com/josharian/native from github.com/mdlayher/netlink+ + L 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/netmon + L github.com/jsimonetti/rtnetlink/internal/unix from github.com/jsimonetti/rtnetlink github.com/kballard/go-shellquote from tailscale.com/cmd/tailscale/cli github.com/mattn/go-colorable from tailscale.com/cmd/tailscale/cli github.com/mattn/go-isatty from github.com/mattn/go-colorable+ - 💣 github.com/mdlayher/netlink from github.com/google/nftables+ - 💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+ - github.com/mdlayher/netlink/nltest from github.com/google/nftables - 💣 github.com/mdlayher/socket from github.com/mdlayher/netlink + L 💣 github.com/mdlayher/netlink from github.com/jsimonetti/rtnetlink+ + L 💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+ + L 💣 github.com/mdlayher/socket from github.com/mdlayher/netlink github.com/miekg/dns from tailscale.com/net/dns/recursive - github.com/mitchellh/go-ps from tailscale.com/cmd/tailscale/cli+ + 💣 github.com/mitchellh/go-ps from tailscale.com/cmd/tailscale/cli+ github.com/peterbourgon/ff/v3 from github.com/peterbourgon/ff/v3/ffcli+ github.com/peterbourgon/ff/v3/ffcli from tailscale.com/cmd/tailscale/cli+ github.com/peterbourgon/ff/v3/internal from github.com/peterbourgon/ff/v3 @@ -44,11 +38,11 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep github.com/tailscale/goupnp/scpd from github.com/tailscale/goupnp github.com/tailscale/goupnp/soap from github.com/tailscale/goupnp+ github.com/tailscale/goupnp/ssdp from github.com/tailscale/goupnp - 💣 github.com/tailscale/netlink from tailscale.com/util/linuxfw - 💣 github.com/tailscale/netlink/nl from github.com/tailscale/netlink + L 💣 github.com/tailscale/netlink from tailscale.com/util/linuxfw + L 💣 github.com/tailscale/netlink/nl from github.com/tailscale/netlink github.com/tailscale/web-client-prebuilt from tailscale.com/client/web github.com/toqueteos/webbrowser from tailscale.com/cmd/tailscale/cli - github.com/vishvananda/netns from github.com/tailscale/netlink+ + L github.com/vishvananda/netns from github.com/tailscale/netlink+ github.com/x448/float16 from github.com/fxamacker/cbor/v2 💣 go4.org/mem from tailscale.com/client/tailscale+ go4.org/netipx from tailscale.com/net/tsaddr @@ -60,7 +54,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/client/tailscale/apitype from tailscale.com/client/tailscale+ tailscale.com/client/web from tailscale.com/cmd/tailscale/cli tailscale.com/clientupdate from tailscale.com/client/web+ - tailscale.com/clientupdate/distsign from tailscale.com/clientupdate + L tailscale.com/clientupdate/distsign from tailscale.com/clientupdate tailscale.com/cmd/tailscale/cli from tailscale.com/cmd/tailscale tailscale.com/cmd/tailscale/cli/ffcomplete from tailscale.com/cmd/tailscale/cli tailscale.com/cmd/tailscale/cli/ffcomplete/internal from tailscale.com/cmd/tailscale/cli/ffcomplete @@ -92,7 +86,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/net/netcheck from tailscale.com/cmd/tailscale/cli tailscale.com/net/neterror from tailscale.com/net/netcheck+ tailscale.com/net/netknob from tailscale.com/net/netns - tailscale.com/net/netmon from tailscale.com/cmd/tailscale/cli+ + 💣 tailscale.com/net/netmon from tailscale.com/cmd/tailscale/cli+ tailscale.com/net/netns from tailscale.com/derp/derphttp+ tailscale.com/net/netutil from tailscale.com/client/tailscale+ tailscale.com/net/packet from tailscale.com/wgengine/capture @@ -100,7 +94,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/net/portmapper from tailscale.com/cmd/tailscale/cli+ tailscale.com/net/sockstats from tailscale.com/control/controlhttp+ tailscale.com/net/stun from tailscale.com/net/netcheck - tailscale.com/net/tcpinfo from tailscale.com/derp + L tailscale.com/net/tcpinfo from tailscale.com/derp tailscale.com/net/tlsdial from tailscale.com/cmd/tailscale/cli+ tailscale.com/net/tlsdial/blockblame from tailscale.com/net/tlsdial tailscale.com/net/tsaddr from tailscale.com/client/web+ @@ -138,13 +132,13 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/util/cmpver from tailscale.com/clientupdate tailscale.com/util/ctxkey from tailscale.com/derp+ 💣 tailscale.com/util/deephash from tailscale.com/util/syspolicy/setting - 💣 tailscale.com/util/dirwalk from tailscale.com/metrics + L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics tailscale.com/util/dnsname from tailscale.com/cmd/tailscale/cli+ tailscale.com/util/groupmember from tailscale.com/client/web 💣 tailscale.com/util/hashx from tailscale.com/util/deephash tailscale.com/util/httpm from tailscale.com/client/tailscale+ tailscale.com/util/lineiter from tailscale.com/hostinfo+ - tailscale.com/util/linuxfw from tailscale.com/net/netns + L tailscale.com/util/linuxfw from tailscale.com/net/netns tailscale.com/util/mak from tailscale.com/cmd/tailscale/cli+ tailscale.com/util/multierr from tailscale.com/control/controlhttp+ tailscale.com/util/must from tailscale.com/clientupdate/distsign+ @@ -194,12 +188,13 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep golang.org/x/net/ipv4 from github.com/miekg/dns+ golang.org/x/net/ipv6 from github.com/miekg/dns+ golang.org/x/net/proxy from tailscale.com/net/netns + D golang.org/x/net/route from net+ golang.org/x/oauth2 from golang.org/x/oauth2/clientcredentials golang.org/x/oauth2/clientcredentials from tailscale.com/cmd/tailscale/cli golang.org/x/oauth2/internal from golang.org/x/oauth2+ golang.org/x/sync/errgroup from github.com/mdlayher/socket+ golang.org/x/sys/cpu from github.com/josharian/native+ - golang.org/x/sys/unix from github.com/google/nftables+ + golang.org/x/sys/unix from github.com/jsimonetti/rtnetlink/internal/unix+ golang.org/x/text/secure/bidirule from golang.org/x/net/idna golang.org/x/text/transform from golang.org/x/text/secure/bidirule+ golang.org/x/text/unicode/bidi from golang.org/x/net/idna+ @@ -235,6 +230,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep crypto/tls from github.com/miekg/dns+ crypto/x509 from crypto/tls+ crypto/x509/pkix from crypto/x509+ + D database/sql/driver from github.com/google/uuid embed from crypto/internal/nistec+ encoding from encoding/gob+ encoding/asn1 from crypto/x509+ diff --git a/cmd/tailscaled/depaware-minlinux.txt b/cmd/tailscaled/depaware-minlinux.txt index 8d56c2595..a5dd84935 100644 --- a/cmd/tailscaled/depaware-minlinux.txt +++ b/cmd/tailscaled/depaware-minlinux.txt @@ -4,9 +4,9 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de filippo.io/edwards25519/field from filippo.io/edwards25519 github.com/anmitsu/go-shlex from tailscale.com/tempfork/gliderlabs/ssh github.com/bits-and-blooms/bitset from github.com/gaissmai/bart - github.com/coreos/go-iptables/iptables from tailscale.com/util/linuxfw + L github.com/coreos/go-iptables/iptables from tailscale.com/util/linuxfw 💣 github.com/creack/pty from tailscale.com/ssh/tailssh - github.com/digitalocean/go-smbios/smbios from tailscale.com/posture + L github.com/digitalocean/go-smbios/smbios from tailscale.com/posture github.com/djherbis/times from tailscale.com/drive/driveimpl github.com/fxamacker/cbor/v2 from tailscale.com/tka github.com/gaissmai/bart from tailscale.com/net/ipset+ @@ -16,22 +16,16 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de github.com/go-json-experiment/json/internal/jsonopts from github.com/go-json-experiment/json+ github.com/go-json-experiment/json/internal/jsonwire from github.com/go-json-experiment/json+ github.com/go-json-experiment/json/jsontext from github.com/go-json-experiment/json+ - 💣 github.com/godbus/dbus/v5 from tailscale.com/net/dns+ + L 💣 github.com/godbus/dbus/v5 from tailscale.com/net/dns+ github.com/golang/groupcache/lru from tailscale.com/net/dnscache - github.com/google/nftables from tailscale.com/util/linuxfw - 💣 github.com/google/nftables/alignedbuff from github.com/google/nftables/xt - 💣 github.com/google/nftables/binaryutil from github.com/google/nftables+ - github.com/google/nftables/expr from github.com/google/nftables+ - github.com/google/nftables/internal/parseexprfunc from github.com/google/nftables+ - github.com/google/nftables/xt from github.com/google/nftables/expr+ github.com/gorilla/csrf from tailscale.com/client/web github.com/gorilla/securecookie from github.com/gorilla/csrf github.com/hdevalence/ed25519consensus from tailscale.com/clientupdate/distsign+ - 💣 github.com/illarion/gonotify/v2 from tailscale.com/net/dns + L 💣 github.com/illarion/gonotify/v2 from tailscale.com/net/dns github.com/jellydator/ttlcache/v3 from tailscale.com/drive/driveimpl/compositedav - github.com/josharian/native from github.com/mdlayher/netlink+ - 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/netmon - github.com/jsimonetti/rtnetlink/internal/unix from github.com/jsimonetti/rtnetlink + L github.com/josharian/native from github.com/mdlayher/netlink+ + L 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/netmon + L github.com/jsimonetti/rtnetlink/internal/unix from github.com/jsimonetti/rtnetlink github.com/klauspost/compress from github.com/klauspost/compress/zstd github.com/klauspost/compress/fse from github.com/klauspost/compress/huff0 github.com/klauspost/compress/huff0 from github.com/klauspost/compress/zstd @@ -41,17 +35,16 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de github.com/klauspost/compress/zstd/internal/xxhash from github.com/klauspost/compress/zstd github.com/kortschak/wol from tailscale.com/ipn/ipnlocal github.com/kr/fs from github.com/pkg/sftp - github.com/mdlayher/genetlink from tailscale.com/net/tstun - 💣 github.com/mdlayher/netlink from github.com/google/nftables+ - 💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+ - github.com/mdlayher/netlink/nltest from github.com/google/nftables - github.com/mdlayher/sdnotify from tailscale.com/util/systemd - 💣 github.com/mdlayher/socket from github.com/mdlayher/netlink+ + L github.com/mdlayher/genetlink from tailscale.com/net/tstun + L 💣 github.com/mdlayher/netlink from github.com/jsimonetti/rtnetlink+ + L 💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+ + L github.com/mdlayher/sdnotify from tailscale.com/util/systemd + L 💣 github.com/mdlayher/socket from github.com/mdlayher/netlink+ github.com/miekg/dns from tailscale.com/net/dns/recursive - github.com/mitchellh/go-ps from tailscale.com/safesocket + 💣 github.com/mitchellh/go-ps from tailscale.com/safesocket github.com/pkg/sftp from tailscale.com/ssh/tailssh github.com/pkg/sftp/internal/encoding/ssh/filexfer from github.com/pkg/sftp - 💣 github.com/safchain/ethtool from tailscale.com/doctor/ethtool+ + L 💣 github.com/safchain/ethtool from tailscale.com/doctor/ethtool+ github.com/tailscale/golang-x-crypto/acme from tailscale.com/ipn/ipnlocal github.com/tailscale/golang-x-crypto/internal/poly1305 from github.com/tailscale/golang-x-crypto/ssh github.com/tailscale/golang-x-crypto/ssh from tailscale.com/ipn/ipnlocal+ @@ -63,13 +56,13 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de github.com/tailscale/goupnp/soap from github.com/tailscale/goupnp+ github.com/tailscale/goupnp/ssdp from github.com/tailscale/goupnp github.com/tailscale/hujson from tailscale.com/ipn/conffile - 💣 github.com/tailscale/netlink from tailscale.com/net/routetable+ - 💣 github.com/tailscale/netlink/nl from github.com/tailscale/netlink + L 💣 github.com/tailscale/netlink from tailscale.com/net/routetable+ + L 💣 github.com/tailscale/netlink/nl from github.com/tailscale/netlink github.com/tailscale/peercred from tailscale.com/ipn/ipnauth github.com/tailscale/web-client-prebuilt from tailscale.com/client/web 💣 github.com/tailscale/wireguard-go/conn from github.com/tailscale/wireguard-go/device+ 💣 github.com/tailscale/wireguard-go/device from tailscale.com/net/tstun+ - github.com/tailscale/wireguard-go/ipc from github.com/tailscale/wireguard-go/device + 💣 github.com/tailscale/wireguard-go/ipc from github.com/tailscale/wireguard-go/device github.com/tailscale/wireguard-go/ratelimiter from github.com/tailscale/wireguard-go/device github.com/tailscale/wireguard-go/replay from github.com/tailscale/wireguard-go/device github.com/tailscale/wireguard-go/rwcancel from github.com/tailscale/wireguard-go/device+ @@ -78,7 +71,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de github.com/tailscale/xnet/webdav from tailscale.com/drive/driveimpl+ github.com/tailscale/xnet/webdav/internal/xml from github.com/tailscale/xnet/webdav github.com/u-root/u-root/pkg/termios from tailscale.com/ssh/tailssh - github.com/vishvananda/netns from github.com/tailscale/netlink+ + L github.com/vishvananda/netns from github.com/tailscale/netlink+ github.com/x448/float16 from github.com/fxamacker/cbor/v2 💣 go4.org/mem from tailscale.com/client/tailscale+ go4.org/netipx from tailscale.com/ipn/ipnlocal+ @@ -89,7 +82,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/client/tailscale/apitype from tailscale.com/client/tailscale+ tailscale.com/client/web from tailscale.com/ipn/ipnlocal tailscale.com/clientupdate from tailscale.com/client/web+ - tailscale.com/clientupdate/distsign from tailscale.com/clientupdate + L tailscale.com/clientupdate/distsign from tailscale.com/clientupdate tailscale.com/cmd/tailscaled/childproc from tailscale.com/cmd/tailscaled+ tailscale.com/control/controlbase from tailscale.com/control/controlhttp+ tailscale.com/control/controlclient from tailscale.com/cmd/tailscaled+ @@ -149,7 +142,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/net/neterror from tailscale.com/net/dns/resolver+ tailscale.com/net/netkernelconf from tailscale.com/ipn/ipnlocal tailscale.com/net/netknob from tailscale.com/logpolicy+ - tailscale.com/net/netmon from tailscale.com/cmd/tailscaled+ + 💣 tailscale.com/net/netmon from tailscale.com/cmd/tailscaled+ tailscale.com/net/netns from tailscale.com/cmd/tailscaled+ tailscale.com/net/netutil from tailscale.com/client/tailscale+ tailscale.com/net/packet from tailscale.com/net/connstats+ @@ -161,7 +154,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/net/socks5 from tailscale.com/cmd/tailscaled tailscale.com/net/sockstats from tailscale.com/control/controlclient+ tailscale.com/net/stun from tailscale.com/ipn/localapi+ - tailscale.com/net/tcpinfo from tailscale.com/derp + L tailscale.com/net/tcpinfo from tailscale.com/derp tailscale.com/net/tlsdial from tailscale.com/control/controlclient+ tailscale.com/net/tlsdial/blockblame from tailscale.com/net/tlsdial tailscale.com/net/tsaddr from tailscale.com/client/web+ @@ -214,7 +207,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/util/cmpver from tailscale.com/clientupdate+ tailscale.com/util/ctxkey from tailscale.com/derp+ 💣 tailscale.com/util/deephash from tailscale.com/ipn/ipnlocal+ - 💣 tailscale.com/util/dirwalk from tailscale.com/metrics+ + L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics+ tailscale.com/util/dnsname from tailscale.com/appc+ tailscale.com/util/execqueue from tailscale.com/appc+ tailscale.com/util/goroutines from tailscale.com/ipn/ipnlocal @@ -223,7 +216,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/util/httphdr from tailscale.com/ipn/ipnlocal+ tailscale.com/util/httpm from tailscale.com/client/tailscale+ tailscale.com/util/lineiter from tailscale.com/hostinfo+ - tailscale.com/util/linuxfw from tailscale.com/net/netns+ + L tailscale.com/util/linuxfw from tailscale.com/net/netns+ tailscale.com/util/mak from tailscale.com/appc+ tailscale.com/util/multierr from tailscale.com/cmd/tailscaled+ tailscale.com/util/must from tailscale.com/clientupdate/distsign+ @@ -298,6 +291,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de golang.org/x/net/ipv4 from github.com/miekg/dns+ golang.org/x/net/ipv6 from github.com/miekg/dns+ golang.org/x/net/proxy from tailscale.com/net/netns + D golang.org/x/net/route from net+ golang.org/x/sync/errgroup from github.com/mdlayher/socket+ golang.org/x/sync/singleflight from github.com/jellydator/ttlcache/v3 golang.org/x/sys/cpu from github.com/josharian/native+ diff --git a/util/linuxfw/iptables_for_svcs.go b/util/linuxfw/iptables_for_svcs.go index 8e0f5d48d..d1d047830 100644 --- a/util/linuxfw/iptables_for_svcs.go +++ b/util/linuxfw/iptables_for_svcs.go @@ -1,7 +1,7 @@ // Copyright (c) Tailscale Inc & AUTHORS // SPDX-License-Identifier: BSD-3-Clause -//go:build linux +//go:build linux && !ts_omit_nftables package linuxfw diff --git a/util/linuxfw/nftables.go b/util/linuxfw/nftables.go index 056563071..bfe44d0d6 100644 --- a/util/linuxfw/nftables.go +++ b/util/linuxfw/nftables.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause // TODO(#8502): add support for more architectures -//go:build linux && (arm64 || amd64) +//go:build linux && (arm64 || amd64) && !ts_omit_nftables package linuxfw diff --git a/util/linuxfw/nftables_for_svcs.go b/util/linuxfw/nftables_for_svcs.go index 130585b22..dd582b31a 100644 --- a/util/linuxfw/nftables_for_svcs.go +++ b/util/linuxfw/nftables_for_svcs.go @@ -1,7 +1,7 @@ // Copyright (c) Tailscale Inc & AUTHORS // SPDX-License-Identifier: BSD-3-Clause -//go:build linux +//go:build linux && !ts_omit_nftables package linuxfw @@ -222,17 +222,6 @@ func (n *nftablesRunner) ensureChainForSvc(svc string, targetIP netip.Addr) (*nf return nat, svcCh, nil } -// // PortMap is the port mapping for a service rule. -type PortMap struct { - // MatchPort is the local port to which the rule should apply. - MatchPort uint16 - // TargetPort is the port to which the traffic should be forwarded. - TargetPort uint16 - // Protocol is the protocol to match packets on. Only TCP and UDP are - // supported. - Protocol string -} - func protoFromString(s string) (uint8, error) { switch strings.ToLower(s) { case "tcp": diff --git a/util/linuxfw/nftables_runner.go b/util/linuxfw/nftables_runner.go index 0f411521b..75beb8659 100644 --- a/util/linuxfw/nftables_runner.go +++ b/util/linuxfw/nftables_runner.go @@ -1,7 +1,7 @@ // Copyright (c) Tailscale Inc & AUTHORS // SPDX-License-Identifier: BSD-3-Clause -//go:build linux +//go:build linux && !ts_omit_nftables package linuxfw @@ -468,110 +468,6 @@ func getOrCreateChain(c *nftables.Conn, cinfo chainInfo) (*nftables.Chain, error return chain, nil } -// NetfilterRunner abstracts helpers to run netfilter commands. It is -// implemented by linuxfw.IPTablesRunner and linuxfw.NfTablesRunner. -type NetfilterRunner interface { - // AddLoopbackRule adds a rule to permit loopback traffic to addr. This rule - // is added only if it does not already exist. - AddLoopbackRule(addr netip.Addr) error - - // DelLoopbackRule removes the rule added by AddLoopbackRule. - DelLoopbackRule(addr netip.Addr) error - - // AddHooks adds rules to conventional chains like "FORWARD", "INPUT" and - // "POSTROUTING" to jump from those chains to tailscale chains. - AddHooks() error - - // DelHooks deletes rules added by AddHooks. - DelHooks(logf logger.Logf) error - - // AddChains creates custom Tailscale chains. - AddChains() error - - // DelChains removes chains added by AddChains. - DelChains() error - - // AddBase adds rules reused by different other rules. - AddBase(tunname string) error - - // DelBase removes rules added by AddBase. - DelBase() error - - // AddSNATRule adds the netfilter rule to SNAT incoming traffic over - // the Tailscale interface destined for local subnets. An error is - // returned if the rule already exists. - AddSNATRule() error - - // DelSNATRule removes the rule added by AddSNATRule. - DelSNATRule() error - - // AddStatefulRule adds a netfilter rule for stateful packet filtering - // using conntrack. - AddStatefulRule(tunname string) error - - // DelStatefulRule removes a netfilter rule for stateful packet filtering - // using conntrack. - DelStatefulRule(tunname string) error - - // HasIPV6 reports true if the system supports IPv6. - HasIPV6() bool - - // HasIPV6NAT reports true if the system supports IPv6 NAT. - HasIPV6NAT() bool - - // HasIPV6Filter reports true if the system supports IPv6 filter tables - // This is only meaningful for iptables implementation, where hosts have - // partial ipables support (i.e missing filter table). For nftables - // implementation, this will default to the value of HasIPv6(). - HasIPV6Filter() bool - - // AddDNATRule adds a rule to the nat/PREROUTING chain to DNAT traffic - // destined for the given original destination to the given new destination. - // This is used to forward all traffic destined for the Tailscale interface - // to the provided destination, as used in the Kubernetes ingress proxies. - AddDNATRule(origDst, dst netip.Addr) error - - // DNATWithLoadBalancer adds a rule to the nat/PREROUTING chain to DNAT - // traffic destined for the given original destination to the given new - // destination(s) using round robin to load balance if more than one - // destination is provided. This is used to forward all traffic destined - // for the Tailscale interface to the provided destination(s), as used - // in the Kubernetes ingress proxies. - DNATWithLoadBalancer(origDst netip.Addr, dsts []netip.Addr) error - - // EnsureSNATForDst sets up firewall to mask the source for traffic destined for dst to src: - // - creates a SNAT rule if it doesn't already exist - // - deletes any pre-existing rules matching the destination - // This is used to forward traffic destined for the local machine over - // the Tailscale interface, as used in the Kubernetes egress proxies. - EnsureSNATForDst(src, dst netip.Addr) error - - // DNATNonTailscaleTraffic adds a rule to the nat/PREROUTING chain to DNAT - // all traffic inbound from any interface except exemptInterface to dst. - // This is used to forward traffic destined for the local machine over - // the Tailscale interface, as used in the Kubernetes egress proxies. - DNATNonTailscaleTraffic(exemptInterface string, dst netip.Addr) error - - EnsurePortMapRuleForSvc(svc, tun string, targetIP netip.Addr, pm PortMap) error - - DeletePortMapRuleForSvc(svc, tun string, targetIP netip.Addr, pm PortMap) error - - DeleteSvc(svc, tun string, targetIPs []netip.Addr, pm []PortMap) error - - // ClampMSSToPMTU adds a rule to the mangle/FORWARD chain to clamp MSS for - // traffic destined for the provided tun interface. - ClampMSSToPMTU(tun string, addr netip.Addr) error - - // AddMagicsockPortRule adds a rule to the ts-input chain to accept - // incoming traffic on the specified port, to allow magicsock to - // communicate. - AddMagicsockPortRule(port uint16, network string) error - - // DelMagicsockPortRule removes the rule created by AddMagicsockPortRule, - // if it exists. - DelMagicsockPortRule(port uint16, network string) error -} - // New creates a NetfilterRunner, auto-detecting whether to use // nftables or iptables. // As nftables is still experimental, iptables will be used unless diff --git a/util/linuxfw/nftables_types.go b/util/linuxfw/nftables_types.go index b6e24d2a6..52d7fef31 100644 --- a/util/linuxfw/nftables_types.go +++ b/util/linuxfw/nftables_types.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause // TODO(#8502): add support for more architectures -//go:build linux && (arm64 || amd64) +//go:build linux && (arm64 || amd64) && !ts_omit_nftables package linuxfw diff --git a/util/linuxfw/omit_nftables.go b/util/linuxfw/omit_nftables.go new file mode 100644 index 000000000..3fc8e3a1a --- /dev/null +++ b/util/linuxfw/omit_nftables.go @@ -0,0 +1,24 @@ +//go:build ts_omit_nftables + +package linuxfw + +import ( + "errors" + + "tailscale.com/types/logger" +) + +// ErrUnsupported is the error returned from all functions on non-Linux +// platforms. +var ErrUnsupported = errors.New("linuxfw:unsupported") + +// DetectNetfilter is not supported on non-Linux platforms. +func detectNetfilter() (int, error) { + return 0, ErrUnsupported +} + +func NfTablesCleanUp(logf logger.Logf) {} + +func New(any, any) (NetfilterRunner, error) { + return nil, ErrUnsupported +} diff --git a/util/linuxfw/runner.go b/util/linuxfw/runner.go new file mode 100644 index 000000000..b6f0841ae --- /dev/null +++ b/util/linuxfw/runner.go @@ -0,0 +1,122 @@ +package linuxfw + +import ( + "net/netip" + + "tailscale.com/types/logger" +) + +// // PortMap is the port mapping for a service rule. +type PortMap struct { + // MatchPort is the local port to which the rule should apply. + MatchPort uint16 + // TargetPort is the port to which the traffic should be forwarded. + TargetPort uint16 + // Protocol is the protocol to match packets on. Only TCP and UDP are + // supported. + Protocol string +} + +// NetfilterRunner abstracts helpers to run netfilter commands. It is +// implemented by linuxfw.IPTablesRunner and linuxfw.NfTablesRunner. +type NetfilterRunner interface { + // AddLoopbackRule adds a rule to permit loopback traffic to addr. This rule + // is added only if it does not already exist. + AddLoopbackRule(addr netip.Addr) error + + // DelLoopbackRule removes the rule added by AddLoopbackRule. + DelLoopbackRule(addr netip.Addr) error + + // AddHooks adds rules to conventional chains like "FORWARD", "INPUT" and + // "POSTROUTING" to jump from those chains to tailscale chains. + AddHooks() error + + // DelHooks deletes rules added by AddHooks. + DelHooks(logf logger.Logf) error + + // AddChains creates custom Tailscale chains. + AddChains() error + + // DelChains removes chains added by AddChains. + DelChains() error + + // AddBase adds rules reused by different other rules. + AddBase(tunname string) error + + // DelBase removes rules added by AddBase. + DelBase() error + + // AddSNATRule adds the netfilter rule to SNAT incoming traffic over + // the Tailscale interface destined for local subnets. An error is + // returned if the rule already exists. + AddSNATRule() error + + // DelSNATRule removes the rule added by AddSNATRule. + DelSNATRule() error + + // AddStatefulRule adds a netfilter rule for stateful packet filtering + // using conntrack. + AddStatefulRule(tunname string) error + + // DelStatefulRule removes a netfilter rule for stateful packet filtering + // using conntrack. + DelStatefulRule(tunname string) error + + // HasIPV6 reports true if the system supports IPv6. + HasIPV6() bool + + // HasIPV6NAT reports true if the system supports IPv6 NAT. + HasIPV6NAT() bool + + // HasIPV6Filter reports true if the system supports IPv6 filter tables + // This is only meaningful for iptables implementation, where hosts have + // partial ipables support (i.e missing filter table). For nftables + // implementation, this will default to the value of HasIPv6(). + HasIPV6Filter() bool + + // AddDNATRule adds a rule to the nat/PREROUTING chain to DNAT traffic + // destined for the given original destination to the given new destination. + // This is used to forward all traffic destined for the Tailscale interface + // to the provided destination, as used in the Kubernetes ingress proxies. + AddDNATRule(origDst, dst netip.Addr) error + + // DNATWithLoadBalancer adds a rule to the nat/PREROUTING chain to DNAT + // traffic destined for the given original destination to the given new + // destination(s) using round robin to load balance if more than one + // destination is provided. This is used to forward all traffic destined + // for the Tailscale interface to the provided destination(s), as used + // in the Kubernetes ingress proxies. + DNATWithLoadBalancer(origDst netip.Addr, dsts []netip.Addr) error + + // EnsureSNATForDst sets up firewall to mask the source for traffic destined for dst to src: + // - creates a SNAT rule if it doesn't already exist + // - deletes any pre-existing rules matching the destination + // This is used to forward traffic destined for the local machine over + // the Tailscale interface, as used in the Kubernetes egress proxies. + EnsureSNATForDst(src, dst netip.Addr) error + + // DNATNonTailscaleTraffic adds a rule to the nat/PREROUTING chain to DNAT + // all traffic inbound from any interface except exemptInterface to dst. + // This is used to forward traffic destined for the local machine over + // the Tailscale interface, as used in the Kubernetes egress proxies. + DNATNonTailscaleTraffic(exemptInterface string, dst netip.Addr) error + + EnsurePortMapRuleForSvc(svc, tun string, targetIP netip.Addr, pm PortMap) error + + DeletePortMapRuleForSvc(svc, tun string, targetIP netip.Addr, pm PortMap) error + + DeleteSvc(svc, tun string, targetIPs []netip.Addr, pm []PortMap) error + + // ClampMSSToPMTU adds a rule to the mangle/FORWARD chain to clamp MSS for + // traffic destined for the provided tun interface. + ClampMSSToPMTU(tun string, addr netip.Addr) error + + // AddMagicsockPortRule adds a rule to the ts-input chain to accept + // incoming traffic on the specified port, to allow magicsock to + // communicate. + AddMagicsockPortRule(port uint16, network string) error + + // DelMagicsockPortRule removes the rule created by AddMagicsockPortRule, + // if it exists. + DelMagicsockPortRule(port uint16, network string) error +}