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 <bcreane@gmail.com>
This commit is contained in:
Brendan Creane authored and GitHub committed 2026-11-03 06:39:53 -08:00
1 parent f5d378471e
commit d45c5ddfbb
2 files changed
+51 -7

No files matched your search

+6 -7
View File
@@ -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
+45
View File
@@ -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{