mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 02:37:38 +00:00
client/tailscale, cmd/tailscale/cli: plumb --socket through
Without this, `tailscale status` ignores the --socket flag on macOS and always talks to the IPNExtension, even if you wanted it to inspect a userspace tailscaled. Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
parent
f01091babe
commit
e67f1b5da0
@ -16,10 +16,14 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"tailscale.com/ipn/ipnstate"
|
"tailscale.com/ipn/ipnstate"
|
||||||
|
"tailscale.com/paths"
|
||||||
"tailscale.com/safesocket"
|
"tailscale.com/safesocket"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TailscaledSocket is the tailscaled Unix socket.
|
||||||
|
var TailscaledSocket = paths.DefaultTailscaledSocket()
|
||||||
|
|
||||||
// tsClient does HTTP requests to the local Tailscale daemon.
|
// tsClient does HTTP requests to the local Tailscale daemon.
|
||||||
var tsClient = &http.Client{
|
var tsClient = &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
@ -27,14 +31,16 @@ var tsClient = &http.Client{
|
|||||||
if addr != "local-tailscaled.sock:80" {
|
if addr != "local-tailscaled.sock:80" {
|
||||||
return nil, fmt.Errorf("unexpected URL address %q", addr)
|
return nil, fmt.Errorf("unexpected URL address %q", addr)
|
||||||
}
|
}
|
||||||
// On macOS, when dialing from non-sandboxed program to sandboxed GUI running
|
if TailscaledSocket == paths.DefaultTailscaledSocket() {
|
||||||
// a TCP server on a random port, find the random port. For HTTP connections,
|
// On macOS, when dialing from non-sandboxed program to sandboxed GUI running
|
||||||
// we don't send the token. It gets added in an HTTP Basic-Auth header.
|
// a TCP server on a random port, find the random port. For HTTP connections,
|
||||||
if port, _, err := safesocket.LocalTCPPortAndToken(); err == nil {
|
// we don't send the token. It gets added in an HTTP Basic-Auth header.
|
||||||
var d net.Dialer
|
if port, _, err := safesocket.LocalTCPPortAndToken(); err == nil {
|
||||||
return d.DialContext(ctx, "tcp", "localhost:"+strconv.Itoa(port))
|
var d net.Dialer
|
||||||
|
return d.DialContext(ctx, "tcp", "localhost:"+strconv.Itoa(port))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return safesocket.ConnectDefault()
|
return safesocket.Connect(TailscaledSocket, 41112)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/peterbourgon/ff/v2/ffcli"
|
"github.com/peterbourgon/ff/v2/ffcli"
|
||||||
|
"tailscale.com/client/tailscale"
|
||||||
"tailscale.com/ipn"
|
"tailscale.com/ipn"
|
||||||
"tailscale.com/paths"
|
"tailscale.com/paths"
|
||||||
"tailscale.com/safesocket"
|
"tailscale.com/safesocket"
|
||||||
@ -88,6 +89,8 @@ change in the future.
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tailscale.TailscaledSocket = rootArgs.socket
|
||||||
|
|
||||||
err := rootCmd.Run(context.Background())
|
err := rootCmd.Run(context.Background())
|
||||||
if err == flag.ErrHelp {
|
if err == flag.ErrHelp {
|
||||||
return nil
|
return nil
|
||||||
|
@ -10,8 +10,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"tailscale.com/paths"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type closeable interface {
|
type closeable interface {
|
||||||
@ -31,11 +29,6 @@ func ConnCloseWrite(c net.Conn) error {
|
|||||||
return c.(closeable).CloseWrite()
|
return c.(closeable).CloseWrite()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConnectDefault connects to the local Tailscale daemon.
|
|
||||||
func ConnectDefault() (net.Conn, error) {
|
|
||||||
return Connect(paths.DefaultTailscaledSocket(), 41112)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect connects to either path (on Unix) or the provided localhost port (on Windows).
|
// Connect connects to either path (on Unix) or the provided localhost port (on Windows).
|
||||||
func Connect(path string, port uint16) (net.Conn, error) {
|
func Connect(path string, port uint16) (net.Conn, error) {
|
||||||
return connect(path, port)
|
return connect(path, port)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user