ether

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 17 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 ether manages the bus (the ether): an embedded NATS server, or a connection to an external cluster. The interface is the same for both modes - neither thrall nor lord can tell the difference, because both speak only NATS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientOptions

func ClientOptions(caPath, nkeySeed string) ([]nats.Option, error)

ClientOptions builds the nats options for a secured bus from credential paths: a CA the client verifies the server against and an nkey seed it authenticates with. An empty path adds no option, so an empty pair connects unsecured. Shared by the lord (via Config) and the operator CLI, so every client constructs the same options in one place.

Types

type Auth

type Auth struct {
	NkeySeed string `toml:"nkey_seed"`
}

Auth configures client authentication to an external bus. NkeySeed is the path to an nkey seed file the client signs the server nonce with. Empty = no auth.

type Config

type Config struct {
	Mode string `toml:"mode"` // "embedded" | "external"
	URL  string `toml:"url"`  // for external: "nats://a:4222,nats://b:4222"
	// StoreDir is the JetStream storage directory for the embedded server. Empty
	// (the default) uses an ephemeral temp dir removed on Stop; a fixed path keeps
	// the durable mailbox across a lord/process restart. Ignored in external mode.
	StoreDir string `toml:"store_dir"`
	TLS      TLS    `toml:"tls"`  // client-side transport security (external mode)
	Auth     Auth   `toml:"auth"` // client authentication (external mode)
	// Leaf, when present, makes the embedded server a leaf node of a central hub
	// (the spoke side of a hub-spoke topology). Valid only for embedded mode; nil =
	// a standalone embedded bus, as before.
	Leaf *Leaf `toml:"leaf"`
	// Security, when present, exposes the embedded server on the network with server-side
	// TLS and mandatory nkey authentication (the server side of the bus). Valid only for
	// embedded mode, and not together with a leaf (securing the leaf spoke is a later
	// increment). nil = today's behaviour: loopback bind, no auth. Unrelated to TLS/Auth
	// above, which are the client side (connecting out to an external bus).
	Security *Security `toml:"security"`
}

Config corresponds to the nats section in the manifest.

func (Config) ClientCredentials added in v0.9.0

func (c Config) ClientCredentials(role Role) (ca, nkeySeed string)

ClientCredentials returns the CA and nkey seed paths a client of the given role uses to reach this bus, from the right source for the mode: an external bus uses the client-side TLS/Auth fields; a secured embedded bus uses its own Security fields. In the least-privilege tier the seed is the role's own; in the simple tier (and external) role is immaterial - one shared identity. An unsecured bus returns empty paths. It is the one place the lord (its own connection as RoleLord, injecting RoleThrall into thralls) and the operator CLI (RoleOperator endpoint) derive credentials, so every client stays consistent with however the bus is secured.

func (Config) Validate added in v0.7.0

func (c Config) Validate() error

Validate rejects a semantically broken nats config. It runs after the manifest applies defaults (so an empty Mode has already become "embedded"), and is the single place the bus config's validity lives - the manifest validation calls it. A leaf makes sense only for the embedded spoke; the hub side is external, bring-your-own NATS config.

type Ether

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

Ether holds the running bus and the system connection for the lord and registry.

func Start

func Start(ctx context.Context, cfg Config, opts ...StartOption) (*Ether, error)

Start brings up an embedded NATS server (default), or connects to an external URL.

func (*Ether) Conn

func (e *Ether) Conn() *nats.Conn

Conn returns the system NATS connection (lord, registry, observability).

func (*Ether) Reload added in v0.9.0

func (e *Ether) Reload(cfg Config) error

Reload re-applies the secured embedded server's credentials without a restart: it rebuilds the server options from the current [nats.security] files - which the operator has replaced in place (a renewed TLS cert, a new nkey) - and hands them to the running server, keeping live connections up. The bind and storage are unchanged, so only the certificate and the authorized identities change; a structural change (a different listen address or role set) is not a reload and needs a restart. Meaningful only for a secured embedded bus.

func (*Ether) Stop

func (e *Ether) Stop()

