From c7d4bf2333b195b1553e588040f008ca307089ea Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 1 Feb 2021 13:52:01 -0800 Subject: [PATCH] cmd/tailscale/cli: recommend sudo for 'tailscale up' on failure Fixes #1220 --- cmd/tailscale/cli/up.go | 11 ++++++++++- ipn/message.go | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/tailscale/cli/up.go b/cmd/tailscale/cli/up.go index d95ad30be..e60801f9b 100644 --- a/cmd/tailscale/cli/up.go +++ b/cmd/tailscale/cli/up.go @@ -228,7 +228,16 @@ func runUp(ctx context.Context, args []string) error { AuthKey: upArgs.authKey, Notify: func(n ipn.Notify) { if n.ErrMessage != nil { - fatalf("backend error: %v\n", *n.ErrMessage) + msg := *n.ErrMessage + if msg == ipn.ErrMsgPermissionDenied { + switch runtime.GOOS { + case "windows": + msg += " (Tailscale service in use by other user?)" + default: + msg += " (try 'sudo tailscale up [...]')" + } + } + fatalf("backend error: %v\n", msg) } if s := n.State; s != nil { switch *s { diff --git a/ipn/message.go b/ipn/message.go index a9106dac7..9b7783f98 100644 --- a/ipn/message.go +++ b/ipn/message.go @@ -146,6 +146,10 @@ func (bs *BackendServer) GotFakeCommand(ctx context.Context, cmd *Command) error return bs.GotCommand(ctx, cmd) } +// ErrMsgPermissionDenied is the Notify.ErrMessage value used an +// operation was done from a user/context that didn't have permission. +const ErrMsgPermissionDenied = "permission denied" + func (bs *BackendServer) GotCommand(ctx context.Context, cmd *Command) error { if cmd.Version != version.Long && !cmd.AllowVersionSkew { vs := fmt.Sprintf("GotCommand: Version mismatch! frontend=%#v backend=%#v", @@ -178,7 +182,7 @@ func (bs *BackendServer) GotCommand(ctx context.Context, cmd *Command) error { } if IsReadonlyContext(ctx) { - msg := "permission denied" + msg := ErrMsgPermissionDenied bs.send(Notify{ErrMessage: &msg}) return nil }