conffile

package
v1.102.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: BSD-3-Clause Imports: 21 Imported by: 5

Documentation

Overview

Package conffile contains code to load, manipulate, and access config file settings.

Index

Constants

View Source
const LegacyVersion = "0.0.0"

LegacyVersion is the sentinel ServicesConfigFile.Version used to mark a config that was loaded from the legacy raw ipn.ServeConfig format (a version-less file, such as "tailscale serve status --json" output). When Version is LegacyVersion, ServicesConfigFile.Legacy is set and Services is nil. It is never written to disk; the on-disk format always uses "0.0.1".

View Source
const VMUserDataPath = "vm:user-data"

VMUserDataPath is a sentinel value for Load to use to get the data from the VM's metadata service's user-data field.

Variables

View Source
var ErrNoConfig = errors.New("no config present")

ErrNoConfig is returned (wrapped) by Load when the config source is absent or unreadable: a missing file, an EC2 instance with no user-data, an unreachable metadata service, or a build without the relevant cloud support. It reports "no config was provided", as distinct from "a config was provided but is invalid" (which Load returns as an unwrapped parse/validate error). Callers that want to boot unconfigured when no config is present (e.g. tailscaled's "optional:" -config prefix) can check for it with errors.Is.

Functions

This section is empty.

Types

type Config

type Config struct {
	Path    string // disk path of HuJSON, or VMUserDataPath
	Raw     []byte // raw bytes from disk, in HuJSON form
	Std     []byte // standardized JSON form
	Version string // "alpha0" for now

	// Parsed is the parsed config, converted from its on-disk version to the
	// latest known format.
	//
	// As of 2023-10-15 there is exactly one format ("alpha0") so this is both
	// the on-disk format and the in-memory upgraded format.
	Parsed ipn.ConfigVAlpha
}

Config describes a config file.

func Load

func Load(path string) (*Config, error)

Load reads and parses the config file at the provided path on disk.

func (*Config) WantRunning

func (c *Config) WantRunning() bool

WantRunning reports whether c is non-nil and it's configured to be running.

type ServiceDetailsFile added in v1.90.0

type ServiceDetailsFile struct {
	// Version is always "0.0.1", set if and only if this is not inside a
	// [ServiceConfigFile].
	Version string `json:"version,omitzero"`

	// Endpoints are sets of reverse proxy mappings from ProtoPortRanges on a
	// Service to Targets (proto+destination+port) on remote destinations (or
	// localhost).
	// For example, "tcp:443" -> "tcp://localhost:8000" is an endpoint definition
	// mapping traffic on the TCP port 443 of the Service to port 8080 on localhost.
	// The Proto in the key must be populated.
	// As a special case, if the only mapping provided is "*" -> "TUN", that
	// enables TUN/L3 mode, where packets are delivered to the Tailscale network
	// interface with the understanding that the user will deal with them manually.
	Endpoints map[*tailcfg.ProtoPortRange]*Target `json:"endpoints"`

	// Advertised is a flag that tells control whether or not the client thinks
	// it is ready to host a particular Tailscale Service. If unset, it is
	// assumed to be true.
	Advertised opt.Bool `json:"advertised,omitzero"`
}

ServiceDetailsFile is the config syntax for an individual Tailscale Service.

type ServiceProtocol added in v1.90.0

type ServiceProtocol string

ServiceProtocol is the protocol of a Target.

const (
	ProtoHTTP             ServiceProtocol = "http"
	ProtoHTTPS            ServiceProtocol = "https"
	ProtoHTTPSInsecure    ServiceProtocol = "https+insecure"
	ProtoTCP              ServiceProtocol = "tcp"
	ProtoTLSTerminatedTCP ServiceProtocol = "tls-terminated-tcp"
	ProtoFile             ServiceProtocol = "file"
	ProtoTUN              ServiceProtocol = "TUN"
)

type ServicesConfigFile added in v1.90.0

type ServicesConfigFile struct {
	// Version is "0.0.1" for the declarative services configuration file
	// format, or [LegacyVersion] ("0.0.0") when this value was produced by
	// [LoadServicesConfig] from a legacy raw ipn.ServeConfig file (in which
	// case Legacy is set instead of Services).
	Version string `json:"version"`

	Services map[tailcfg.ServiceName]*ServiceDetailsFile `json:"services,omitzero"`

	// Legacy holds a raw ipn.ServeConfig parsed from a version-less file (e.g.
	// "tailscale serve status --json" output). It is non-nil only when Version
	// is [LegacyVersion]. It is an in-memory loading artifact and is never
	// serialized.
	Legacy *ipn.ServeConfig `json:"-"`
}

ServicesConfigFile is the config file format for services configuration.

func LoadServicesConfig added in v1.90.0

func LoadServicesConfig(filename string, forService string) (*ServicesConfigFile, error)

LoadServicesConfig loads a serve config file as a ServicesConfigFile.

If the file has a top-level "version" field it is parsed as that versioned declarative format. Otherwise it is treated as a legacy raw ipn.ServeConfig (such as "tailscale serve status --json" emits): the returned ServicesConfigFile has Version LegacyVersion and its Legacy field set to the parsed raw config, with Services left nil.

forService is used only for the versioned Services configuration file format.

type Target added in v1.90.0

type Target struct {
	// The protocol over which to communicate with the Destination.
	// Protocol == ProtoTUN is a special case, activating "TUN mode" where
	// packets are delivered to the Tailscale TUN interface and then manually
	// handled by the user.
	Protocol ServiceProtocol

	// If Protocol is ProtoFile, then Destination is a file path.
	// If Protocol is ProtoTUN, then Destination is empty.
	// If Protocol is ProtoHTTP, ProtoHTTPS, ProtoHTTPSInsecure, ProtoTCP, or
	// ProtoTLSTerminatedTCP and Destination starts with "unix:", it is a Unix
	// socket path (e.g. "unix:/var/run/app.sock" or "unix:relative.sock").
	// Otherwise, it is a host.
	Destination string

	// If Protocol is not ProtoFile or ProtoTUN, then DestinationPorts is the
	// set of ports on which to connect to the host referred to by Destination.
	// For unix socket targets (Destination starting with "unix:"),
	// DestinationPorts is unused and left at the zero value.
	DestinationPorts tailcfg.PortRange
}

Target is a destination for traffic to go to when it arrives at a Tailscale Service host.

func (*Target) MarshalText added in v1.90.0

func (t *Target) MarshalText() ([]byte, error)

func (*Target) UnmarshalJSON added in v1.90.0

func (t *Target) UnmarshalJSON(buf []byte) error

UnmarshalJSON implements [jsonv1.Unmarshaler].

func (*Target) UnmarshalJSONFrom added in v1.90.0

func (t *Target) UnmarshalJSONFrom(dec *jsontext.Decoder) error

UnmarshalJSONFrom implements jsonv2.UnmarshalerFrom.

Jump to

Keyboard shortcuts

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