api

package
v0.3.0-rc.53 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 22 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 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

View Source
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.

View Source
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

View Source
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.

View Source
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.

View Source
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 OpenAPI

func OpenAPI() []byte

OpenAPI is the API description served at /api/v1/openapi.yaml.

func RetryAfter

func RetryAfter(d time.Duration) string

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

func ScopeProblem(p store.Principal, scope string) string

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.

func ToolMeta

func ToolMeta(name string) map[string]any

ToolMeta returns structured MCP _meta attributes for a registered tool name.

func WaitWords

func WaitWords(d time.Duration) string

WaitWords says a lockout's wait as a person reads it: "a minute", "9 minutes". Errors carry it so a client knows how long to wait before trying again.

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

func (a *Auth) Authenticate(r *http.Request, secret string) (store.Principal, bool)

Authenticate is Check without the reason for a refusal.

func (*Auth) Blocked

func (a *Auth) Blocked(r *http.Request) bool

Blocked reports whether the client's address is locked out.

func (*Auth) BlockedFor

func (a *Auth) BlockedFor(r *http.Request) (time.Duration, bool)

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

func (a *Auth) BlockedForSecret(r *http.Request, secret string) (time.Duration, bool)

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

func (a *Auth) Check(r *http.Request, secret string) (store.Principal, time.Duration, error)

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

func (a *Auth) CheckToken(r *http.Request, secret string) (store.Token, time.Duration, error)

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) Client

func (a *Auth) Client(r *http.Request) netip.Addr

Client is the request's client address, as the configured proxies give it.

func (*Auth) Fail

func (a *Auth) Fail(r *http.Request)

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

func (a *Auth) Remember(r *http.Request, secrets ...string)

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

func (a *Auth) Separate() *Auth

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

func (a *Auth) SignIn(r *http.Request, username, password string) (store.Account, error)

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

func (a *Auth) UserBlockedFor(r *http.Request, username string) (time.Duration, bool)

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.

func (*Auth) Verify

func (a *Auth) Verify(r *http.Request, secret string) (store.Token, bool)

Verify is CheckToken without the reason for a refusal.

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"`
	ShareLinks      bool   `json:"share_links"`
	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"`
	UnavailableReason string   `json:"unavailable_reason,omitempty"`
}

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.

func (*Server) Register

func (s *Server) Register(mux *http.ServeMux)

Register adds the API's routes to mux.

Jump to

Keyboard shortcuts

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