Documentation
¶
Overview ¶
Package share lets the owner's other devices connect to this daemon.
Tailscale Serve publishes https://<this machine>:<daemon port> on the tailnet and forwards it to a loopback listener under a random path that only the Serve configuration knows. (A Unix socket would keep other local accounts out by itself, but macOS's sandboxed Tailscale cannot open one and Linux lets only administrators serve one.) A request is accepted when all of these hold:
- it arrived under that path, for this machine's tailnet name or address, and on Linux over a connection from root or this account, which tailscaled runs as (see fromserve.go);
- it carries the peer header, which a web page cannot add without a CORS preflight, so a browser on one of the devices cannot be abused;
- Tailscale reports it from another device of the user who owns this machine, not tagged (Serve sets Tailscale-User-Login and X-Forwarded-For itself); requests from this machine are refused, so local accounts, apps and containers cannot use the tailnet way in;
- it is signed with the key this daemon issued to that same device when it was paired with a one-time code (see devices.go and sign.go). Only the hello and pairing endpoints work without a signature.
Index ¶
- Constants
- Variables
- func Challenge(h http.Header) string
- type Code
- type Credential
- type Device
- type DeviceStatus
- type Manager
- func (m *Manager) Apply(ctx context.Context) Status
- func (m *Manager) Close(ctx context.Context)
- func (m *Manager) NewCode() (Code, error)
- func (m *Manager) Pair(p Peer, code, instance string) (Credential, error)
- func (m *Manager) Revoke(ref string) (bool, error)
- func (m *Manager) Run(ctx context.Context)
- func (m *Manager) Set(enabled bool)
- func (m *Manager) SetHandler(h http.Handler)
- func (m *Manager) SetNotifier(fn func(title, msg string))
- func (m *Manager) Status() Status
- func (m *Manager) Subscribe() chan struct{}
- func (m *Manager) Unsubscribe(ch chan struct{})
- type Peer
- type Status
Constants ¶
const ( HelloPath = "/api/hello" PairPath = "/api/pair" )
Paths that work for an owned device without a signature.
Variables ¶
var ( HeaderDevice = signing.Header("Device") HeaderChallenge = signing.HeaderChallenge HeaderProof = signing.HeaderProof // HeaderEpoch names the listener a request is meant for. Each listener // has a random epoch, sent with the proof, and signatures cover it, so a // request sent to a listener that no longer exists is useless elsewhere. HeaderEpoch = signing.HeaderEpoch )
Header names; each is "X-<product>-<name>".
var ErrAmbiguous = errors.New("several paired devices have that name; use the device ID or full DNS name")
ErrAmbiguous is returned when a name matches several paired devices.
var ErrPairing = errors.New("the pairing code is wrong or has expired; get a new one on the shared computer")
ErrPairing is returned for a wrong, used or expired code.
Functions ¶
Types ¶
type Credential ¶
Credential is what a connecting device keeps after pairing.
func (Credential) Proven ¶
Proven reports whether a reply proves that the daemon holds c's key, and returns the listener epoch the proof vouches for.
type Device ¶
type Device struct {
ID string `json:"id"`
Name string `json:"name"`
DNSName string `json:"dnsName"`
OS string `json:"os,omitempty"`
PairedAt time.Time `json:"pairedAt"`
// LastSeen is when the device last connected or disconnected (see
// presence.go), at pairing the pairing time; zero in records from
// before it was kept.
LastSeen time.Time `json:"lastSeen,omitzero"`
// Instance tells apart daemons on the same device (accounts, a
// development daemon); each pairs on its own.
Instance string `json:"instance,omitempty"`
// Key is the device's signing key, hex encoded; never sent to clients.
Key string `json:"key,omitempty"`
}
Device is a paired device.
type DeviceStatus ¶ added in v0.4.0
type DeviceStatus struct {
Device
// Connected is true while the device has a connection open.
Connected bool `json:"connected,omitempty"`
// Since is when the device's announced connection began; a client that
// notifies the user itself announces each new value once.
Since time.Time `json:"since,omitzero"`
}
DeviceStatus is a paired device as the dashboard and the app show it.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the listener, this daemon's Tailscale Serve entry and the paired devices.
func (*Manager) Close ¶
Close withdraws the Serve entry and stops the listener for good: an Apply still queued afterwards does nothing. It gives up waiting when ctx ends.
func (*Manager) NewCode ¶
NewCode issues a pairing code; sharing must be on and reachable, so the code is only ever entered for a daemon that is really serving.
func (*Manager) Pair ¶
func (m *Manager) Pair(p Peer, code, instance string) (Credential, error)
Pair redeems a code for the daemon instance behind an accepted request and returns the credential it signs with from now on.
func (*Manager) Revoke ¶
Revoke removes a paired device by ID, DNS name or host name and ends its requests in flight.
func (*Manager) Run ¶
Run re-applies sharing periodically, so it comes up once Tailscale starts, returns if someone resets Tailscale Serve, and retries a withdrawal that failed.
func (*Manager) SetHandler ¶
SetHandler sets the handler for accepted requests.
func (*Manager) SetNotifier ¶ added in v0.4.0
SetNotifier sets the function that shows a desktop notification.
func (*Manager) Subscribe ¶ added in v0.4.0
func (m *Manager) Subscribe() chan struct{}
Subscribe returns a channel signalled when a device pairs, connects, disconnects or is removed; Unsubscribe stops it.
func (*Manager) Unsubscribe ¶ added in v0.4.0
func (m *Manager) Unsubscribe(ch chan struct{})
type Peer ¶
type Peer struct {
Node tailnet.Node
// Device is the pairing the request presented, nil on the hello and
// pairing endpoints when there is none.
Device *Device
}
Peer describes the device behind an accepted request.
type Status ¶
type Status struct {
Enabled bool `json:"enabled"`
Active bool `json:"active"`
URL string `json:"url,omitempty"`
Error string `json:"error,omitempty"`
Problem string `json:"problem,omitempty"` // tailnet.Problem of Error
Devices []DeviceStatus `json:"devices"`
}
Status describes sharing for the dashboard.