server

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 37 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 server provides the takt server and its configuration.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDataDirectoryShared is returned when the data directory can be reached by
	// someone other than its owner.
	ErrDataDirectoryShared = errors.New("data directory is accessible to more than its owner")
	// ErrDataDirectoryInUse is returned when another server holds the data
	// directory.
	ErrDataDirectoryInUse = errors.New("data directory is in use by another takt server")
)
View Source
var (
	// ErrClientSecretReadable is returned when the OIDC client secret file can be
	// read by someone other than its owner.
	ErrClientSecretReadable = errors.New("oidc client secret file is readable by more than its owner")
)

Functions

func Run

func Run(ctx context.Context, config Config) error

Run starts the takt server using the given configuration and blocks until the context is cancelled or the server stops with an error.

Types

type AuthConfig added in v0.5.0

type AuthConfig struct {
	// OIDC settings. Absent means static tokens are the only
	// authentication.
	OIDC OIDCConfig `toml:"oidc"`
}

The AuthConfig type contains configuration for authenticating API callers. It hangs off the Config as a pointer because its presence is the setting: writing [auth] turns the layer on, even with nothing in the block, and an absent block means anything reaching the listener holds the whole API, exactly as before the layer existed.

func (*AuthConfig) OIDCEnabled added in v0.5.0

func (c *AuthConfig) OIDCEnabled() bool

OIDCEnabled reports whether OIDC logins are configured.

type Config

type Config struct {
	// The file this configuration was read from, empty when it was not read
	// from one. Not a setting: it is what LoadConfig records, so the server
	// knows where its own configuration lives.
	Source string `toml:"-"`
	// HTTP server settings.
	HTTP HTTPConfig `toml:"http"`
	// On-disk state settings.
	Data DataConfig `toml:"data"`
	// Docker daemon settings.
	Docker DockerConfig `toml:"docker"`
	// Settings for the exec runtime.
	Exec ExecConfig `toml:"exec"`
	// Reconciliation settings.
	Reconcile ReconcileConfig `toml:"reconcile"`
	// Settings for the workloads takt runs.
	Workload WorkloadConfig `toml:"workload"`
	// Secret storage settings.
	Secrets SecretsConfig `toml:"secrets"`
	// Authentication settings. The block's presence is what enables the
	// auth layer — nil means the block is absent and the network-boundary
	// model stands.
	Auth *AuthConfig `toml:"auth"`
	// Trace and log export settings.
	Telemetry TelemetryConfig `toml:"telemetry"`
	// Logging settings.
	Logging LoggingConfig `toml:"logging"`
}

The Config type contains the top-level configuration for the takt server.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config populated with sensible defaults, so that the server runs out of the box with no configuration file at all.

func LoadConfig

func LoadConfig(path string) (Config, error)

LoadConfig the configuration file at the specified path. The configuration file is expected in TOML format.

Values absent from the file keep their default, so a file only has to describe what it changes.

func (Config) ACLResetPath added in v0.5.0

func (c Config) ACLResetPath() string

ACLResetPath returns the file whose presence removes the recovery token at startup, so `takt acl init` works again.

Beside DatabasePath for the same reason: writing this file is a host-level act, and the operator performing it has the configuration and nothing else to go on.

func (Config) DatabasePath

func (c Config) DatabasePath() string

DatabasePath returns the SQLite database file inside the configured data directory.

On the configuration rather than beside the server that reads it, because the server is not the only thing that needs to find it. Restoring a node writes the database back, and it has the configuration and nothing else to go on. A second copy of this join would be a second definition of where a node keeps its state, and the two drifting apart puts the database somewhere the server does not look.

func (Config) KeysPath

func (c Config) KeysPath() string

KeysPath returns the directory holding the secret encryption keys.

Resolved here rather than defaulted in DefaultConfig, because the default sits inside the data directory and a configuration file may have moved that. A default computed before the file was read would point at the directory takt is not using.

func (Config) PrivatePaths added in v0.9.0

func (c Config) PrivatePaths() []string

PrivatePaths returns the paths on the host that hold the server's own secrets: the data directory, which holds the database, the keyring and every workload's mounted values, the configuration file, which may hold an OIDC client secret, the TLS private key, the OIDC client secret file and the docker credential file. An exec workload runs as the server's user, so these are what its confinement has to keep from it.

