tailscale

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 13 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 tailscale is everything grat asks of Tailscale, and nothing more.

The rest of grat never calls the foreign tool directly. It takes the Client interface, so the commands can be tested on a machine that has no Tailscale, and so a different way of publishing a local service would replace this package rather than every caller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inspect

func Inspect(ctx context.Context) (Stage, CommandClient, error)

Inspect reports how far this machine has come.

A missing command and an unreachable service are told apart without reading the tool's error text: if the command is there and the status call fails, the service is what is missing. That holds on both systems and survives a reworded message.

func IsInstalledByPackageManager

func IsInstalledByPackageManager(executable string) bool

IsInstalledByPackageManager reports whether the executable sits where the documented installation puts it, which is what makes it grat's to remove.

It is a second opinion on the note grat wrote when it installed: a person who replaced that Tailscale with one of their own should keep it.

func OpenInBrowser

func OpenInBrowser(ctx context.Context, address string) error

OpenInBrowser asks the system to open address. A failure is not fatal, because the address is printed as well and can be opened by hand.

func Run

func Run(ctx context.Context, name string, arguments []string, input io.Reader, output io.Writer) error

Run executes a prepared command, letting only its error stream reach the terminal.

This is for the one command a person has to take part in: starting the background service asks for an administrator password, and sudo writes that prompt to the error stream and expects the terminal to show it. Capturing that would leave grat waiting with nothing on screen. What the command writes to standard output is the package manager talking about itself, so it is kept for a failure and shown at no other time.

func RunQuietly

func RunQuietly(ctx context.Context, name string, arguments []string) error

RunQuietly executes a prepared command without letting its output reach the terminal.

A package manager prints a great deal that is about itself rather than about grat, and the step lines around this call exist so that a reader follows what grat is doing. The output is kept rather than discarded, because a failure is only explainable with it.

func RunRemovalStep

func RunRemovalStep(ctx context.Context, step RemovalStep, output writerForPrompt) error

RunRemovalStep executes one step.

A step that asks for a password keeps its error stream, because sudo writes the prompt there and expects a terminal to show it. Everything else is the package manager talking about itself and is kept for a failure.

Types

type Client

type Client interface {
	// Open publishes funnel.Path at funnel.PublicPort, forwarding to funnel.Target.
	//
	// needsEnabling is called with an address when the tailnet has not enabled
	// Funnel, which is a permission only its owner can grant. The call happens
	// whilst Open is still waiting, because that address is what ends the wait.
	Open(ctx context.Context, funnel Funnel, needsEnabling func(address string)) error
	// Close withdraws exactly the given funnel and leaves every other one standing.
	Close(ctx context.Context, funnel Funnel) error
	// Funnels reports what is published right now.
	Funnels(ctx context.Context) ([]Funnel, error)
	// Hostname returns the machine's name inside the tailnet.
	Hostname(ctx context.Context) (string, error)
}

Client is the set of Tailscale operations grat performs.

Implementations must leave alone anything grat did not open. Close therefore takes the same funnel that Open received, rather than clearing whatever is currently published.

type CommandClient

type CommandClient struct {
	// contains filtered or unexported fields
}

CommandClient talks to Tailscale by running its command.

func Locate

func Locate() (CommandClient, error)

Locate finds the Tailscale command and returns a client bound to it.

It looks on the PATH first and then inside the macOS application bundle. A missing command yields ErrNotInstalled naming both places, because that error is the starting point for installing Tailscale rather than a failure on its own.

func NewCommandClient

func NewCommandClient(path string) CommandClient

NewCommandClient returns a client that runs the command at path. The setup step uses it after an installation, when it knows where the command landed.

func (CommandClient) Close

func (client CommandClient) Close(ctx context.Context, funnel Funnel) error

Close withdraws one path. Tailscale requires the same flags the funnel was opened with, followed by off, so the arguments differ from Open only in that word and in the omitted target.

func (CommandClient) Executable

func (client CommandClient) Executable() string

Executable returns the resolved path, which the setup step reports.

func (CommandClient) Funnels

func (client CommandClient) Funnels(ctx context.Context) ([]Funnel, error)

Funnels reports what Tailscale currently publishes.

The shape read here is the serve configuration: AllowFunnel says which host and port pairs are public, and Web lists the paths served below each of them. Only those two parts are read, so a field elsewhere in that structure does not concern grat.

func (CommandClient) Hostname

func (client CommandClient) Hostname(ctx context.Context) (string, error)

Hostname returns this machine's name inside the tailnet, without the trailing dot that Tailscale appends to the fully qualified name.

func (CommandClient) Open

func (client CommandClient) Open(ctx context.Context, funnel Funnel, needsEnabling func(address string)) error

Open publishes one path.

The funnel runs in the background, because it has to outlive the grat command that opened it: without --bg the tool holds the terminal and withdraws the funnel when it is interrupted. Prompts are answered in advance with --yes, since grat asks the one question that matters before it gets here.

One thing --yes cannot answer is a tailnet that has not enabled Funnel at all. Tailscale then prints an address and waits for somebody to visit it, so the command neither fails nor returns. needsEnabling is called with that address when it appears, which is what lets the caller say so and open the page rather than leaving a reader in front of a command that looks stuck.

func (CommandClient) SignIn

func (client CommandClient) SignIn(ctx context.Context) error

SignIn starts the sign-in.

Its output stays off the terminal. The address a person has to visit is read from the status by SignInURL and opened by grat itself, so printing it here as well would say the same thing twice in a shape grat does not control. It returns as soon as the command does, which is before the machine is connected; WaitUntilReady covers the rest.

func (CommandClient) SignInURL

func (client CommandClient) SignInURL(ctx context.Context) (string, error)

SignInURL returns the address a person has to open to sign this machine in.

It is empty until the sign-in has actually been started, and empty again once the machine is connected, so a caller starts SignIn first and then polls this until an address appears. Reading it from the status is what lets grat open the page itself instead of parsing the tool's printed output.

func (CommandClient) WaitUntilReady

func (client CommandClient) WaitUntilReady(ctx context.Context, interval time.Duration) error

WaitUntilReady polls until the machine reports itself connected or the context ends. The interval is short enough to feel immediate and long enough not to spin.

type ErrCommandFailed

type ErrCommandFailed struct {
	// Arguments is the command line grat used, without the executable.
	Arguments []string
	// Output is what Tailscale wrote, trimmed.
	Output string
	// Err is the underlying failure from running the process.
	Err error
}

ErrCommandFailed reports that the Tailscale command ran and refused. It carries what Tailscale said, so a caller can show a reason without the caller having to know anything about the tool.

func (ErrCommandFailed) Error

func (err ErrCommandFailed) Error() string

func (ErrCommandFailed) Unwrap

func (err ErrCommandFailed) Unwrap() error

type ErrNoInstallPath

type ErrNoInstallPath struct {
	System string
	Reason string
}

ErrNoInstallPath reports that grat knows no documented way to install Tailscale on this system. It carries the system name so the message can say which.

func (ErrNoInstallPath) Error

func (err ErrNoInstallPath) Error() string

type ErrNotInstalled

type ErrNotInstalled struct {
	// Searched lists the places that were looked at, so the message can say where.
	Searched []string
}

ErrNotInstalled reports that no Tailscale command could be found. It is not a failure in itself: the caller decides whether to install Tailscale or to say what is missing.

func (ErrNotInstalled) Error

func (err ErrNotInstalled) Error() string

type ErrRemovalStepFailed

type ErrRemovalStepFailed struct {
	Step RemovalStep
	Err  error
}

ErrRemovalStepFailed carries which step failed, so a report can say what is left to do by hand.

func (ErrRemovalStepFailed) Error

func (err ErrRemovalStepFailed) Error() string

func (ErrRemovalStepFailed) Unwrap

func (err ErrRemovalStepFailed) Unwrap() error

type Funnel

type Funnel struct {
	// Path is the single path that goes public. It starts with a slash, and it is
	// the whole of what leaves the machine.
	Path string
	// PublicPort is the port the funnel listens on. Tailscale accepts 443, 8443 and
	// 10000, and grat rejects anything else when it reads the configuration.
	PublicPort int
	// Target is the local address the funnel forwards to, such as
	// http://localhost:4001.
	Target string
}

Funnel is one local path published to the public internet.

