tailnet

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 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 tailnet asks the local Tailscale client about this machine: whether it is on a tailnet, its MagicDNS name and addresses, and whether the tailnet can issue HTTPS certificates for it. It also fetches such a certificate (`tailscale cert`). It only runs the tailscale command line with fixed arguments; it never talks to the network itself, and a machine without Tailscale simply reports that it is not on a tailnet.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoTailscale = errors.New("tailscale is not installed (no tailscale command found)")

ErrNoTailscale means the tailscale command line was not found.

Functions

func Find

func Find() string

Find returns the path of the tailscale command line, or "" when it is not installed: tailscale on PATH, else the standard install location of the Windows and macOS apps.

Types

type Client

type Client struct {
	// Run runs the tailscale command line; nil finds it (Find) and runs it.
	Run Runner
	// CacheFor is how long a Status answer is reused; 0 means a minute.
	CacheFor time.Duration
	// Now is the clock; nil means time.Now.
	Now func() time.Time
	// contains filtered or unexported fields
}

Client asks Tailscale about this machine. The zero value finds the tailscale command line on first use.

func (*Client) Cert

func (c *Client) Cert(ctx context.Context, domain, certFile, keyFile string) error

Cert fetches (or renews) the HTTPS certificate for domain from the tailnet into certFile and keyFile, using `tailscale cert`. Tailscale keeps its own copy and only asks for a new certificate when the old one is close to expiry, so calling it daily is cheap. The tailnet must have HTTPS certificates enabled, and the certificate is published in the public Certificate Transparency logs.

func (*Client) Forget

func (c *Client) Forget()

Forget drops the cached Status answer.

func (*Client) Status

func (c *Client) Status(ctx context.Context) (Info, error)

Status reports this machine's tailnet state. A machine without Tailscale, or with Tailscale stopped or logged out, reports Info{Running: false} and no error; errors are for a tailscale command line that answered something unexpected.

type Info

type Info struct {
	// Running is true when Tailscale is up and logged in to a tailnet.
	Running bool `json:"running"`
	// DNSName is this machine's MagicDNS name without the trailing dot,
	// for example "chat-pi.tail1234.ts.net"; "" when MagicDNS is off.
	DNSName string `json:"dns_name,omitempty"`
	// IPs are this machine's Tailscale addresses (100.x.y.z and fd7a:...).
	IPs []netip.Addr `json:"ips,omitempty"`
	// CertDomains are the names the tailnet can issue HTTPS certificates
	// for; empty when HTTPS certificates are not enabled in the tailnet.
	CertDomains []string `json:"cert_domains,omitempty"`
}

Info is what Tailscale reports about this machine.

func ParseStatus

func ParseStatus(b []byte) (Info, error)

ParseStatus reads the output of `tailscale status --json`.

func (Info) CanCert

func (i Info) CanCert() bool

CanCert reports whether the tailnet issues HTTPS certificates for DNSName.

type Runner

type Runner func(ctx context.Context, args ...string) ([]byte, error)

Runner runs the tailscale command line with args and returns its standard output.

Jump to

Keyboard shortcuts

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