types

package
v0.23.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: BSD-3-Clause Imports: 27 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HTTPReadTimeout        = 30 * time.Second
	HTTPShutdownTimeout    = 3 * time.Second
	TLSALPN01ChallengeType = "TLS-ALPN-01"
	HTTP01ChallengeType    = "HTTP-01"

	JSONLogFormat = "json"
	TextLogFormat = "text"

	KeepAliveInterval = 60 * time.Second
	MaxHostnameLength = 255
)

Variables

View Source
var (
	ErrNodeAddressesInvalid = errors.New("failed to parse node addresses")
	ErrHostnameTooLong      = errors.New("hostname too long")
)
View Source
var (
	ExitRouteV4 = netip.MustParsePrefix("0.0.0.0/0")
	ExitRouteV6 = netip.MustParsePrefix("::/0")
)
View Source
var ErrCannotParsePrefix = errors.New("cannot parse prefix")

Functions

func GetDNSConfig

func GetDNSConfig() (*tailcfg.DNSConfig, string)

func IsCLIConfigured

func IsCLIConfigured() bool

func LoadConfig

func LoadConfig(path string, isFile bool) error

Types

type ACLConfig

type ACLConfig struct {
	PolicyPath string
}

func GetACLConfig

func GetACLConfig() ACLConfig

type APIKey

type APIKey struct {
	ID     uint64 `gorm:"primary_key"`
	Prefix string `gorm:"uniqueIndex"`
	Hash   []byte

	CreatedAt  *time.Time
	Expiration *time.Time
	LastSeen   *time.Time
}

APIKey describes the datamodel for API keys used to remotely authenticate with headscale.

func (*APIKey) Proto

func (key *APIKey) Proto() *v1.ApiKey

type CLIConfig

type CLIConfig struct {
	Address  string
	APIKey   string
	Timeout  time.Duration
	Insecure bool
}

type Config

type Config struct {
	ServerURL                      string
	Addr                           string
	MetricsAddr                    string
	GRPCAddr                       string
	GRPCAllowInsecure              bool
	EphemeralNodeInactivityTimeout time.Duration
	NodeUpdateCheckInterval        time.Duration
	IPPrefixes                     []netip.Prefix
	PrivateKeyPath                 string
	NoisePrivateKeyPath            string
	BaseDomain                     string
	Log                            LogConfig
	DisableUpdateCheck             bool

	DERP DERPConfig

	DBtype string
	DBpath string
	DBhost string
	DBport int
	DBname string
	DBuser string
	DBpass string
	DBssl  string

	TLS TLSConfig

	ACMEURL   string
	ACMEEmail string

	DNSConfig *tailcfg.DNSConfig

	UnixSocket           string
	UnixSocketPermission fs.FileMode

	OIDC OIDCConfig

	LogTail             LogTailConfig
	RandomizeClientPort bool

	CLI CLIConfig

	ACL ACLConfig
}

Config contains the initial Headscale configuration.

func GetHeadscaleConfig

func GetHeadscaleConfig() (*Config, error)

type DERPConfig

type DERPConfig struct {
	ServerEnabled    bool
	ServerRegionID   int
	ServerRegionCode string
	ServerRegionName string
	STUNAddr         string
	URLs             []url.URL
	Paths            []string
	AutoUpdate       bool
	UpdateFrequency  time.Duration
}

func GetDERPConfig

func GetDERPConfig() DERPConfig

type HostInfo

type HostInfo tailcfg.Hostinfo

This is a "wrapper" type around tailscales Hostinfo to allow us to add database "serialization" methods. This allows us to use a typed values throughout the code and not have to marshal/unmarshal and error check all over the code.

func (*HostInfo) Scan

func (hi *HostInfo) Scan(destination interface{}) error

func (HostInfo) Value

func (hi HostInfo) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface.

type IPPrefix

type IPPrefix netip.Prefix

func (*IPPrefix) Scan

func (i *IPPrefix) Scan(destination interface{}) error

