share

package
v0.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	HelloPath = "/api/hello"
	PairPath  = "/api/pair"
)

Paths that work for an owned device without a signature.

Variables

View Source
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>".

View Source
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.

View Source
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

func Challenge

func Challenge(h http.Header) string

Challenge adds a fresh challenge to h and returns it.

Types

type Code

type Code struct {
	Code      string    `json:"code"`
	ExpiresAt time.Time `json:"expiresAt"`
}

Code is a pairing code shown to the user.

type Credential

type Credential struct {
	ID  string `json:"id"`
	Key string `json:"key"`
}

Credential is what a connecting device keeps after pairing.

func (Credential) Proven

func (c Credential) Proven(challenge string, reply http.Header) (string, bool)

Proven reports whether a reply proves that the daemon holds c's key, and returns the listener epoch the proof vouches for.

func (Credential) Sign

func (c Credential) Sign(h http.Header, method, uri string, body []byte, epoch string)

Sign adds the signature headers for a request to h. uri is the request URI as sent on the wire (escaped path and query); epoch is the one the daemon last proved, empty before the first proof.

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 New

func New(port int, stateDir string, ts *tailnet.Cache) *Manager

New creates a manager for a daemon on port that keeps its files in stateDir.

func (*Manager) Apply

func (m *Manager) Apply(ctx context.Context) Status

Apply makes the live state match the setting. Problems are kept in Status.

func (*Manager) Close

func (m *Manager) Close(ctx context.Context)

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

func (m *Manager) NewCode() (Code, error)

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

func (m *Manager) Revoke(ref string) (bool, error)

Revoke removes a paired device by ID, DNS name or host name and ends its requests in flight.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context)

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) Set

func (m *Manager) Set(enabled bool)

Set records whether sharing should be on; Apply makes it so.

func (*Manager) SetHandler

func (m *Manager) SetHandler(h http.Handler)

SetHandler sets the handler for accepted requests.

func (*Manager) SetNotifier added in v0.4.0

func (m *Manager) SetNotifier(fn func(title, msg string))

SetNotifier sets the function that shows a desktop notification.

func (*Manager) Status

func (m *Manager) Status() Status

Status returns the current state.

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.

func PeerFrom

func PeerFrom(ctx context.Context) (Peer, bool)

PeerFrom returns the device behind a request the guard accepted.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL