Documentation
¶
Overview ¶
Package ctl is the local admin socket: a small HTTP API on a Unix socket in the data directory, so that `beacon token …`, `machine …`, `ssh …`, `config …` and `drill …` work against the running service, which holds the database lock.
Only processes of the service's own user (or root) can connect: the socket is mode 0600 in the data directory, and on Linux and macOS the peer's user id is checked on every connection.
Index ¶
- Constants
- Variables
- func ConfigHandler(c Config) http.Handler
- func ConnContext(ctx context.Context, c net.Conn) context.Context
- func CurrentUser() string
- func Dial(ctx context.Context, path string) (*Client, Info, error)
- func DrillHandler(s DrillStore, ...) http.Handler
- func Handler(s Service, active func(location string) error, m Machines) http.Handler
- func Listen(path string) (net.Listener, error)
- func ParseSSHKey(line string) (store.SSHKey, error)
- func ParseTTL(s string) (time.Duration, error)
- func Path(dataDir string) string
- func PeopleHandler(p People) http.Handler
- func SettingsHandler(s Settings) http.Handler
- func SilenceHandler(s Silences) http.Handler
- type AgentRequest
- type ClaimRequest
- type Client
- func (c *Client) AddAgent(ctx context.Context, in AgentRequest) (bridge.AgentCreated, error)
- func (c *Client) AddMachine(ctx context.Context, in sshgate.MachineInput) (sshgate.Added, error)
- func (c *Client) AddSSHKey(ctx context.Context, token, key string) (TokenInfo, error)
- func (c *Client) Agents(ctx context.Context) ([]bridge.AgentView, error)
- func (c *Client) CheckConfig(ctx context.Context) (ConfigState, error)
- func (c *Client) Claim(ctx context.Context, in ClaimRequest) (bridge.AgentView, error)
- func (c *Client) ConfigHistory(ctx context.Context, limit int) ([]store.ConfigChange, error)
- func (c *Client) CreateSilence(ctx context.Context, in SilenceRequest) (SilenceResponse, error)
- func (c *Client) CreateToken(ctx context.Context, in TokenRequest) (TokenResponse, error)
- func (c *Client) Drill(ctx context.Context, duration string) (DrillState, error)
- func (c *Client) DrillStatus(ctx context.Context) (DrillState, error)
- func (c *Client) Enroll(ctx context.Context, in EnrollRequest) (TokenResponse, error)
- func (c *Client) ExpireSilence(ctx context.Context, id string) error
- func (c *Client) ExportConfig(ctx context.Context) (Export, error)
- func (c *Client) GetSettings(ctx context.Context) (config.SettingsView, error)
- func (c *Client) ImportConfig(ctx context.Context, in ImportRequest) (store.ConfigChange, error)
- func (c *Client) Invite(ctx context.Context, in InviteRequest) (bridge.LinkView, error)
- func (c *Client) ListSilences(ctx context.Context) ([]alertmanager.Silence, error)
- func (c *Client) Machines(ctx context.Context) (sshgate.Machines, error)
- func (c *Client) PauseSSH(ctx context.Context, paused bool) (SSHState, error)
- func (c *Client) RemoveAgent(ctx context.Context, name string) error
- func (c *Client) RemoveMachine(ctx context.Context, name string) error
- func (c *Client) RemoveSSHKey(ctx context.Context, token, fingerprint string) (TokenInfo, error)
- func (c *Client) ResetUser(ctx context.Context, name string) (bridge.LinkView, error)
- func (c *Client) RevertConfig(ctx context.Context, in RevertRequest) (store.ConfigChange, error)
- func (c *Client) RevokeToken(ctx context.Context, name string) error
- func (c *Client) RulesToken(ctx context.Context, rotate bool) (string, error)
- func (c *Client) SSH(ctx context.Context) (SSHState, error)
- func (c *Client) SetAgentMachines(ctx context.Context, agent string, machines []string) (bridge.AgentView, error)
- func (c *Client) SetMachineConnector(ctx context.Context, name, key string) (sshgate.MachineView, error)
- func (c *Client) SetTokenMachines(ctx context.Context, token string, machines []string) (TokenInfo, error)
- func (c *Client) SetUserMachines(ctx context.Context, username string, machines []string) (bridge.UserView, error)
- func (c *Client) SetupLink(ctx context.Context) (bridge.LinkView, error)
- func (c *Client) Tokens(ctx context.Context) ([]TokenInfo, error)
- func (c *Client) UpdateSettings(ctx context.Context, in config.SettingsInput) (config.SettingsView, error)
- func (c *Client) UpdateUser(ctx context.Context, name string, ch bridge.UserChange) (bridge.UserView, error)
- func (c *Client) Users(ctx context.Context) (UsersResponse, error)
- type Config
- type ConfigState
- type ConnectorKeyRequest
- type DrillRequest
- type DrillState
- type DrillStore
- type EnrollRequest
- type Export
- type ImportRequest
- type Info
- type InviteRequest
- type Machines
- type MachinesRequest
- type PauseRequest
- type People
- type RevertRequest
- type RulesTokenResponse
- type SSHKeyRequest
- type SSHState
- type Service
- type Settings
- type SilenceRequest
- type SilenceResponse
- type Silences
- type TokenInfo
- type TokenRequest
- type TokenResponse
- type UsersResponse
Constants ¶
const DrillKey = "drill"
DrillKey is where the drill's end is stored.
const EnrollTTL = 2 * 365 * 24 * time.Hour
EnrollTTL is how long a machine token lasts. A probe stops being able to write when its machine expires (the gateway checks the catalogue), so the token itself may outlive that.
const MaxDrill = 2 * time.Hour
MaxDrill is the longest a drill may run.
const MaxImport = 16 << 20
MaxImport is the largest import the socket takes.
const UserHeader = "X-Status-User"
UserHeader carries the name of the person running the command, as the client sees it. The audit log names the user the operating system says connected, where it can tell (cliActor).
Variables ¶
var EnrollKinds = map[string]string{
"probe": "probe:write",
"host": "host:write",
"heartbeat": "heartbeat:write",
"rules": "alerts:send",
}
EnrollKinds map what is enrolled to the scope of its token.
Functions ¶
func ConfigHandler ¶
ConfigHandler serves the configuration's routes under /v1/config/, beside Handler.
func ConnContext ¶
ConnContext gives each request on the socket the peer's user id, where the listener learnt it, so that the audit log names whoever runs a command by who they are rather than by what the client says. The socket's http.Server takes it as its ConnContext.
func CurrentUser ¶
func CurrentUser() string
CurrentUser is the name recorded in the audit log for commands run from this process.
func DrillHandler ¶
func DrillHandler(s DrillStore, record func(ctx context.Context, until time.Time, by string) error) http.Handler
DrillHandler serves /v1/drill, beside Handler. record, when not nil, records a drill starting (until is when it ends) or a running drill ending (until is zero) as a change event, so that the evidence of the alert a drill causes says it is one, and until when.
func Handler ¶
Handler serves the socket's API. active reports whether a probe location exists and its machine has not expired; nil accepts any location. m is the SSH channel, nil when it is off.
func Listen ¶
Listen opens the socket at path. A socket already there was left by a service that stopped (the caller holds the database lock, so no other service can be running); it is replaced. Anything else at path is an error and is left alone.
func ParseSSHKey ¶
ParseSSHKey reads an authorized_keys line into what a token keeps.
func PeopleHandler ¶
PeopleHandler serves /v1/setup, /v1/users, /v1/agents and /v1/claims, beside Handler.
func SettingsHandler ¶
SettingsHandler serves /v1/settings and /v1/settings/rules-token on the admin socket.
func SilenceHandler ¶
SilenceHandler serves the silences' routes under /v1/silences, beside Handler.
Types ¶
type AgentRequest ¶
type AgentRequest struct {
Name string `json:"name"`
Owner string `json:"owner"`
Preset string `json:"preset,omitempty"`
Scopes []string `json:"scopes,omitempty"`
Machines []string `json:"machines,omitempty"`
SSHKeys []string `json:"ssh_keys,omitempty"`
TTL string `json:"ttl"`
}
AgentRequest makes an agent for Owner with a token lasting TTL (365d, 720h). Machines is its machine access as the command line writes it (store.ParseMachineList); none when empty.
type ClaimRequest ¶
type ClaimRequest struct {
Token string `json:"token"`
Owner string `json:"owner"`
Agent string `json:"agent,omitempty"`
Preset string `json:"preset,omitempty"`
}
ClaimRequest makes a legacy token an agent of Owner.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the running service over its socket.
func (*Client) AddAgent ¶
func (c *Client) AddAgent(ctx context.Context, in AgentRequest) (bridge.AgentCreated, error)
AddAgent makes an agent and its first token.
func (*Client) AddMachine ¶
AddMachine adds a machine, pinning its host key.
func (*Client) CheckConfig ¶
func (c *Client) CheckConfig(ctx context.Context) (ConfigState, error)
CheckConfig reports whether the running service's configuration passes its checks.
func (*Client) ConfigHistory ¶
ConfigHistory lists the latest changes to the configuration.
func (*Client) CreateSilence ¶
func (c *Client) CreateSilence(ctx context.Context, in SilenceRequest) (SilenceResponse, error)
CreateSilence silences an alert group or every alert matching the request's matchers.
func (*Client) CreateToken ¶
func (c *Client) CreateToken(ctx context.Context, in TokenRequest) (TokenResponse, error)
CreateToken creates a token.
func (*Client) DrillStatus ¶
func (c *Client) DrillStatus(ctx context.Context) (DrillState, error)
DrillStatus reports the drill.
func (*Client) Enroll ¶
func (c *Client) Enroll(ctx context.Context, in EnrollRequest) (TokenResponse, error)
Enroll gives a machine its gateway token.
func (*Client) ExpireSilence ¶
ExpireSilence ends a silence now.
func (*Client) ExportConfig ¶
ExportConfig fetches the configuration in force as files.
func (*Client) GetSettings ¶
GetSettings fetches the redacted system settings from the running service.
func (*Client) ImportConfig ¶
func (c *Client) ImportConfig(ctx context.Context, in ImportRequest) (store.ConfigChange, error)
ImportConfig imports files into the running service's configuration.
func (*Client) ListSilences ¶
ListSilences lists the silences, active and pending first as the bridge sorts them.
func (*Client) RemoveAgent ¶
RemoveAgent deletes an agent with its credentials.
func (*Client) RemoveMachine ¶
RemoveMachine forgets a machine.
func (*Client) RemoveSSHKey ¶
RemoveSSHKey takes a key, by its fingerprint, from a token.
func (*Client) RevertConfig ¶
func (c *Client) RevertConfig(ctx context.Context, in RevertRequest) (store.ConfigChange, error)
RevertConfig undoes one change.
func (*Client) RevokeToken ¶
RevokeToken deletes a token.
func (*Client) RulesToken ¶
RulesToken reads or rotates the rule engine's bearer token over the admin socket.
func (*Client) SetAgentMachines ¶
func (c *Client) SetAgentMachines(ctx context.Context, agent string, machines []string) (bridge.AgentView, error)
SetAgentMachines sets the machines an agent reaches, as the command line writes them (store.ParseMachineList): all, or names, each with @END optionally; none when empty.
func (*Client) SetMachineConnector ¶
func (c *Client) SetMachineConnector(ctx context.Context, name, key string) (sshgate.MachineView, error)
SetMachineConnector sets or changes the key a machine behind NAT connects out with.
func (*Client) SetTokenMachines ¶
func (c *Client) SetTokenMachines(ctx context.Context, token string, machines []string) (TokenInfo, error)
SetTokenMachines sets the machines a token reaches, as the command line writes them (store.ParseMachineList): all, or names; none when empty.
func (*Client) SetUserMachines ¶
func (c *Client) SetUserMachines(ctx context.Context, username string, machines []string) (bridge.UserView, error)
SetUserMachines names the critical machines a person who is not an owner reaches (none: no more).
func (*Client) UpdateSettings ¶
func (c *Client) UpdateSettings(ctx context.Context, in config.SettingsInput) (config.SettingsView, error)
UpdateSettings updates system settings on the running service.
type Config ¶
type Config interface {
Import(ctx context.Context, who configdb.Actor, f configdb.Files, note string, dryRun bool) (store.ConfigChange, error)
Export() (configdb.Files, int64, error)
History(f configdb.HistoryFilter) ([]store.ConfigChange, error)
Revert(ctx context.Context, who configdb.Actor, version int64, note string) (store.ConfigChange, error)
Check() error
Warnings() []string
Version() int64
Summary() string
}
Config is the configuration Beacon holds, as the socket serves it for `beacon config …`.
type ConfigState ¶
type ConfigState struct {
Version int64 `json:"version"`
Summary string `json:"summary"`
Problem string `json:"problem,omitempty"`
Warnings []string `json:"warnings,omitempty"`
}
ConfigState is what check-config reports of the running service's configuration. Warnings name what it refers to that Beacon does not know (a heartbeat's machine not enrolled), which is no problem.
type ConnectorKeyRequest ¶
type ConnectorKeyRequest struct {
Key string `json:"key"`
}
ConnectorKeyRequest sets the key a machine behind NAT connects out with (an authorized_keys line).
type DrillRequest ¶
type DrillRequest struct {
Duration string `json:"duration"`
}
DrillRequest starts a drill for a while, or ends it ("off").
type DrillState ¶
type DrillState struct {
Until time.Time `json:"until,omitzero"`
Run string `json:"run,omitempty"`
Observed []string `json:"observed_locations,omitempty"`
}
DrillState says until when the drill check fails.
type DrillStore ¶
type DrillStore interface {
SetDrill(now, until time.Time, by, detail string) (exercise.Run, bool, error)
DrillRun() exercise.Run
DrillObservedLocations(run string) []string
}
DrillStore keeps the drill's end and the audit log.
type EnrollRequest ¶
type EnrollRequest struct {
Kind string `json:"kind"` // probe, host or heartbeat
Subject string `json:"subject"` // the location id, host name or sender name
Rotate bool `json:"rotate,omitempty"`
}
EnrollRequest gives a machine its gateway token: a probe location, a host, or a heartbeat sender. An enrolled machine is enrolled again only with Rotate, which replaces its old token with the new one at once: the old token works until the new one is made and recorded.
type ImportRequest ¶
type ImportRequest struct {
Files configdb.Files `json:"files"`
Note string `json:"note,omitempty"`
DryRun bool `json:"dry_run,omitempty"`
}
ImportRequest imports files (paths as configdb.Files has them), or with DryRun says what it would change.
type Info ¶
type Info struct {
Version string `json:"version"`
}
Info describes the running service.
type InviteRequest ¶
InviteRequest invites someone with a role.
type Machines ¶
type Machines interface {
Add(ctx context.Context, who sshgate.Actor, in sshgate.MachineInput) (sshgate.Added, error)
Remove(ctx context.Context, who sshgate.Actor, name string) error
List(who sshgate.Actor, address string) (sshgate.Machines, error)
SetPaused(ctx context.Context, who sshgate.Actor, paused bool) error
PausedSince() time.Time
CAPublicKey() string
HostKey() string
SetConnector(ctx context.Context, who sshgate.Actor, name, key string) (sshgate.MachineView, error)
// Recheck closes what is open on the channel for whoever may no longer reach it.
Recheck() int
}
Machines is the SSH channel as the socket serves it.
type MachinesRequest ¶
type MachinesRequest struct {
Machines []string `json:"machines"`
}
MachinesRequest sets the machines a token reaches; empty means all.
type PauseRequest ¶
type PauseRequest struct {
Paused bool `json:"paused"`
}
PauseRequest pauses or resumes agents' access to machines.
type People ¶
type People interface {
SetupLink(via string) (bridge.LinkView, error)
Users(who bridge.Actor) ([]bridge.UserView, []bridge.LinkView, error)
Invite(ctx context.Context, who bridge.Actor, role, note string) (bridge.LinkView, error)
UpdateUser(ctx context.Context, who bridge.Actor, username string, ch bridge.UserChange) (bridge.UserView, error)
ResetLink(ctx context.Context, who bridge.Actor, username string) (bridge.LinkView, error)
Agents(who bridge.Actor, owner string) ([]bridge.AgentView, error)
CreateAgent(ctx context.Context, who bridge.Actor, in bridge.AgentInput) (bridge.AgentCreated, error)
DeleteAgent(ctx context.Context, who bridge.Actor, name string) error
ClaimToken(ctx context.Context, who bridge.Actor, token, owner, agent, preset string) (bridge.AgentView, error)
UpdateAgent(ctx context.Context, who bridge.Actor, name string, up bridge.AgentUpdate) (bridge.AgentView, error)
SetCriticalMachines(ctx context.Context, who bridge.Actor, username string, named store.MachineAccess) (bridge.UserView, error)
}
People is the bridge as the socket serves it for `beacon setup`, `beacon user …`, `beacon agent …` and `beacon token claim`: the methods the console, the API and MCP call, so that what the command line does is audited and echoed like theirs. The command line on the host may do everything an owner may.
type RevertRequest ¶
RevertRequest undoes the change that made Version.
type RulesTokenResponse ¶
type RulesTokenResponse struct {
Token string `json:"token"`
}
RulesTokenResponse carries the rule engine's bearer token over the local Unix admin socket.
type SSHKeyRequest ¶
type SSHKeyRequest struct {
Key string `json:"key"`
}
SSHKeyRequest gives a token a public key for the SSH channel (an authorized_keys line).
type SSHState ¶
type SSHState struct {
Enabled bool `json:"enabled"`
PausedSince time.Time `json:"paused_since,omitzero"`
HostKey string `json:"host_key,omitempty"`
TrustedUserCAKey string `json:"trusted_user_ca_key,omitempty"`
}
SSHState is the channel's state for `beacon ssh status`.
type Service ¶
type Service interface {
CreateToken(name string, scopes []string, ttl time.Duration, by string) (string, store.Token, error)
CreateSubjectToken(name, subject string, scopes []string, ttl time.Duration, by string) (string, store.Token, error)
Tokens() []store.Token
UpdateToken(name string, change func(*store.Token) error) (store.Token, error)
UpdateTokenRecorded(name string, change func(*store.Token) error, record store.Record[store.Token]) (store.Token, error)
AddTokenSSHKey(name string, k store.SSHKey) (store.Token, error)
AddTokenSSHKeyRecorded(name string, k store.SSHKey, record store.Record[store.Token]) (store.Token, error)
CreateSubjectTokenRecorded(name, subject string, scopes []string, ttl time.Duration, by string, replace bool,
record func(old *store.Token, t store.Token) []store.AuditEntry) (string, store.Token, error)
RevokeToken(name string) error
Audit(e store.AuditEntry) error
SetTime(key string, t time.Time) error
Time(key string) time.Time
CriticalMachines() map[string]bool
}
Service is what the socket serves.
type Settings ¶
type Settings interface {
View() config.SettingsView
Update(ctx context.Context, actor, via string, in config.SettingsInput) (*config.Config, config.SettingsView, error)
RulesToken() string
RotateRulesToken(ctx context.Context, actor, via string) (string, error)
}
Settings is what the admin socket needs from config.Manager.
type SilenceRequest ¶
type SilenceRequest struct {
Alert string `json:"alert,omitempty"`
Matchers map[string]string `json:"matchers,omitempty"`
Duration string `json:"duration"`
Comment string `json:"comment"`
}
SilenceRequest creates a silence for one firing alert group (Alert, its id) or for every alert whose labels equal all of Matchers; one of the two. Duration is like 4h, at most 24h; Comment says why.
type SilenceResponse ¶
type SilenceResponse struct {
Silence alertmanager.Silence `json:"silence"`
Group *bridge.GroupView `json:"group,omitempty"`
}
SilenceResponse is the silence made and, when it was made for one alert group, that group.
type Silences ¶
type Silences interface {
Silence(ctx context.Context, id string, d time.Duration, who bridge.Actor, comment string) (bridge.GroupView, error)
SilenceLabels(ctx context.Context, labels map[string]string, d time.Duration, who bridge.Actor, comment string) (alertmanager.Silence, error)
ExpireSilence(ctx context.Context, id string, who bridge.Actor) error
Silences(ctx context.Context) ([]alertmanager.Silence, error)
}
Silences is the bridge as the socket serves it for `beacon silence …`: the methods the API and MCP call, so that a silence made on the command line is audited and echoed like theirs.
type TokenInfo ¶
type TokenInfo struct {
Name string `json:"name"`
Scopes []string `json:"scopes"`
Subject string `json:"subject"`
Created time.Time `json:"created"`
CreatedBy string `json:"created_by"`
Expires time.Time `json:"expires"`
SSHKeys []string `json:"ssh_keys,omitempty"`
Lifetime string `json:"lifetime,omitempty"`
Renewed time.Time `json:"renewed,omitzero"`
Agent string `json:"agent,omitempty"` // the agent whose token it is; its scopes and machines are the agent's
bridge.MachineAccessView
}
TokenInfo is a token as the socket lists it (the hash is not interesting to people): SSHKeys are the fingerprints of its keys for the SSH channel, Machines the machines it reaches there (none: all). Lifetime is what it was created with, as token create -expires takes it; Renewed the last time it renewed itself.
type TokenRequest ¶
type TokenRequest struct {
Name string `json:"name"`
Scopes []string `json:"scopes"`
TTL string `json:"ttl"` // such as 365d or 720h
SSHKeys []string `json:"ssh_keys,omitempty"`
// Machines is its machine access as the command line writes it (store.ParseMachineList): all, or
// machine names, each with @END optionally; none when empty.
Machines []string `json:"machines,omitempty"`
}
TokenRequest creates a token. SSHKeys (authorized_keys lines) sign in to the SSH channel; Machines limits the machines it reaches there (none: all).
type TokenResponse ¶
TokenResponse carries the new token's secret, shown once.