Skip to content

Commit 3e4b0c1

Browse files
committed
cmd/tailscale, ipn/ipnlocal: add ts_omit_webclient
Fixes tailscale#17063 Updates tailscale#12614 Change-Id: I0a189f6a4d1c4558351e3195839867725774fa96 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
1 parent ffc82ad commit 3e4b0c1

File tree

8 files changed

+63
-23
lines changed

8 files changed

+63
-23
lines changed

build_dist.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ while [ "$#" -gt 1 ]; do
4141
fi
4242
shift
4343
ldflags="$ldflags -w -s"
44-
tags="${tags:+$tags,}ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube,ts_omit_completion,ts_omit_ssh,ts_omit_wakeonlan,ts_omit_capture,ts_omit_relayserver,ts_omit_systray,ts_omit_taildrop,ts_omit_tpm,ts_omit_syspolicy,ts_omit_debugeventbus"
44+
tags="${tags:+$tags,}ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube,ts_omit_completion,ts_omit_ssh,ts_omit_wakeonlan,ts_omit_capture,ts_omit_relayserver,ts_omit_systray,ts_omit_taildrop,ts_omit_tpm,ts_omit_syspolicy,ts_omit_debugeventbus,ts_omit_webclient"
4545
;;
4646
--box)
4747
if [ ! -z "${TAGS:-}" ]; then