The configuration file rather than its directory. The directory is what holds the host's own files when the file sits in /etc directly, and denying it denied a workload every one of them.

The data directory is named whole, although a workload's own working directory, its volumes and the values it mounts sit beneath it. The confinement grants those by name, and a grant by name does not depend on the directory above it being granted. Without this entry a data directory placed under a system directory, or under an allowed path, is granted entry by entry with only the keyring left out.

func (*Config) ServedOverTLS added in v0.9.0

func (c *Config) ServedOverTLS() bool

ServedOverTLS reports whether the browser reaches this server over TLS: the server terminates it, or a reverse proxy in front does, which the operator says with behind-tls or by giving an https OIDC redirect URL. That decides whether a cookie may be marked Secure.

func (*Config) Validate

func (c *Config) Validate() error

Validate the configuration fields, resolving the data directory before anything reads it.

The directory is made absolute here rather than left as written. A relative one produces workloads that cannot start: Landlock is given the path of a workload's own directory and docker is given the path of a volume, and both refuse a path that is not absolute. The failure then surfaces as a workload that never converges, which says nothing about the configuration that caused it.

This is the ordinary case rather than an exotic one. The development configuration in the repository names ./data, and the fallback used when the home directory cannot be read is "data".

An empty directory is left alone so that the check below reports it as missing. Resolving it would silently turn it into the working directory.

func (Config) VolumesPath

func (c Config) VolumesPath() string

VolumesPath returns the directory holding every volume, one per identifier.

Beside DatabasePath for the same reason. A volume is found by the identifier it was assigned, so restoring a node has to report which of those directories are not there — and it cannot ask the service that owns the layout, because that service only exists once a server is running.

type DataConfig

type DataConfig struct {
	// The directory the SQLite database is stored in.
	Directory string `toml:"directory"`
}

The DataConfig type contains configuration for the server's on-disk state.

type DockerConfig

type DockerConfig struct {
	// The daemon to connect to. Empty uses the environment's configuration,
	// which falls back to the local socket.
	Host string `toml:"host"`
	// The docker credential file registry credentials are resolved from when a
	// workload's image is pulled.
	//
	// Empty reads docker's own default location, so a docker login by the user
	// running the server just works. Set it when that default holds nothing —
	// notably when takt itself runs in a container. The file is read when a
	// pull happens rather than at startup, and an absent file means anonymous
	// pulls.
	ConfigFile string `toml:"config-file"`
	// Whether the images no workload names and no container uses are removed.
	// Images only: a container, a volume, a network and the build cache are
	// never touched.
	//
	// On by default, because the daemon's images are takt's to reap the way
	// host ports are its to allocate, and a disk filling with the images of
	// every tag ever bumped is the failure that goes unnoticed for months.
	Prune bool `toml:"prune"`
	// How long an image is left alone after nothing references it, so that a
	// tag bumped and reverted within the delay does not pull the image again.
	PruneDelay time.Duration `toml:"prune-delay"`
	// How often the server asks what each pull-always or followed workload's
	// tag resolves to, reporting the ones behind their tag and moving the
	// followed ones on. Zero, the default, never asks: a check is a manifest
	// request to the registry, and Docker Hub counts those against its pull
	// rate limit, so turning it on is the operator's decision.
	DigestInterval time.Duration `toml:"digest-interval"`
}

The DockerConfig type contains configuration for talking to the Docker daemon.

type ExecConfig

type ExecConfig struct {
	// Extra paths every exec workload may read.
	//
	// An exec workload is confined to its own directory, the volumes and values it
	// mounts, and the host's own system directories. That covers a command
	// installed the ordinary way and not one whose runtime lives elsewhere — a
	// language installed under a home directory, or a nix store. Name those here.
	//
	// Read-only, so this opens what a workload may read rather than what it may
	// change. It is host configuration rather than a manifest field on purpose: a
	// manifest arrives from anything holding a write grant, so a workload able to
	// widen its own confinement would undo it. Which paths are opened is a
	// decision the operator who administers the host makes.
	//
	// Every path must be absolute. A path that is not there is ignored, so a list
	// covering several hosts does not have to match each one exactly.
	AllowPaths []string `toml:"allow-paths"`
}