Stop closes the connection and (in embedded mode) stops the server. An ephemeral store dir is removed; a persistent one (configured store_dir) is kept so the durable mailbox survives to the next start.

func (*Ether) URL

func (e *Ether) URL() string

URL returns the bus address; injected into thralls as AETHER_NATS_URL.

type Leaf added in v0.7.0

type Leaf struct {
	Remote string `toml:"remote"` // the hub's leafnode listener, e.g. "nats-leaf://hub.internal:7422"
	Site   string `toml:"site"`   // the account this node binds to = its isolation unit on the hub
	Domain string `toml:"domain"` // JetStream domain, unique per node (else the leaf's and hub's streams collide)
	// Credentials for the leaf link. User/Password suit a dev cluster (and may also be
	// embedded directly in Remote); Nkey is the path to an nkey seed file for production.
	User     string `toml:"user"`
	Password string `toml:"password"`
	Nkey     string `toml:"nkey"`
}

Leaf configures the embedded server as a NATS leaf node of a central hub. It binds this node's bus into a per-site account on the hub and gives its JetStream a per-node domain, closing the gap where an embedded bus could not be a spoke. aether owns only this spoke-side intent - which hub, which site, which JS domain, which credential; the hub side stays operator-authored NATS config (mode = "external").

type Role added in v0.9.0

type Role string

Role identifies which of the three least-privilege identities a client authenticates as. In the simple tier all three collapse onto the one shared seed; in the least-privilege tier each has its own seed and a role-scoped permission set on the server.

const (
	RoleLord     Role = "lord"     // the supervisor: full rights, incl. aether._lord.>
	RoleThrall   Role = "thrall"   // a worker: its data plane, but not the broad supervision control
	RoleOperator Role = "operator" // the CLI / dashboard: call/cast and observe, but not control
)

type Security added in v0.9.0

type Security struct {
	Listen  string `toml:"listen"`   // network bind, e.g. "0.0.0.0:4222"
	TLSCert string `toml:"tls_cert"` // path to the server certificate (PEM)
	TLSKey  string `toml:"tls_key"`  // path to the server private key (PEM)
	CA      string `toml:"ca"`       // path to the CA clients verify the server against (the lord distributes it)

	// Simple tier: one shared identity, full rights, no role separation.
	NkeySeed string `toml:"nkey_seed"`

	// Least-privilege tier: one nkey seed per role (all three required together, and exclusive
	// with NkeySeed). The recommended path - the role permissions are what enforce aether._lord.>
	// as node-local on a networked bus.
	LordNkey     string `toml:"lord_nkey"`
	ThrallNkey   string `toml:"thrall_nkey"`
	OperatorNkey string `toml:"operator_nkey"`
}

Security configures the embedded server for a network bind with server-side TLS and mandatory nkey authentication. Present = the bus is exposed on Listen, encrypted, and every client must authenticate; absent = the loopback, no-auth default. When present, all fields are required (no half-secured bus).

Authentication has two mutually exclusive shapes. NkeySeed is the *simple* tier: one shared identity with full rights (encrypted and authenticated, but no role separation). The per-role seeds (LordNkey / ThrallNkey / OperatorNkey, all three together) are the *least-privilege* tier: each of the lord, thralls and operator gets its own identity with a role-scoped permission set, so a thrall cannot drive supervision (see securedServerOptions). Set one shape or the other, never a mix. mTLS is a later opt-in.

type StartOption added in v0.7.0

type StartOption func(*startOptions)

StartOption tunes how the bus is brought up. Options carry runtime context the nats config alone does not - today the app name, which the leaf spoke exports as its data plane.

func WithApp added in v0.7.0

func WithApp(app string) StartOption

WithApp supplies the manifest's app name. It is required for an embedded leaf spoke (the export subject aether.<app>.> is otherwise undefined) and ignored by the other modes.

type TLS

type TLS struct {
	CA string `toml:"ca"`
}

TLS configures client-side transport security for an external bus. CA is the path to a PEM file used to verify the server's certificate (server TLS). Empty = no TLS.

Jump to

Keyboard shortcuts

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