hsic

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: BSD-3-Clause Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IntegrationTestDockerFileName = "Dockerfile.integration"
)

Variables

This section is empty.

Functions

func DefaultConfigEnv added in v0.18.0

func DefaultConfigEnv() map[string]string

func MinimumConfigYAML added in v0.18.0

func MinimumConfigYAML() string

Types

type AuthKeyOptions added in v0.28.0

type AuthKeyOptions struct {
	// User is the user ID that owns the auth key. If nil and Tags are specified,
	// the auth key is owned by the tags only (tags-as-identity model).
	User *uint64
	// Reusable indicates if the key can be used multiple times
	Reusable bool
	// Ephemeral indicates if nodes registered with this key should be ephemeral
	Ephemeral bool
	// Tags are the tags to assign to the auth key
	Tags []string
}

AuthKeyOptions defines options for creating an auth key.

type HeadscaleInContainer

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

HeadscaleInContainer is an implementation of ControlServer which sets up a Headscale instance inside a container.

func New

func New(
	pool *dockertest.Pool,
	networks []*dockertest.Network,
	opts ...Option,
) (*HeadscaleInContainer, error)

New returns a new HeadscaleInContainer instance.

func (*HeadscaleInContainer) ApproveRoutes added in v0.26.0

func (t *HeadscaleInContainer) ApproveRoutes(id uint64, routes []netip.Prefix) (*v1.Node, error)

ApproveRoutes approves routes for a node.

func (*HeadscaleInContainer) ConnectToNetwork added in v0.22.2

func (t *HeadscaleInContainer) ConnectToNetwork(network *dockertest.Network) error

func (*HeadscaleInContainer) CreateAuthKey

func (t *HeadscaleInContainer) CreateAuthKey(
	user uint64,
	reusable bool,
	ephemeral bool,
) (*v1.PreAuthKey, error)

CreateAuthKey creates a new "authorisation key" for a User that can be used to authorise a TailscaleClient with the Headscale instance.

func (*HeadscaleInContainer) CreateAuthKeyWithOptions added in v0.28.0

func (t *HeadscaleInContainer) CreateAuthKeyWithOptions(opts AuthKeyOptions) (*v1.PreAuthKey, error)

CreateAuthKeyWithOptions creates a new "authorisation key" with the specified options. This supports both user-owned and tags-only auth keys.

func (*HeadscaleInContainer) CreateAuthKeyWithTags added in v0.28.0

func (t *HeadscaleInContainer) CreateAuthKeyWithTags(
	user uint64,
	reusable bool,
	ephemeral bool,
	tags []string,
) (*v1.PreAuthKey, error)

CreateAuthKeyWithTags creates a new "authorisation key" for a User with the specified tags. This is used to create tagged PreAuthKeys for testing the tags-as-identity model.

func (*HeadscaleInContainer) CreateUser added in v0.19.0

func (t *HeadscaleInContainer) CreateUser(
	user string,
) (*v1.User, error)

CreateUser adds a new user to the Headscale instance.

func (*HeadscaleInContainer) DebugBatcher added in v0.27.0

func (t *HeadscaleInContainer) DebugBatcher() (*hscontrol.DebugBatcherInfo, error)

DebugBatcher fetches the batcher debug information from the debug endpoint.

func (*HeadscaleInContainer) DebugFilter added in v0.27.0

func (t *HeadscaleInContainer) DebugFilter() ([]tailcfg.FilterRule, error)

DebugFilter fetches the current filter rules from the debug endpoint.

func (*HeadscaleInContainer) DebugNodeStore added in v0.27.0

func (t *HeadscaleInContainer) DebugNodeStore() (map[types.NodeID]types.Node, error)

DebugNodeStore fetches the NodeStore data from the debug endpoint.

func (*HeadscaleInContainer) DebugPolicy added in v0.27.0

func (t *HeadscaleInContainer) DebugPolicy() (string, error)

DebugPolicy fetches the current policy from the debug endpoint.

func (*HeadscaleInContainer) DeleteAuthKey added in v0.28.0

func (t *HeadscaleInContainer) DeleteAuthKey(
	id uint64,
) error

DeleteAuthKey deletes an "authorisation key" by ID.

func (*HeadscaleInContainer) DeleteNode added in v0.27.0

func (t *HeadscaleInContainer) DeleteNode(nodeID uint64) error

func (*HeadscaleInContainer) DeleteUser added in v0.28.0

func (t *HeadscaleInContainer) DeleteUser(userID uint64) error

DeleteUser deletes a user from the Headscale instance.

func (*HeadscaleInContainer) Execute

func (t *HeadscaleInContainer) Execute(
	command []string,
) (string, error)

