Skip to content

Commit c42a4e4

Browse files
committed
tailfs: listen for local clients only on 100.100.100.100
FileSystemForLocal was listening on the node's Tailscale address, which potentially exposes the user's view of TailFS shares to other Tailnet users. Remote nodes should connect to exported shares via the peerapi. This removes that code so that FileSystemForLocal is only avaialable on 100.100.100.100:8080. Updates tailscale/corp#16827 Signed-off-by: Percy Wegmann <percy@tailscale.com>
1 parent d0ef3a2 commit c42a4e4

File tree

3 files changed

+2
-68
lines changed

3 files changed

+2
-68
lines changed

ipn/ipnlocal/local.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,6 @@ type LocalBackend struct {
287287
serveListeners map[netip.AddrPort]*localListener // listeners for local serve traffic
288288
serveProxyHandlers sync.Map // string (HTTPHandler.Proxy) => *reverseProxy
289289

290-
tailFSListeners map[netip.AddrPort]*localListener // listeners for local tailfs traffic
291-
292290
// statusLock must be held before calling statusChanged.Wait() or
293291
// statusChanged.Broadcast().
294292
statusLock sync.Mutex
@@ -4770,10 +4768,6 @@ func (b *LocalBackend) setTCPPortsInterceptedFromNetmapAndPrefsLocked(prefs ipn.
47704768
}
47714769
}
47724770

4773-
if !b.sys.IsNetstack() {
4774-
b.updateTailFSListenersLocked()
4775-
}
4776-
47774771
b.reloadServeConfigLocked(prefs)
47784772
if b.serveConfig.Valid() {
47794773
servePorts := make([]uint16, 0, 3)

ipn/ipnlocal/tailfs.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,16 @@
44
package ipnlocal
55

66
import (
7-
"context"
87
"encoding/json"
98
"errors"
109
"fmt"
11-
"net"
12-
"net/netip"
1310
"os"
1411
"regexp"
1512
"strings"
16-
"time"
1713

1814
"tailscale.com/ipn"
19-
"tailscale.com/logtail/backoff"
2015
"tailscale.com/tailcfg"
2116
"tailscale.com/tailfs"
22-
"tailscale.com/types/logger"
2317
"tailscale.com/types/netmap"
2418
)
2519

@@ -241,60 +235,6 @@ func (b *LocalBackend) tailFSGetSharesLocked() (map[string]*tailfs.Share, error)
241235
return shares, nil
242236
}
243237

244-
// updateTailFSListenersLocked creates listeners on the local TailFS port.
245-
// This is needed to properly route local traffic when using kernel networking
246-
// mode.
247-
func (b *LocalBackend) updateTailFSListenersLocked() {
248-
if b.netMap == nil {
249-
return
250-
}
251-
252-
addrs := b.netMap.GetAddresses()
253-
oldListeners := b.tailFSListeners
254-
newListeners := make(map[netip.AddrPort]*localListener, addrs.Len())
255-
for i := range addrs.LenIter() {
256-
if fs, ok := b.sys.TailFSForLocal.GetOK(); ok {
257-
addrPort := netip.AddrPortFrom(addrs.At(i).Addr(), TailFSLocalPort)
258-
if sl, ok := b.tailFSListeners[addrPort]; ok {
259-
newListeners[addrPort] = sl
260-
delete(oldListeners, addrPort)
261-
continue // already listening
262-
}
263-
264-
sl := b.newTailFSListener(context.Background(), fs, addrPort, b.logf)
265-
newListeners[addrPort] = sl
266-
go sl.Run()
267-
}
268-
}
269-
270-
// At this point, anything left in oldListeners can be stopped.
271-
for _, sl := range oldListeners {
272-
sl.cancel()
273-
}
274-
}
275-
276-
// newTailFSListener returns a listener for local connections to a tailfs
277-
// WebDAV FileSystem.
278-
func (b *LocalBackend) newTailFSListener(ctx context.Context, fs tailfs.FileSystemForLocal, ap netip.AddrPort, logf logger.Logf) *localListener {
279-
ctx, cancel := context.WithCancel(ctx)
280-
return &localListener{
281-
b: b,
282-
ap: ap,
283-
ctx: ctx,
284-
cancel: cancel,
285-
logf: logf,
286-
287-
handler: func(conn net.Conn) error {
288-
if !b.TailFSAccessEnabled() {
289-
conn.Close()
290-
return nil
291-
}
292-
return fs.HandleConn(conn, conn.RemoteAddr())
293-
},
294-
bo: backoff.NewBackoff(fmt.Sprintf("tailfs-listener-%d", ap.Port()), logf, 30*time.Second),
295-
}
296-
}
297-
298238
// updateTailFSPeersLocked sets all applicable peers from the netmap as tailfs
299239
// remotes.
300240
func (b *LocalBackend) updateTailFSPeersLocked(nm *netmap.NetworkMap) {

wgengine/netstack/netstack.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,10 +919,10 @@ func (ns *Impl) acceptTCP(r *tcp.ForwarderRequest) {
919919
return gonet.NewTCPConn(&wq, ep)
920920
}
921921

922-
// Local DNS Service (DNS and WebDAV)
922+
// Local Services (DNS and WebDAV)
923923
hittingServiceIP := dialIP == serviceIP || dialIP == serviceIPv6
924924
hittingDNS := hittingServiceIP && reqDetails.LocalPort == 53
925-
hittingTailFS := hittingServiceIP && ns.tailFSForLocal != nil && reqDetails.LocalPort == 8080
925+
hittingTailFS := hittingServiceIP && ns.tailFSForLocal != nil && reqDetails.LocalPort == ipnlocal.TailFSLocalPort
926926
if hittingDNS || hittingTailFS {
927927
c := getConnOrReset()
928928
if c == nil {

0 commit comments

Comments
 (0)