From d45c5ddfbbc1bb6ded8e3e9a15af9ece78bb4744 Mon Sep 17 00:00:00 2001 From: Brendan Creane Date: Tue, 3 Nov 2026 06:39:53 -0800 Subject: [PATCH] cmd/tailscale/cli: check the requested port before enabling Funnel (#22120) The funnel command checked Funnel access with a hardcoded port 443, so any requested port passed and the CLI reported it as available on the internet. Check the port the user asked for instead. Turning Funnel off skips the check so existing configs on other ports can still be removed. Fixes #10742 Fixes #21989 Signed-off-by: Brendan Creane --- cmd/tailscale/cli/serve_v2.go | 13 ++++----- cmd/tailscale/cli/serve_v2_test.go | 45 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/cmd/tailscale/cli/serve_v2.go b/cmd/tailscale/cli/serve_v2.go index 0ec4f5a66..06a9abe6e 100644 --- a/cmd/tailscale/cli/serve_v2.go +++ b/cmd/tailscale/cli/serve_v2.go @@ -407,13 +407,6 @@ func (e *serveEnv) runServeCombined(subcmd serveMode) execFunc { return errors.New("Error: --service flag is not supported with funnel") } - if funnel { - // verify node has funnel capabilities - if err := e.verifyFunnelEnabled(ctx, 443); err != nil { - return err - } - } - if forService && !e.bg.Value { return errors.New("Error: --service flag is only compatible with background mode") } @@ -460,6 +453,12 @@ func (e *serveEnv) runServeCombined(subcmd serveMode) execFunc { parentSC := sc turnOff := len(args) > 0 && "off" == args[len(args)-1] + if funnel && !turnOff { + // Verify the node can use Funnel on the requested port. + if err := e.verifyFunnelEnabled(ctx, srvPort); err != nil { + return err + } + } if !turnOff && srvType == serveTypeHTTPS { // Running serve with https requires that the tailnet has enabled // https cert provisioning. Send users through an interactive flow diff --git a/cmd/tailscale/cli/serve_v2_test.go b/cmd/tailscale/cli/serve_v2_test.go index da61dc8c1..bfb7f9a45 100644 --- a/cmd/tailscale/cli/serve_v2_test.go +++ b/cmd/tailscale/cli/serve_v2_test.go @@ -893,6 +893,51 @@ func TestServeDevConfigMutations(t *testing.T) { }, }, }, + { + // The fake status only allows Funnel on ports 443 and 8443. + name: "funnel_port_not_allowed", + steps: []step{ + { + command: cmd("funnel --bg --https=10000 3000"), + wantErr: func(err error) (badErrMsg string) { + if err == nil || !strings.Contains(err.Error(), "not allowed for funnel") { + return fmt.Sprintf("want a port-not-allowed error; got %v", err) + } + return "" + }, + }, + { + command: cmd("funnel --bg --tcp=10000 tcp://localhost:5432"), + wantErr: func(err error) (badErrMsg string) { + if err == nil || !strings.Contains(err.Error(), "not allowed for funnel") { + return fmt.Sprintf("want a port-not-allowed error; got %v", err) + } + return "" + }, + }, + }, + }, + { + // Turning Funnel off on a port that is no longer allowed must + // still work, so users can clean up configs made before the + // port check applied to the requested port. + name: "funnel_off_on_disallowed_port", + initialState: fakeLocalServeClient{ + config: &ipn.ServeConfig{ + TCP: map[uint16]*ipn.TCPPortHandler{10000: {HTTPS: true}}, + Web: map[ipn.HostPort]*ipn.WebServerConfig{ + "foo.test.ts.net:10000": {Handlers: map[string]*ipn.HTTPHandler{ + "/": {Proxy: "http://127.0.0.1:3000"}, + }}, + }, + AllowFunnel: map[ipn.HostPort]bool{"foo.test.ts.net:10000": true}, + }, + }, + steps: []step{{ + command: cmd("funnel --https=10000 off"), + want: &ipn.ServeConfig{}, + }}, + }, { name: "no_http_with_funnel", steps: []step{