The ExecConfig type contains configuration for the exec runtime.

type HTTPConfig

type HTTPConfig struct {
	// The address the HTTP server binds to, in host:port form.
	Address string `toml:"address"`
	// The host names a request may name, beyond an address literal and
	// "localhost", which are always accepted.
	//
	// A request naming anything else is refused. Reaching this API is enough to
	// run code on the host, and a browser will send a request to a loopback
	// address on behalf of any page the operator visited — so the name a request
	// asks for is checked rather than assumed to be takt's own. Set this to the
	// name a reverse proxy in front of takt serves.
	Hosts []string `toml:"hosts"`
	// The PEM certificate file the server presents when it serves TLS. Set
	// together with tls-key, or not at all. The pair is reread when this
	// file changes, so a renewal does not need a restart.
	TLSCert string `toml:"tls-cert"`
	// The PEM private key for tls-cert. The file must be readable only by
	// the user running the server.
	TLSKey string `toml:"tls-key"`
	// Whether a reverse proxy in front of this server terminates TLS. The
	// server itself speaks plain HTTP on a loopback listener, but the
	// browser reaches it over TLS, so a session cookie is marked Secure
	// and every response carries Strict-Transport-Security.
	//
	// A setting rather than something read from a forwarded header,
	// because a header is what any client on the loopback network can
	// send, and whether the browser's connection is encrypted is a fact
	// about the deployment rather than the request.
	BehindTLS bool `toml:"behind-tls"`
	// The most header values a request may carry, counted across every
	// header. A request carrying more is refused before a handler sees it.
	//
	// Nothing the API accepts needs many: a client sends a handful, and a
	// browser a few dozen. The bound is what stops a request from spending
	// the server's memory on headers nothing reads.
	MaxHeaderValues int `toml:"max-header-values"`
}

The HTTPConfig type contains configuration for the HTTP listener.

func (HTTPConfig) TLSEnabled

func (c HTTPConfig) TLSEnabled() bool

TLSEnabled reports whether the server terminates TLS itself.

type LoggingConfig

type LoggingConfig struct {
	// The minimum level to emit. One of "debug", "info", "warn", "error".
	Level string `toml:"level"`
}

The LoggingConfig type contains configuration for application logging.

type OIDCConfig added in v0.5.0

type OIDCConfig struct {
	// The issuer `takt auth login` and the UI run the authorization code
	// flow against, as a URL. Its presence is what enables OIDC.
	Issuer string `toml:"issuer"`
	// The client identifier registered with the issuer.
	ClientID string `toml:"client-id"`
	// The client secret, when the issuer treats takt as a confidential
	// client. Empty for a public client using PKCE alone.
	ClientSecret string `toml:"client-secret"`
	// A file holding the client secret, as an alternative to writing it
	// in client-secret. A configuration kept in a repository beside the
	// manifests then carries a path rather than the secret. The file must
	// be readable only by the user running the server, the same rule as
	// tls-key. Set one of the two, not both.
	ClientSecretFile string `toml:"client-secret-file"`
	// The URL browsers reach this server by, such as
	// "https://takt.example.com". Its presence is what enables the UI's
	// login redirect, whose callback the issuer must be able to send the
	// browser back to. The CLI's loopback flow works without it.
	RedirectURL string `toml:"redirect-url"`
	// The scopes a login requests. Defaults to "openid", "email" and
	// "profile". Add whatever scope the issuer needs before it includes
	// the claim the policy's groupsClaim reads, such as "groups".
	Scopes []string `toml:"scopes"`
}

The OIDCConfig type contains configuration for exchanging OIDC identities for tokens.

func (OIDCConfig) ReadClientSecret added in v0.12.0

func (c OIDCConfig) ReadClientSecret() (string, error)

ReadClientSecret returns the client secret, from client-secret-file when it is set and from client-secret otherwise. A file whose mode lets anyone but its owner read it is refused rather than narrowed, as the TLS key and the keyring are: whoever could read it already had the chance.

Read once at startup rather than on each exchange. The issuer holds the same secret, so changing it is a change on both sides and a restart beside it is no extra step.

type ReconcileConfig