Execute runs a command inside the Headscale container and returns the result of stdout as a string.

func (*HeadscaleInContainer) FetchPath added in v0.22.2

func (t *HeadscaleInContainer) FetchPath(path string) ([]byte, error)

FetchPath gets a path from inside the Headscale container and returns a tar file as byte array.

func (*HeadscaleInContainer) GetAllMapReponses added in v0.27.0

func (t *HeadscaleInContainer) GetAllMapReponses() (map[types.NodeID][]tailcfg.MapResponse, error)

func (*HeadscaleInContainer) GetCert

func (t *HeadscaleInContainer) GetCert() []byte

GetCert returns the public certificate of the HeadscaleInContainer.

func (*HeadscaleInContainer) GetEndpoint

func (t *HeadscaleInContainer) GetEndpoint() string

GetEndpoint returns the Headscale endpoint for the HeadscaleInContainer.

func (*HeadscaleInContainer) GetHealthEndpoint

func (t *HeadscaleInContainer) GetHealthEndpoint() string

GetHealthEndpoint returns a health endpoint for the HeadscaleInContainer instance.

func (*HeadscaleInContainer) GetHostMetricsPort added in v0.28.0

func (t *HeadscaleInContainer) GetHostMetricsPort() string

GetHostMetricsPort returns the dynamically assigned host port for metrics/pprof access. This port can be used by operators to access metrics at http://localhost:{port}/metrics and debug endpoints at http://localhost:{port}/debug/ while tests are running.

func (*HeadscaleInContainer) GetHostname

func (t *HeadscaleInContainer) GetHostname() string

GetHostname returns the hostname of the HeadscaleInContainer.

func (*HeadscaleInContainer) GetIPEndpoint added in v0.27.0

func (t *HeadscaleInContainer) GetIPEndpoint() string

GetIPEndpoint returns the Headscale endpoint using IP address instead of hostname.

func (*HeadscaleInContainer) GetIPInNetwork added in v0.27.0

func (t *HeadscaleInContainer) GetIPInNetwork(network *dockertest.Network) string

GetIPInNetwork returns the IP address of the HeadscaleInContainer in the given network.

func (*HeadscaleInContainer) GetPort

func (t *HeadscaleInContainer) GetPort() string

GetPort returns the docker container port as a string.

func (*HeadscaleInContainer) ListNodes added in v0.25.0

func (t *HeadscaleInContainer) ListNodes(
	users ...string,
) ([]*v1.Node, error)

ListNodes lists the currently registered Nodes in headscale. Optionally a list of usernames can be passed to get users for specific users.

func (*HeadscaleInContainer) ListUsers added in v0.25.0

func (t *HeadscaleInContainer) ListUsers() ([]*v1.User, error)

ListUsers returns a list of users from Headscale.

func (*HeadscaleInContainer) MapUsers added in v0.26.0

func (t *HeadscaleInContainer) MapUsers() (map[string]*v1.User, error)

MapUsers returns a map of users from Headscale. It is keyed by the user name.

func (*HeadscaleInContainer) NodesByName added in v0.26.0

func (t *HeadscaleInContainer) NodesByName() (map[string]*v1.Node, error)

func (*HeadscaleInContainer) NodesByUser added in v0.26.0

func (t *HeadscaleInContainer) NodesByUser() (map[string][]*v1.Node, error)

func (*HeadscaleInContainer) PID added in v0.26.0

func (h *HeadscaleInContainer) PID() (int, error)

func (*HeadscaleInContainer) PrimaryRoutes added in v0.27.0

func (t *HeadscaleInContainer) PrimaryRoutes() (*routes.DebugRoutes, error)

PrimaryRoutes fetches the primary routes from the debug endpoint.

func (*HeadscaleInContainer) Reload added in v0.26.0

func (h *HeadscaleInContainer) Reload() error

Reload sends a SIGHUP to the headscale process to reload internals, for example Policy from file.

func (*HeadscaleInContainer) SaveDatabase added in v0.23.0

func (t *HeadscaleInContainer) SaveDatabase(savePath string) error

func (*HeadscaleInContainer) SaveLog added in v0.20.0

func (t *HeadscaleInContainer) SaveLog(path string) (string, string, error)

SaveLog saves the current stdout log of the container to a path on the host system.

func (*HeadscaleInContainer) SaveMapResponses added in v0.23.0

func (t *HeadscaleInContainer) SaveMapResponses(savePath string) error

func (*HeadscaleInContainer) SaveMetrics added in v0.23.0

func (t *HeadscaleInContainer) SaveMetrics(savePath string) error

func (*HeadscaleInContainer) SaveProfile added in v0.22.2