cmd/tailscale/cli/cli.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ func noDupFlagify(c *ffcli.Command) {
209209

210210
var fileCmd func() *ffcli.Command
211211
var sysPolicyCmd func() *ffcli.Command
212+
var maybeWebCmd func() *ffcli.Command
212213

213214
func newRootCmd() *ffcli.Command {
214215
rootfs := newFlagSet("tailscale")
@@ -251,7 +252,7 @@ change in the future.
251252
funnelCmd(),
252253
serveCmd(),
253254
versionCmd,
254-
webCmd,
255+
nilOrCall(maybeWebCmd),
255256
nilOrCall(fileCmd),
256257
bugReportCmd,
257258
certCmd,

cmd/tailscale/cli/set.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
"strings"
1616

1717
"github.com/peterbourgon/ff/v3/ffcli"
18-
"tailscale.com/client/web"
1918
"tailscale.com/clientupdate"
2019
"tailscale.com/cmd/tailscale/cli/ffcomplete"
2120
"tailscale.com/ipn"
2221
"tailscale.com/net/netutil"
2322
"tailscale.com/net/tsaddr"
2423
"tailscale.com/safesocket"
24+
"tailscale.com/tsconst"
2525
"tailscale.com/types/opt"
2626
"tailscale.com/types/ptr"
2727
"tailscale.com/types/views"
@@ -264,7 +264,7 @@ func runSet(ctx context.Context, args []string) (retErr error) {
264264
}
265265

266266
if setArgs.runWebClient && len(st.TailscaleIPs) > 0 {
267-
printf("\nWeb interface now running at %s:%d\n", st.TailscaleIPs[0], web.ListenPort)
267+
printf("\nWeb interface now running at %s:%d\n", st.TailscaleIPs[0], tsconst.WebListenPort)
268268
}
269269

270270
return nil

cmd/tailscale/cli/web.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Tailscale Inc & AUTHORS
22
// SPDX-License-Identifier: BSD-3-Clause
33

4+
//go:build !ts_omit_webclient
5+
46
package cli
57

68
import (
@@ -22,31 +24,38 @@ import (
2224
"github.com/peterbourgon/ff/v3/ffcli"
2325
"tailscale.com/client/web"
2426
"tailscale.com/ipn"
27+
"tailscale.com/tsconst"
2528
)
2629

27-
var webCmd = &ffcli.Command{
28-
Name: "web",
29-
ShortUsage: "tailscale web [flags]",
30-
ShortHelp: "Run a web server for controlling Tailscale",
30+
func init() {
31+
maybeWebCmd = webCmd
32+
}
33+
34+
func webCmd() *ffcli.Command {
35+
return &ffcli.Command{
36+
Name: "web",
37+
ShortUsage: "tailscale web [flags]",
38+
ShortHelp: "Run a web server for controlling Tailscale",
3139

32-
LongHelp: strings.TrimSpace(`
40+
LongHelp: strings.TrimSpace(`
3341
"tailscale web" runs a webserver for controlling the Tailscale daemon.
3442
3543
It's primarily intended for use on Synology, QNAP, and other
3644
NAS devices where a web interface is the natural place to control
3745
Tailscale, as opposed to a CLI or a native app.
3846
`),
3947

40-
FlagSet: (func() *flag.FlagSet {
41-
webf := newFlagSet("web")
42-
webf.StringVar(&webArgs.listen, "listen", "localhost:8088", "listen address; use port 0 for automatic")
43-
webf.BoolVar(&webArgs.cgi, "cgi", false, "run as CGI script")
44-
webf.StringVar(&webArgs.prefix, "prefix", "", "URL prefix added to requests (for cgi or reverse proxies)")
45-
webf.BoolVar(&webArgs.readonly, "readonly", false, "run web UI in read-only mode")
46-
webf.StringVar(&webArgs.origin, "origin", "", "origin at which the web UI is served (if behind a reverse proxy or used with cgi)")
47-
return webf
48-
})(),
49-
Exec: runWeb,
48+
FlagSet: (func() *flag.FlagSet {
49+
webf := newFlagSet("web")
50+
webf.StringVar(&webArgs.listen, "listen", "localhost:8088", "listen address; use port 0 for automatic")
51+
webf.BoolVar(&webArgs.cgi, "cgi", false, "run as CGI script")
52+
webf.StringVar(&webArgs.prefix, "prefix", "", "URL prefix added to requests (for cgi or reverse proxies)")
53+
webf.BoolVar(&webArgs.readonly, "readonly", false, "run web UI in read-only mode")
54+
webf.StringVar(&webArgs.origin, "origin", "", "origin at which the web UI is served (if behind a reverse proxy or used with cgi)")
55+
return webf
56+
})(),
57+
Exec: runWeb,
58+
}
5059
}
5160

5261
var webArgs struct {
@@ -101,7 +110,7 @@ func runWeb(ctx context.Context, args []string) error {
101110
var startedManagementClient bool // we started the management client
102111
if !existingWebClient && !webArgs.readonly {
103112
// Also start full client in tailscaled.
104-
log.Printf("starting tailscaled web client at http://%s\n", netip.AddrPortFrom(selfIP, web.ListenPort))
113+
log.Printf("starting tailscaled web client at http://%s\n", netip.AddrPortFrom(selfIP, tsconst.WebListenPort))
105114
if err := setRunWebClient(ctx, true); err != nil {
106115
return fmt.Errorf("starting web client in tailscaled: %w", err)
107116
}

cmd/tailscaled/deps_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package main
55

66
import (
7+
"strings"
78
"testing"
89

910
"tailscale.com/tstest/deptest"
@@ -41,3 +42,22 @@ func TestOmitSyspolicy(t *testing.T) {
4142
},
4243
}.Check(t)
4344
}
45+
46+
// Test that we can build a binary without reflect.MethodByName.
47+
// See https://github.com/tailscale/tailscale/issues/17063
48+
func TestOmitReflectThings(t *testing.T) {
49+
deptest.DepChecker{
50+
GOOS: "linux",
51+
GOARCH: "amd64",
52+
Tags: "ts_include_cli,ts_omit_systray,ts_omit_debugeventbus,ts_omit_webclient",
53+
BadDeps: map[string]string{
54+
"text/template": "unexpected text/template usage",
55+
"html/template": "unexpected text/template usage",
56+
},
57+
OnDep: func(dep string) {
58+
if strings.Contains(dep, "systray") {
59+
t.Errorf("unexpected systray dep %q", dep)
60+
}
61+
},
62+
}.Check(t)
63+
}

ipn/ipnlocal/web_client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Tailscale Inc & AUTHORS
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
//go:build !ios && !android
4+
//go:build !ios && !android && !ts_omit_webclient
55

66
package ipnlocal
77

@@ -22,11 +22,12 @@ import (
2222
"tailscale.com/logtail/backoff"
2323
"tailscale.com/net/netutil"
2424
"tailscale.com/tailcfg"
25+
"tailscale.com/tsconst"
2526
"tailscale.com/types/logger"
2627
"tailscale.com/util/mak"
2728
)
2829

29-
const webClientPort = web.ListenPort
30+
const webClientPort = tsconst.WebListenPort
3031

3132
// webClient holds state for the web interface for managing this
3233
// tailscale instance. The web interface is not used by default,

ipn/ipnlocal/web_client_stub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Tailscale Inc & AUTHORS
22
// SPDX-License-Identifier: BSD-3-Clause
33

4-
//go:build ios || android
4+
//go:build ios || android || ts_omit_webclient
55

66
package ipnlocal
77

tsconst/webclient.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) Tailscale Inc & AUTHORS
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
package tsconst
5+
6+
// WebListenPort is the static port used for the web client when run inside
7+
// tailscaled. (5252 are the numbers above the letters "TSTS" on a qwerty
8+
// keyboard.)
9+
const WebListenPort = 5252

0 commit comments

Comments
 (0)