type ReconcileConfig struct {
	// How often a full reconciliation pass runs regardless of driver events.
	// Events make convergence prompt. This bounds how long a missed one can
	// go unnoticed.
	Interval time.Duration `toml:"interval"`
	// How long a workload's first start is held for the instance of a workload
	// it references to pass its health check, before it is started anyway.
	//
	// A reader started beside a slow database would otherwise start, fail to
	// connect, exit and be restarted on the paced backoff until the database
	// answered, and a deployment doing what it was told would look broken.
	// Zero disables the hold.
	ReadinessWait time.Duration `toml:"readiness-wait"`
}

The ReconcileConfig type contains configuration for the reconciliation loop.

type SecretsConfig

type SecretsConfig struct {
	// The directory holding the keys a secret's value is encrypted under.
	//
	// A key is generated on first start if the directory is empty. Anything that
	// can read this directory can read every secret takt holds, so it is created
	// readable only by the user running the server — and it belongs on a backup,
	// because a secret sealed under a key that is gone cannot be recovered.
	//
	// A directory rather than a file because rotating a key writes the new one
	// before anything points at it. Each key is named by an identifier the
	// database records, so which one is current is something the database
	// answers.
	//
	// Empty puts the keyring beside the database, in the data directory.
	Keys string `toml:"keys"`
}

The SecretsConfig type contains configuration for the secrets takt holds.

type TelemetryConfig

type TelemetryConfig struct {
	// The OTLP endpoint traces and logs are exported to over HTTP, as a URL
	// such as "http://collector.internal:4318". The scheme decides whether
	// the connection uses TLS. Empty exports neither, which is the default.
	//
	// Everything beyond the endpoint — headers, timeouts, sampling, resource
	// attributes — is read from the standard OTEL_* environment variables
	// the SDK already honours, rather than repeated here.
	OTLPEndpoint string `toml:"otlp-endpoint"`

	// Replaces the OTLP span exporter when set. Never read from the
	// configuration file. Tests use it to write spans somewhere they can
	// read.
	SpanExporter sdktrace.SpanExporter `toml:"-"`
	// Replaces the OTLP log exporter when set, under the same rules as
	// SpanExporter.
	LogExporter sdklog.Exporter `toml:"-"`
}

The TelemetryConfig type contains configuration for exporting traces and logs.

Metrics need none of this: they are always collected and served by the /api/v1/system/metrics endpoint.

type WorkloadConfig

type WorkloadConfig struct {
	// The address a workload's host ports are published on.
	//
	// Every interface by default. A published port is one something has to
	// reach, and the things that reach it include the other workloads on this
	// host: a container cannot dial a port published on loopback, since loopback
	// inside a container is its own. Name an interface's address to restrict
	// what a workload is exposed to.
	//
	// This is not the API's address, which stays on loopback. Reaching the API
	// is enough to run code on the host, where reaching a workload's port only
	// reaches what that workload serves.
	//
	// This applies to a port takt publishes on a workload's behalf, which means a
	// container. An exec workload binds its port itself, so what it listens on is
	// the process's business and takt has nothing to say about it.
	Bind string `toml:"bind"`
	// Host paths a workload may name in a path mount, as absolute prefixes.
	// A path is accepted when it is one of these or sits beneath one. A
	// prefix ending in ":ro" is granted for reading only, so a mount beneath
	// it is accepted only when it says readOnly: true. The most specific
	// prefix decides, so "/:ro" beside "/mnt/media" opens the whole host for
	// observation without opening it for writing.
	//
	// Empty refuses every path mount, which is the default: a path mount
	// reaches outside takt-managed state, so it is a sandbox escape by
	// design. It is host configuration rather than a manifest field for the
	// reason the exec allow-paths list is: a manifest arrives from anything
	// holding a write grant, so a workload able to widen its own reach
	// would undo the gate. Which paths are opened is a decision the
	// operator who administers the host makes.
	AllowHostPaths []string `toml:"allow-host-paths"`
	// The lowest host port that may be allocated.
	MinPort int `toml:"min-port"`
	// The highest host port that may be allocated.
	MaxPort int `toml:"max-port"`
	// The most events kept for one workload. The oldest are removed as new ones
	// arrive, so this bounds what the table can grow to rather than how long an
	// event survives.
	//
	// The default keeps the card an operator reads and little else. Raise it on a
	// host where a workload's history is worth more than the rows it costs.
	MaxEvents int `toml:"max-events"`
}