func (t *HeadscaleInContainer) SaveProfile(savePath string) error

func (*HeadscaleInContainer) SendInterrupt added in v0.22.2

func (t *HeadscaleInContainer) SendInterrupt() error

func (*HeadscaleInContainer) SetNodeTags added in v0.28.0

func (t *HeadscaleInContainer) SetNodeTags(nodeID uint64, tags []string) error

SetNodeTags sets tags on a node via the headscale CLI. This simulates what the Tailscale admin console UI does - it calls the headscale SetTags API which is exposed via the CLI command: headscale nodes tag -i <id> -t <tags>.

func (*HeadscaleInContainer) SetPolicy added in v0.26.0

func (h *HeadscaleInContainer) SetPolicy(pol *policyv2.Policy) error

func (*HeadscaleInContainer) Shutdown

func (t *HeadscaleInContainer) Shutdown() (string, string, error)

Shutdown stops and cleans up the Headscale container.

func (*HeadscaleInContainer) WaitForRunning added in v0.23.0

func (t *HeadscaleInContainer) WaitForRunning() error

WaitForRunning blocks until the Headscale instance is ready to serve clients.

func (*HeadscaleInContainer) WriteFile

func (t *HeadscaleInContainer) WriteFile(path string, data []byte) error

WriteFile save file inside the Headscale container.

func (*HeadscaleInContainer) WriteLogs added in v0.24.0

func (t *HeadscaleInContainer) WriteLogs(stdout, stderr io.Writer) error

WriteLogs writes the current stdout/stderr log of the container to the given io.Writers.

type Option

type Option = func(c *HeadscaleInContainer)

Option represent optional settings that can be given to a Headscale instance.

func WithACLPolicy

func WithACLPolicy(acl *policyv2.Policy) Option

WithACLPolicy adds a hscontrol.ACLPolicy policy to the HeadscaleInContainer instance.

func WithCACert added in v0.24.0

func WithCACert(cert []byte) Option

WithCACert adds it to the trusted surtificate of the container.

func WithConfigEnv

func WithConfigEnv(configEnv map[string]string) Option

WithConfigEnv takes a map of environment variables that can be used to override Headscale configuration.

func WithCustomTLS added in v0.24.0

func WithCustomTLS(cert, key []byte) Option

WithCustomTLS uses the given certificates for the Headscale instance.

func WithDERPAsIP added in v0.27.0

func WithDERPAsIP() Option

WithDERPAsIP enables using IP address instead of hostname for DERP server. This is useful for integration tests where DNS resolution may be unreliable.

func WithDERPConfig added in v0.24.0

func WithDERPConfig(derpMap tailcfg.DERPMap) Option

WithDERPConfig configures Headscale use a custom DERP server only.

func WithEmbeddedDERPServerOnly added in v0.23.0

func WithEmbeddedDERPServerOnly() Option

WithEmbeddedDERPServerOnly configures Headscale to start and only use the embedded DERP server. It requires WithTLS and WithHostnameAsServerURL to be set.

func WithExtraPorts added in v0.22.2

func WithExtraPorts(ports []string) Option

WithExtraPorts exposes additional ports on the container (e.g. 3478/udp for STUN).

func WithFileInContainer added in v0.18.0

func WithFileInContainer(path string, contents []byte) Option

WithFileInContainer adds a file to the container at the given path.

func WithHostPortBindings added in v0.22.2

func WithHostPortBindings(bindings map[string][]string) Option

func WithHostname added in v0.24.0

func WithHostname(hostname string) Option

WithHostname sets the hostname of the Headscale instance.

func WithIPAllocationStrategy added in v0.23.0

func WithIPAllocationStrategy(strategy types.IPAllocationStrategy) Option

WithIPAllocationStrategy sets the tests IP Allocation strategy.

func WithPolicyMode added in v0.26.0

func WithPolicyMode(mode types.PolicyMode) Option

WithPolicy sets the policy mode for headscale.

func WithPort

func WithPort(port int) Option

WithPort sets the port on where to run Headscale.

func WithPostgres added in v0.23.0

func WithPostgres() Option

WithPostgres spins up a Postgres container and sets it as the main database.

func WithTLS

func WithTLS() Option

WithTLS creates certificates and enables HTTPS.

func WithTestName

func WithTestName(testName string) Option

WithTestName sets a name for the test, this will be reflected in the Docker container name.

func WithTimezone added in v0.23.0

func WithTimezone(timezone string) Option

func WithTuning added in v0.23.0

func WithTuning(batchTimeout time.Duration, mapSessionChanSize int) Option

WithTuning allows changing the tuning settings easily.

Jump to

Keyboard shortcuts

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