Documentation
¶
Overview ¶
Package api is the REST API under /api/v1. Reads and writes need a bearer token with the right scope; the OpenAPI description is public. Errors are JSON {"error", "code"} with stable codes.
Index ¶
- Constants
- Variables
- func OpenAPI() []byte
- func RetryAfter(d time.Duration) string
- func ScopeProblem(p store.Principal, scope string) string
- func ToolMeta(name string) map[string]any
- func WaitWords(d time.Duration) string
- type Auth
- func (a *Auth) Attempt(r *http.Request, secret string, verify func() (accepted, genuine bool)) (time.Duration, error)
- func (a *Auth) Authenticate(r *http.Request, secret string) (store.Principal, bool)
- func (a *Auth) Blocked(r *http.Request) bool
- func (a *Auth) BlockedFor(r *http.Request) (time.Duration, bool)
- func (a *Auth) BlockedForSecret(r *http.Request, secret string) (time.Duration, bool)
- func (a *Auth) Check(r *http.Request, secret string) (store.Principal, time.Duration, error)
- func (a *Auth) CheckToken(r *http.Request, secret string) (store.Token, time.Duration, error)
- func (a *Auth) Client(r *http.Request) netip.Addr
- func (a *Auth) Fail(r *http.Request)
- func (a *Auth) Remember(r *http.Request, secrets ...string)
- func (a *Auth) Separate() *Auth
- func (a *Auth) SignIn(r *http.Request, username, password string) (store.Account, error)
- func (a *Auth) UserBlockedFor(r *http.Request, username string) (time.Duration, bool)
- func (a *Auth) Verify(r *http.Request, secret string) (store.Token, bool)
- type CallerCapabilities
- type Capabilities
- type Domain
- type Features
- type MCPPromptArg
- type MCPPromptSpec
- type MCPResourceSpec
- type Operation
- type Server
Constants ¶
const ( DomainIncidents = "incidents" DomainMonitoring = "monitoring" DomainMachines = "machines" DomainStatus = "status" DomainIdentity = "identity" DomainGovernance = "governance" )
Canonical operational domain identifiers shared across REST (/api/v1/capabilities), OpenAPI tags, the MCP server (_meta, resources, prompts) and the operations workspace.
const DocsURL = "https://beacon.openlinkos.com/reference/api"
DocsURL is the API's reference, where an answer to a request without a valid token points: whoever sends one may not know Beacon yet, and that page says how to get a token and what it may do.
Variables ¶
var ErrBlocked = errors.New("too many failed sign-ins; try again in a few minutes")
ErrBlocked means too many sign-ins failed recently, from this address or for this username.
var ErrInvalid = errors.New("the credential is unknown or has expired")
ErrInvalid means a secret is unknown, has expired or was revoked, or its holder may not act now.
var Routes = []string{
"GET /api/v1/bridge", "GET /api/v1/alerts", "GET /api/v1/alerts/{id}", "POST /api/v1/alerts/{id}/ack",
"GET /api/v1/silences", "POST /api/v1/silences", "DELETE /api/v1/silences/{id}", "GET /api/v1/audit",
"GET /api/v1/ssh", "POST /api/v1/ssh/pause", "POST /api/v1/ssh/resume",
"GET /api/v1/machines", "POST /api/v1/machines", "PATCH /api/v1/machines/{name}", "DELETE /api/v1/machines/{name}", "POST /api/v1/machines/{name}/run",
"GET /api/v1/machines/{name}/history", "POST /api/v1/machines/{name}/restore",
"POST /api/v1/machines/{name}/check", "POST /api/v1/machines/{name}/search", "GET /api/v1/machines/{name}/file", "PUT /api/v1/machines/{name}/file", "PATCH /api/v1/machines/{name}/file",
"GET /api/v1/sessions", "GET /api/v1/sessions/{id}", "GET /api/v1/sessions/{id}/recording",
"GET /api/v1/alerts/{id}/evidence", "GET /api/v1/alerts/{id}/timeline", "POST /api/v1/alerts/{id}/notes", "GET /api/v1/changes",
"PUT /api/v1/alerts/{id}/agent-runs/{delivery}", "GET /api/v1/agent-hooks/{name}/first-drill",
"GET /api/v1/incident-outcomes", "GET /api/v1/incident-outcomes/{id}",
"GET /api/v1/incident-episodes",
"PUT /api/v1/machines/{name}/connector",
"POST /api/v1/probe-now",
"POST /api/v1/share-links/{kind}/{id}", "POST /api/v1/share-links/{kind}/{id}/revoke",
"GET /api/v1/team-credentials", "POST /api/v1/team-credentials/{id}/use", "POST /api/v1/team-credentials/{id}/read",
}
Routes lists the authenticated routes, for the test that keeps the OpenAPI description in step.
Functions ¶
func RetryAfter ¶
RetryAfter is a lockout's wait in whole seconds, rounded up, for the Retry-After header. The gateway answers its lockouts the same way the API does, so it shares these words.
func ScopeProblem ¶
ScopeProblem says why p may not use scope ("a|b"): for an agent, what its preset within its owner's role allows, so that it knows whom to ask.
Types ¶
type Auth ¶
type Auth struct {
Store *store.Store
IP *clientip.Resolver
Now func() time.Time
// contains filtered or unexported fields
}
Auth checks bearer tokens and people's passwords, and limits failed attempts per client address and, for passwords, per username.
An address is an IPv4 address, or an IPv6 address's /64, which one machine or one household usually holds whole. Only a secret that Beacon did not issue counts as a failure: a genuine credential refused for what it may do, or because its owner is disabled, is not a guess. After maxFails failures in failWindow the address is locked out until the window ends. A secret is then refused unread unless it was accepted from the same address earlier (within goodFor), so a client with a working credential keeps working beside one that keeps failing, while the locked address cannot be used to try new secrets.
A username is locked after maxUserFails wrong passwords in failWindow, from anywhere. While it is, an address that has itself got that username wrong maxUserAddrFails times is refused for it; an address that has not, such as the person's own, may still sign in, and each wrong password from it counts. Wrong passwords from one address never hold another back for the username, so that someone guessing it cannot keep the person out.
func (*Auth) Attempt ¶
func (a *Auth) Attempt(r *http.Request, secret string, verify func() (accepted, genuine bool)) (time.Duration, error)
Attempt checks a secret under the address's lockout. verify does the checking and reports whether the secret is accepted, and whether a refused secret is nonetheless genuine (one Beacon issued), which does not count as a failure. While the address is locked out, verify runs only for a secret accepted from this address before; any other gets ErrBlocked and the wait, unread. A refused secret gets ErrInvalid.
func (*Auth) Authenticate ¶
Authenticate is Check without the reason for a refusal.
func (*Auth) BlockedFor ¶
BlockedFor reports how much of the address's lockout is left, and whether there is one: how long the client must wait before trying again with anything but a credential that already worked from here.
func (*Auth) BlockedForSecret ¶
BlockedForSecret is BlockedFor for a request that presents secret: a secret that worked from the address, or that Beacon issued to a client there (Remember), passes the lockout.
func (*Auth) Check ¶
Check checks a bearer secret for the API, MCP and the pages, counting failures: a token or an OAuth access token, resolved to who it is and what it may do now. It reports ErrBlocked with the wait, or ErrInvalid.
func (*Auth) CheckToken ¶
CheckToken checks a token secret for the request, counting failures: the machines' check, on the gateway, where an agent's token carries no scopes of its own. It reports ErrBlocked with the wait, or ErrInvalid.
func (*Auth) Fail ¶
Fail counts a failed attempt from the request's client: a wrong code or refresh token on the OAuth token endpoint, say.
func (*Auth) Remember ¶
Remember notes secrets Beacon has just issued to the request's client as having worked from its address: an OAuth client's new access and refresh tokens, which replace the ones it signed in with, so that it keeps working there during a lockout as a token that worked there does.
func (*Auth) Separate ¶
Separate is an Auth on the same store and client addresses that counts its failures apart. The machines' gateway keeps its own, so that what people's and agents' clients get wrong never stops monitoring data, and the other way round.
func (*Auth) SignIn ¶
SignIn checks a person's username and password, limited per address and per username: ErrBlocked after too many failures, store.ErrBadCredentials for a wrong username or password.
func (*Auth) UserBlockedFor ¶
UserBlockedFor is BlockedFor for one username's wrong passwords, as they apply to the request's client: a locked username stays open to an address that has not got it wrong itself.
type CallerCapabilities ¶
type CallerCapabilities struct {
Actor string `json:"actor"`
User string `json:"user,omitempty"`
Agent string `json:"agent,omitempty"`
Preset string `json:"preset,omitempty"`
Scopes []string `json:"scopes"`
MachineScope string `json:"machine_scope"` // all, listed or none; machine_access says the same in today's words
bridge.MachineAccessView
Person bool `json:"person"`
Standalone bool `json:"standalone"`
}
CallerCapabilities summarises who the authenticated caller is and what boundaries apply right now.
type Capabilities ¶
type Capabilities struct {
Caller CallerCapabilities `json:"caller"`
Features Features `json:"features"`
Domains []Domain `json:"domains"`
Resources []MCPResourceSpec `json:"resources"`
Prompts []MCPPromptSpec `json:"prompts"`
}
Capabilities is the live discovery payload returned by GET /api/v1/capabilities, the MCP describe_capabilities tool, beacon://capabilities and the console's Agent & MCP Hub.
func BuildCapabilities ¶
func BuildCapabilities(p store.Principal, f Features) Capabilities
BuildCapabilities constructs the full caller-aware domain, operation, resource and prompt matrix.
type Domain ¶
type Domain struct {
ID string `json:"id"`
Title string `json:"title"`
Tag string `json:"tag"`
Summary string `json:"summary"`
Workflow string `json:"workflow"`
Operations []Operation `json:"operations"`
}
Domain groups related operations with a clear workflow guide for people and AI agents.
type Features ¶
type Features struct {
SSH bool `json:"ssh"`
SSHPaused bool `json:"ssh_paused"`
Config bool `json:"config"`
Settings bool `json:"settings"`
Status bool `json:"status"`
ProbeNow bool `json:"probe_now"`
TeamCredentials bool `json:"team_credentials"`
MCPEndpoint string `json:"mcp_endpoint,omitempty"`
OpenAPIURL string `json:"openapi_url,omitempty"`
DocsURL string `json:"docs_url,omitempty"`
}
Features describes which optional Beacon subsystems are enabled on this instance.
type MCPPromptArg ¶
type MCPPromptArg struct {
Name string `json:"name"`
Description string `json:"description"`
Required bool `json:"required"`
}
MCPPromptArg describes one argument of an operational MCP prompt.
type MCPPromptSpec ¶
type MCPPromptSpec struct {
Name string `json:"name"`
Title string `json:"title"`
Domain string `json:"domain"`
Description string `json:"description"`
Arguments []MCPPromptArg `json:"arguments,omitempty"`
}
MCPPromptSpec describes a reusable operational playbook exposed through MCP prompts.
func MCPPrompts ¶
func MCPPrompts() []MCPPromptSpec
MCPPrompts returns the canonical catalog of operational MCP prompts offered by Beacon.
type MCPResourceSpec ¶
type MCPResourceSpec struct {
URI string `json:"uri"`
Template bool `json:"template,omitempty"`
Name string `json:"name"`
Title string `json:"title"`
Domain string `json:"domain"`
Scopes []string `json:"scopes"`
Description string `json:"description"`
Available bool `json:"available"`
}
MCPResourceSpec describes a read-only MCP resource or RFC 6570 resource template.
type Operation ¶
type Operation struct {
Tool string `json:"tool"`
REST string `json:"rest"`
Domain string `json:"domain"`
Access string `json:"access"` // read, write, destructive
Scopes []string `json:"scopes"`
ScopeMode string `json:"scope_mode,omitempty"` // any (default), all, standalone_admin, owner_or_self, person
Summary string `json:"summary"`
Available bool `json:"available"`
}
Operation describes one Beacon operation across REST and MCP, evaluated against the caller.
type Server ¶
type Server struct {
Bridge *bridge.Bridge
SSH *sshgate.Gate
SSHAddress string
Auth *Auth
Log *slog.Logger
Config *configdb.Service
Settings *config.Manager
Status *status.Service // the public status pages (status.go); nil: none
Credentials *secrets.Service
CredentialsConfigured bool // configured but temporarily unavailable when Credentials is nil
}
Server serves the API. SSH is nil when the SSH channel is off; SSHAddress is where agents reach it. Config is the configuration Beacon holds (its routes are in config.go); nil leaves them out.