func (IPPrefix) Value

func (i IPPrefix) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface.

type IPPrefixes

type IPPrefixes []netip.Prefix

func (*IPPrefixes) Scan

func (i *IPPrefixes) Scan(destination interface{}) error

func (IPPrefixes) Value

func (i IPPrefixes) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface.

type LetsEncryptConfig

type LetsEncryptConfig struct {
	Listen        string
	Hostname      string
	CacheDir      string
	ChallengeType string
}

type LogConfig

type LogConfig struct {
	Format string
	Level  zerolog.Level
}

func GetLogConfig

func GetLogConfig() LogConfig

type LogTailConfig

type LogTailConfig struct {
	Enabled bool
}

func GetLogTailConfig

func GetLogTailConfig() LogTailConfig

type Node

type Node struct {
	ID          uint64 `gorm:"primary_key"`
	MachineKey  string `gorm:"type:varchar(64);unique_index"`
	NodeKey     string
	DiscoKey    string
	IPAddresses NodeAddresses

	// Hostname represents the name given by the Tailscale
	// client during registration
	Hostname string

	// Givenname represents either:
	// a DNS normalized version of Hostname
	// a valid name set by the User
	//
	// GivenName is the name used in all DNS related
	// parts of headscale.
	GivenName string `gorm:"type:varchar(63);unique_index"`
	UserID    uint
	User      User `gorm:"foreignKey:UserID"`

	RegisterMethod string

	ForcedTags StringList

	// TODO(kradalby): This seems like irrelevant information?
	AuthKeyID uint
	AuthKey   *PreAuthKey

	LastSeen *time.Time
	Expiry   *time.Time

	HostInfo  HostInfo
	Endpoints StringList

	Routes []Route

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

Node is a Headscale client.

func (*Node) CanAccess

func (node *Node) CanAccess(filter []tailcfg.FilterRule, node2 *Node) bool

func (*Node) DiscoPublicKey

func (node *Node) DiscoPublicKey() (key.DiscoPublic, error)

func (*Node) GetFQDN

func (node *Node) GetFQDN(dnsConfig *tailcfg.DNSConfig, baseDomain string) (string, error)

func (*Node) GetHostInfo

func (node *Node) GetHostInfo() tailcfg.Hostinfo

GetHostInfo returns a Hostinfo struct for the node.

func (*Node) IsEphemeral

func (node *Node) IsEphemeral() bool

IsEphemeral returns if the node is registered as an Ephemeral node. https://tailscale.com/kb/1111/ephemeral-nodes/

func (Node) IsExpired

func (node Node) IsExpired() bool

IsExpired returns whether the node registration has expired.

func (*Node) IsOnline

func (node *Node) IsOnline() bool

IsOnline returns if the node is connected to Headscale. This is really a naive implementation, as we don't really see if there is a working connection between the client and the server.

func (*Node) MachinePublicKey

func (node *Node) MachinePublicKey() (key.MachinePublic, error)

func (*Node) NodePublicKey

func (node *Node) NodePublicKey() (key.NodePublic, error)

func (*Node) Proto

func (node *Node) Proto() *v1.Node

func (Node) String

func (node Node) String() string

type NodeAddresses

type NodeAddresses []netip.Addr

func (NodeAddresses) AppendToIPSet

func (na NodeAddresses) AppendToIPSet(build *netipx.IPSetBuilder)

AppendToIPSet adds the individual ips in NodeAddresses to a given netipx.IPSetBuilder.

func (NodeAddresses) InIPSet

func (na NodeAddresses) InIPSet(set *netipx.IPSet) bool

func (NodeAddresses) Prefixes

func (na NodeAddresses) Prefixes() []netip.Prefix

func (*NodeAddresses) Scan

func (na *NodeAddresses) Scan(destination interface{}) error

func (NodeAddresses) Sort

func (na NodeAddresses) Sort()

func (NodeAddresses) StringSlice

func (na NodeAddresses) StringSlice() []string

func (NodeAddresses) Value

func (na NodeAddresses) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface.

type Nodes

type Nodes []*Node

func (Nodes) FilterByIP

func (nodes Nodes) FilterByIP(ip netip.Addr) Nodes

func (Nodes) IDMap

func (nodes Nodes) IDMap() map[uint64]*Node

func (Nodes) OnlineNodeMap

func (nodes Nodes) OnlineNodeMap() map[tailcfg.NodeID]bool

func (Nodes) String

func (nodes Nodes) String() string

type OIDCConfig

type OIDCConfig struct {
	OnlyStartIfOIDCIsAvailable bool
	Issuer                     string
	ClientID                   string
	ClientSecret               string
	Scope                      []string
	ExtraParams                map[string]string
	AllowedDomains             []string
	AllowedUsers               []string
	AllowedGroups              []string
	StripEmaildomain           bool
	Expiry                     time.Duration
	UseExpiryFromToken         bool
}

type PreAuthKey

type PreAuthKey struct {
	ID        uint64 `gorm:"primary_key"`
	Key       string
	UserID    uint
	User      User
	Reusable  bool
	Ephemeral bool `gorm:"default:false"`
	Used      bool `gorm:"default:false"`
	ACLTags   []PreAuthKeyACLTag

	CreatedAt  *time.Time
	Expiration *time.Time
}

PreAuthKey describes a pre-authorization key usable in a particular user.

func (*PreAuthKey) Proto

func (key *PreAuthKey) Proto() *v1.PreAuthKey

type PreAuthKeyACLTag

type PreAuthKeyACLTag struct {
	ID           uint64 `gorm:"primary_key"`
	PreAuthKeyID uint64
	Tag          string
}

PreAuthKeyACLTag describes an autmatic tag applied to a node when registered with the associated PreAuthKey.

type Route

type Route struct {
	gorm.Model

	NodeID uint64
	Node   Node
	Prefix IPPrefix

	Advertised bool
	Enabled    bool
	IsPrimary  bool
}

func (*Route) IsExitRoute

func (r *Route) IsExitRoute() bool

func (*Route) String

func (r *Route) String() string

type Routes

type Routes []Route

func (Routes) Prefixes

func (rs Routes) Prefixes() []netip.Prefix

func (Routes) Proto

func (rs Routes) Proto() []*v1.Route

type StateUpdate

type StateUpdate struct {
	// The type of update
	Type StateUpdateType

	// Changed must be set when Type is StatePeerChanged and
	// contain the Node IDs of nodes that have changed.
	Changed Nodes

	// Removed must be set when Type is StatePeerRemoved and
	// contain a list of the nodes that has been removed from
	// the network.
	Removed []tailcfg.NodeID

	// DERPMap must be set when Type is StateDERPUpdated and
	// contain the new DERP Map.
	DERPMap tailcfg.DERPMap
}

StateUpdate is an internal message containing information about a state change that has happened to the network.

type StateUpdateType

type StateUpdateType int
const (
	StateFullUpdate StateUpdateType = iota
	StatePeerChanged
	StatePeerRemoved
	StateDERPUpdated
)

type StringList

type StringList []string

func (*StringList) Scan

func (i *StringList) Scan(destination interface{}) error

func (StringList) Value

func (i StringList) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface.

type TLSConfig

type TLSConfig struct {
	CertPath string
	KeyPath  string

	LetsEncrypt LetsEncryptConfig
}

func GetTLSConfig

func GetTLSConfig() TLSConfig

type User

type User struct {
	gorm.Model
	Name string `gorm:"unique"`
}

User is the way Headscale implements the concept of users in Tailscale

At the end of the day, users in Tailscale are some kind of 'bubbles' or users that contain our machines.

func (*User) Proto

func (n *User) Proto() *v1.User

func (*User) TailscaleLogin

func (n *User) TailscaleLogin() *tailcfg.Login

func (*User) TailscaleUser

func (n *User) TailscaleUser() *tailcfg.User

Jump to

Keyboard shortcuts

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