func (Funnel) IsAmong

func (funnel Funnel) IsAmong(published []Funnel) bool

IsAmong reports whether this funnel is one of those.

func (Funnel) PublicURL

func (funnel Funnel) PublicURL(hostname string) string

PublicURL returns the address the outside world reaches this funnel at. hostname is the machine's name inside the tailnet, with or without the trailing dot that Tailscale reports. The default port is left out of the URL, because a payment provider stores this address and a shorter one is easier to check.

func (Funnel) SameAs

func (funnel Funnel) SameAs(other Funnel) bool

SameAs reports whether two funnels are the same publication.

All three fields decide it, and the target is the one that matters most. A path and a port say which slot is taken; only the target says which service is behind it. Comparing the first two alone made every service sharing the default path look published whilst one funnel existed, so grat status showed one address on every row.

type InstallCommand

type InstallCommand struct {
	// Name is the executable, resolved on the PATH.
	Name string
	// Arguments are passed to it unchanged.
	Arguments []string
	// Display is the line to show a person, which for a piped shell command reads
	// differently from the argument list.
	Display string
}

InstallCommand is what grat would run to install Tailscale on this system. The caller shows it before running it, so nobody is surprised by a change to their machine.

func InstallPath

func InstallPath() (InstallCommand, error)

InstallPath returns the vendor-documented way to install Tailscale here.

There is exactly one path per system and grat builds none of its own. On a Mac that is Homebrew, which grat already uses for itself and which also sets up the background service. On Linux it is the vendor's install script, which adds the package source of the distribution in use.

type RemovalStep

type RemovalStep struct {
	// Subject is what the step is about, as the step line names it.
	Subject string
	// Detail says what the step does, in the present tense.
	Detail string
	// Display is the command as a person would type it, shown before it runs
	// because it changes the machine.
	Display string
	// Name and Arguments are what is executed.
	Name      string
	Arguments []string
	// NeedsAdministrator says the system will ask for a password here.
	NeedsAdministrator bool
	// Optional marks a step whose failure does not stop the rest. Leaving a
	// directory behind is untidy; stopping half way through is worse.
	Optional bool
}

RemovalStep is one command in taking Tailscale off a machine, with the words that say what it is for before it runs.

func RemovalPath

func RemovalPath(executable string) ([]RemovalStep, error)

RemovalPath returns the steps that take Tailscale off this machine, in the order they have to run.

The order is not free. Signing out needs the daemon, so it comes before the service is stopped, and the leftover paths can only go once the package manager has given up its own.

type ServiceCommand

type ServiceCommand struct {
	Name      string
	Arguments []string
	Display   string
	// Note is a consequence worth hearing before the command runs, or empty.
	Note string
	// NeedsAdministrator reports whether the system will ask for a password. grat
	// says so before running it rather than letting the prompt appear unexplained.
	NeedsAdministrator bool
}

ServiceCommand is what starts the background service on this system.

func StartServicePath

func StartServicePath() (ServiceCommand, error)

StartServicePath returns the documented way to run the background service.

On a Mac installed through Homebrew that is a Homebrew service, which needs administrator rights because the service touches the network stack. On Linux the install script leaves a system service that is already enabled, so there is nothing for grat to do beyond reporting it.

type Stage

type Stage string

Stage is how far a machine has come towards being able to publish a funnel. The stages are ordered, and each one is fixed by exactly one action.

const (
	// StageMissing means no Tailscale command was found.
	StageMissing Stage = "missing"
	// StageStopped means the command exists but its background service does not
	// answer.
	StageStopped Stage = "stopped"
	// StageSignedOut means the service runs and this machine belongs to no tailnet.
	StageSignedOut Stage = "signed-out"
	// StageStarting means the service is coming up and has not settled yet.
	StageStarting Stage = "starting"
	// StageReady means a funnel can be opened.
	StageReady Stage = "ready"
)

Directories

Path Synopsis
Package tailscaletest provides a Tailscale client that records what it was asked to do, so commands can be tested on a machine without Tailscale.
Package tailscaletest provides a Tailscale client that records what it was asked to do, so commands can be tested on a machine without Tailscale.

Jump to

Keyboard shortcuts

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