The WorkloadConfig type contains configuration for the workloads takt runs: the address their host ports are published on, and the range it allocates those ports from.

func (WorkloadConfig) Address

func (c WorkloadConfig) Address() (string, error)

Address returns the address a workload dials to reach another workload's published ports.

The bind address answers this whenever it names an interface: that is where the ports are published, and an operator who wrote one has already said which interface they meant. The unspecified address is the exception. It publishes on every interface and names none, and nothing can dial it — a process that tried would reach its own loopback rather than the host.

So the unspecified address resolves to the address of the interface carrying the default route, which is the one anything on this host would reach the host by. A host with no route out has no such address, and loopback comes back along with the reason: an exec workload still reaches its neighbours there, and a container was never going to.

Directories

Path Synopsis
Package api provides the HTTP API surface of the takt server.
Package api provides the HTTP API surface of the takt server.
Package auth provides the identity a request carries and the tokens that prove it.
Package auth provides the identity a request carries and the tokens that prove it.
Package certificate holds the TLS certificate the server presents and rereads it from disk when the certificate file changes, so a renewal does not need a restart.
Package certificate holds the TLS certificate the server presents and rereads it from disk when the certificate file changes, so a renewal does not need a restart.
Package database provides the SQLite-backed persistence layer for the takt server.
Package database provides the SQLite-backed persistence layer for the takt server.
Package driver defines the vocabulary shared between the takt server and the runtimes it can run workloads on.
Package driver defines the vocabulary shared between the takt server and the runtimes it can run workloads on.
docker
Package docker provides the driver that runs takt workloads as Docker containers.
Package docker provides the driver that runs takt workloads as Docker containers.
exec
Package exec provides the driver that runs workloads as processes on the host.
Package exec provides the driver that runs workloads as processes on the host.
Package event names the things the server records about a workload while converging it.
Package event names the things the server records about a workload while converging it.
Package health provides checking of whether a workload is working, as distinct from whether its runtime reports it started.
Package health provides checking of whether a workload is working, as distinct from whether its runtime reports it started.
Package job provides running of the work the server does on its own schedule, as distinct from the work it does in answer to a request or a change.
Package job provides running of the work the server does on its own schedule, as distinct from the work it does in answer to a request or a change.
Package middleware provides the HTTP middleware the server puts in front of its API and web UI.
Package middleware provides the HTTP middleware the server puts in front of its API and web UI.
Package mount materialises the secrets, variables and tokens a workload mounts as files on the host, and owns the directories holding them.
Package mount materialises the secrets, variables and tokens a workload mounts as files on the host, and owns the directories holding them.
Package port provides allocation of host ports to workloads, and settles a workload's ports on the ones it is reached at.
Package port provides allocation of host ports to workloads, and settles a workload's ports on the ones it is reached at.
Package reconciler provides the control loop that drives the running state of the node towards the desired state held in the database.
Package reconciler provides the control loop that drives the running state of the node towards the desired state held in the database.
Package resolve turns the references in a workload's specification into the values they name: a secret's plaintext, a variable's value, or the address another workload is reached at.
Package resolve turns the references in a workload's specification into the values they name: a secret's plaintext, a variable's value, or the address another workload is reached at.
Package secret provides the encryption takt stores a secret's value under.
Package secret provides the encryption takt stores a secret's value under.
Package service provides the domain orchestration layer for the takt server.
Package service provides the domain orchestration layer for the takt server.
Package specdiff provides the comparison of two workload specifications that tells an operator what an apply would change.
Package specdiff provides the comparison of two workload specifications that tells an operator what an apply would change.
Package spechash provides the hash takt computes over a workload's specification.
Package spechash provides the hash takt computes over a workload's specification.
Package state derives what a workload is doing overall from the instances the driver reports for it.
Package state derives what a workload is doing overall from the instances the driver reports for it.
Package telemetry provides the OpenTelemetry providers the server runs with.
Package telemetry provides the OpenTelemetry providers the server runs with.

Jump to

Keyboard shortcuts

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