Documentation
¶
Overview ¶
Package client is how core talks to vedette-host over its unix socket (docs/specs/host-api.md). An absent socket is ErrUnreachable: "not an appliance, or the host is not running"; core shows the matching "unsupported / cannot reach vedette-host" state and never pretends success (modules/host/CONTRACT.md, the section on the host being absent).
Index ¶
- Variables
- func IsCode(err error, code string) bool
- func ResultOf[T any](run api.Run) (T, error)
- type Client
- func (c *Client) Audit(ctx context.Context, since int64, limit int) (api.AuditPage, error)
- func (c *Client) BackupCreate(ctx context.Context, args api.BackupCreateArgs, requestID, actor string) (api.Run, error)
- func (c *Client) BackupPurge(ctx context.Context, requestID, actor string) (deleted int, runID string, err error)
- func (c *Client) BackupRestore(ctx context.Context, backupID, snapshot, requestID, actor string) (api.Run, error)
- func (c *Client) BoxAgentCheck(ctx context.Context, ca, requestID, actor string) (api.Run, error)
- func (c *Client) Close()
- func (c *Client) ContainerPull(ctx context.Context, args api.ContainerPullArgs, requestID, actor string) (api.Run, error)
- func (c *Client) ContainerRollback(ctx context.Context, args api.ContainerRollbackArgs, requestID, actor string) (api.Run, error)
- func (c *Client) ContainerStart(ctx context.Context, args api.ContainerStartArgs, requestID, actor string) (api.Run, error)
- func (c *Client) ContainerStop(ctx context.Context, service string, persist bool, requestID, actor string) (api.Run, error)
- func (c *Client) DownloadBackup(ctx context.Context, backupID string) (io.ReadCloser, int64, error)
- func (c *Client) DownloadExport(ctx context.Context, exportID string) (io.ReadCloser, int64, error)
- func (c *Client) DownloadZapReport(ctx context.Context, reportID string) (io.ReadCloser, int64, error)
- func (c *Client) Events(ctx context.Context, runID string, after uint64) *Stream
- func (c *Client) ExposureFenceCheck(ctx context.Context, args api.ExposureFenceCheckArgs, requestID, actor string) (string, error)
- func (c *Client) ExposureListIP(ctx context.Context, ip, requestID, actor string) error
- func (c *Client) ExposureToken(ctx context.Context, domain, requestID, actor string) (string, error)
- func (c *Client) ExposureTokenForget(ctx context.Context, domain, requestID, actor string) error
- func (c *Client) GetRun(ctx context.Context, runID string) (api.Run, error)
- func (c *Client) Greenbone(ctx context.Context, command string, args any, requestID, actor string) (api.Run, error)
- func (c *Client) Info(ctx context.Context) (api.Info, error)
- func (c *Client) ListRuns(ctx context.Context, limit int) ([]api.Run, error)
- func (c *Client) LogsExport(ctx context.Context, args api.LogsExportArgs, requestID, actor string) (api.Run, error)
- func (c *Client) NetApply(ctx context.Context, args api.NetApplyArgs, requestID, actor string) (api.Run, error)
- func (c *Client) NetConfirm(ctx context.Context, runID, requestID, actor string) (api.Run, error)
- func (c *Client) NetRevert(ctx context.Context, runID, requestID, actor string) (api.Run, error)
- func (c *Client) OSAutoSecuritySet(ctx context.Context, enabled bool, requestID, actor string) (api.Run, error)
- func (c *Client) OSCheck(ctx context.Context, requestID, actor string) (api.Run, error)
- func (c *Client) OSInstall(ctx context.Context, scope, snapshot, requestID, actor string) (api.Run, error)
- func (c *Client) OSReboot(ctx context.Context, args api.OSRebootArgs, requestID, actor string) (api.Run, error)
- func (c *Client) OSRebootCancel(ctx context.Context, requestID, actor string) (api.Run, error)
- func (c *Client) OSTimezoneSet(ctx context.Context, zone, requestID, actor string) (api.Run, error)
- func (c *Client) Run(ctx context.Context, command string, args any, requestID, actor string) (api.Run, error)
- func (c *Client) SelfUpdate(ctx context.Context, args api.HostSelfUpdateArgs, requestID, actor string) (api.Run, error)
- func (c *Client) StateBackups(ctx context.Context) (api.BackupList, error)
- func (c *Client) StateContainers(ctx context.Context) (api.ContainersState, error)
- func (c *Client) StateHPTouches(ctx context.Context) (api.HPTouchesState, error)
- func (c *Client) StateHost(ctx context.Context) (api.HostState, error)
- func (c *Client) StateNet(ctx context.Context) (api.NetState, error)
- func (c *Client) StateOS(ctx context.Context) (api.OSState, error)
- func (c *Client) StatePackages(ctx context.Context) (api.PackagesState, error)
- func (c *Client) StatePorts(ctx context.Context) (api.PortsState, error)
- func (c *Client) StateTime(ctx context.Context) (api.TimeState, error)
- func (c *Client) ZapBaseline(ctx context.Context, args api.ZapBaselineArgs, requestID, actor string) (api.Run, error)
- type Error
- type FenceError
- type Stream
Constants ¶
This section is empty.
Variables ¶
var ErrDenied = errors.New("host: vedette-host closed the connection without answering (peer not allowed, or the host died)")
ErrDenied is wrapped when the host closes the connection before answering. The usual cause is that the peer check rejected this process (wrong uid or cgroup: a deployment error to report as "not allowed"); a host that died mid-request looks the same.
var ErrEventTooLarge = errors.New("host: event is larger than 64 KiB")
ErrEventTooLarge is returned when one event exceeds 64 KiB (a hostile or broken host). It is not retried.
var ErrStreamLost = errors.New("host: event stream lost")
ErrStreamLost is returned by Stream.Next when the connection was lost and could not be resumed. It is not io.EOF: a lost stream says nothing about whether the run finished (ask GetRun).
var ErrUnreachable = errors.New("host: vedette-host is unreachable (not an appliance, or the host is not running)")
ErrUnreachable is wrapped by every failure to connect to the socket (path missing, nothing listening, no permission to open it). A peer the host refuses still connects: see ErrDenied.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the host. It is safe for concurrent use.
func (*Client) BackupCreate ¶
func (c *Client) BackupCreate(ctx context.Context, args api.BackupCreateArgs, requestID, actor string) (api.Run, error)
BackupCreate runs backup.create.
func (*Client) BackupPurge ¶
func (c *Client) BackupPurge(ctx context.Context, requestID, actor string) (deleted int, runID string, err error)
BackupPurge runs backup.purge: the host deletes every backup archive and its index, and answers how many archives went. requestID is the idempotency key (a UUID v4; retry with the same one). It waits for the run (a few files: a moment) and returns the run id as soon as the host has accepted it, also when ctx ends or an error follows, so the caller can ask GetRun(runID) later. A running write is a *Error with code busy; a failed run is an error with the run's code.
func (*Client) BackupRestore ¶
func (c *Client) BackupRestore(ctx context.Context, backupID, snapshot, requestID, actor string) (api.Run, error)
BackupRestore runs backup.restore; snapshot is the id of a snapshot of core's current state (kept as the pre_restore backup).
func (*Client) BoxAgentCheck ¶
BoxAgentCheck runs box_agent.check with the certificates (PEM) agents pin now. A host older than the command answers 404 unknown_command.
func (*Client) ContainerPull ¶
func (c *Client) ContainerPull(ctx context.Context, args api.ContainerPullArgs, requestID, actor string) (api.Run, error)
ContainerPull runs container.pull (slice 3-7): the host verifies the signed documents itself.
func (*Client) ContainerRollback ¶
func (c *Client) ContainerRollback(ctx context.Context, args api.ContainerRollbackArgs, requestID, actor string) (api.Run, error)
ContainerRollback runs container.rollback (slice 3-8a): back to the stored previous version.
func (*Client) ContainerStart ¶
func (c *Client) ContainerStart(ctx context.Context, args api.ContainerStartArgs, requestID, actor string) (api.Run, error)
ContainerStart runs container.start for the current image of a service (slice 3-6: no version).
func (*Client) ContainerStop ¶
func (c *Client) ContainerStop(ctx context.Context, service string, persist bool, requestID, actor string) (api.Run, error)
ContainerStop runs container.stop; persist keeps the service down after a reboot.
func (*Client) DownloadBackup ¶
DownloadBackup opens GET /v1/backups/{id}/content. The caller closes the body. Backups that hold secrets answer 403 contains_secrets.
func (*Client) DownloadExport ¶
DownloadExport opens GET /v1/exports/{id}/content. The caller closes the body.
func (*Client) DownloadZapReport ¶
func (c *Client) DownloadZapReport(ctx context.Context, reportID string) (io.ReadCloser, int64, error)
DownloadZapReport opens GET /v1/zap/{id}/content, the report of the last zap.baseline (at most api.MaxZapReport bytes, as the host says; the caller bounds its read too). The caller closes the body.
func (*Client) Events ¶
Events starts reading the events of runID after event number after (0 for all).
func (*Client) ExposureFenceCheck ¶
func (c *Client) ExposureFenceCheck(ctx context.Context, args api.ExposureFenceCheckArgs, requestID, actor string) (string, error)
ExposureFenceCheck runs exposure.fence_check: the host's own domain fence for an OpenVAS scan; nil error is a yes, with the name's CNAME chain.
func (*Client) ExposureListIP ¶
ExposureListIP runs exposure.token with proved set for a typed public IP: the host lists it for the executors (idempotent).
func (*Client) ExposureToken ¶
func (c *Client) ExposureToken(ctx context.Context, domain, requestID, actor string) (string, error)
ExposureToken runs exposure.token: the box-bound token of a verified domain.
func (*Client) ExposureTokenForget ¶
ExposureTokenForget runs exposure.token_forget (review r2 M-A): the host takes the domain off its fence list (idempotent).
func (*Client) Greenbone ¶
func (c *Client) Greenbone(ctx context.Context, command string, args any, requestID, actor string) (api.Run, error)
Greenbone runs one of the OpenVAS commands (api.CmdGreenboneUp with api.GreenboneUpArgs, api.CmdGreenboneDown or api.CmdGreenboneSyncFeed with nil) and follows the run until it ends, read again every two seconds like ZapBaseline. ctx bounds the wait only: the run goes on at the host until its own limit, or until greenbone.down stops it.
func (*Client) LogsExport ¶
func (c *Client) LogsExport(ctx context.Context, args api.LogsExportArgs, requestID, actor string) (api.Run, error)
LogsExport runs logs.export.
func (*Client) NetApply ¶
func (c *Client) NetApply(ctx context.Context, args api.NetApplyArgs, requestID, actor string) (api.Run, error)
NetApply runs net.apply: the whole desired state of the network part Vedette manages. A change of the management part leaves the run in awaiting_confirm until NetConfirm or NetRevert.
func (*Client) NetConfirm ¶
NetConfirm runs net.confirm for the awaiting net.apply run runID.
func (*Client) OSAutoSecuritySet ¶
func (c *Client) OSAutoSecuritySet(ctx context.Context, enabled bool, requestID, actor string) (api.Run, error)
OSAutoSecuritySet runs os.auto_security.set.
func (*Client) OSInstall ¶
func (c *Client) OSInstall(ctx context.Context, scope, snapshot, requestID, actor string) (api.Run, error)
OSInstall runs os.install with scope "security" or "all"; snapshot is the id of the snapshot core wrote for the pre_os_update backup.
func (*Client) OSReboot ¶
func (c *Client) OSReboot(ctx context.Context, args api.OSRebootArgs, requestID, actor string) (api.Run, error)
OSReboot runs os.reboot.
func (*Client) OSRebootCancel ¶
OSRebootCancel runs os.reboot.cancel.
func (*Client) OSTimezoneSet ¶
OSTimezoneSet runs os.timezone.set: the operating system's time zone becomes zone. A host older than the command answers 404 unknown_command.
func (*Client) Run ¶
func (c *Client) Run(ctx context.Context, command string, args any, requestID, actor string) (api.Run, error)
Run sends POST /v1/commands/{command} with args (any JSON-encodable value, nil for none). requestID must be a UUID v4: it is the idempotency key, so retrying with the same id after a lost connection returns the same run instead of running twice. A replay returns the existing run.
func (*Client) SelfUpdate ¶
func (c *Client) SelfUpdate(ctx context.Context, args api.HostSelfUpdateArgs, requestID, actor string) (api.Run, error)
SelfUpdate runs host.self_update: the host upgrades its own package to the release's. The run is parked while the applier works and the host restarts; reconnect and ask GET /v1/runs/{id} until it ends (at most until its deadline plus 5 minutes).
func (*Client) StateBackups ¶
StateBackups returns GET /v1/state/backups.
func (*Client) StateContainers ¶
StateContainers returns GET /v1/state/containers.
func (*Client) StateHPTouches ¶
StateHPTouches returns GET /v1/state/hp-touches: the sources that tried a new TCP or UDP connection to a decoy address in the last two minutes. A host older than it answers 404 unknown_command.
func (*Client) StateHost ¶
StateHost returns GET /v1/state/host. A host older than host.self_update answers 404 unknown_command.
func (*Client) StateNet ¶
StateNet returns GET /v1/state/net: the cards with their counters and addresses, the default route and the configuration the host wrote. A host older than the network commands answers 404 unknown_command.
func (*Client) StateOS ¶
StateOS returns GET /v1/state/os. A host that has never checked answers 404 no_check_yet.
func (*Client) StatePackages ¶
StatePackages returns GET /v1/state/packages: the Debian packages installed on the box. An older host answers 404 unknown_command.
func (*Client) StatePorts ¶
StatePorts returns GET /v1/state/ports: the ports the box listens on at an address other than loopback, with what holds each (inventory INV-3). A host older than it answers 404 unknown_command.
func (*Client) StateTime ¶
StateTime returns GET /v1/state/time: the operating system's time zone. A host older than it answers 404 unknown_command.
func (*Client) ZapBaseline ¶
func (c *Client) ZapBaseline(ctx context.Context, args api.ZapBaselineArgs, requestID, actor string) (api.Run, error)
ZapBaseline runs zap.baseline and follows the run until it ends (a scan takes minutes: the run is read again every two seconds), then returns it as it ended: succeeded with an api.ZapBaselineResult, or refused or failed with its code. ctx bounds the wait; the run itself stops at the host's own limit.
type Error ¶
type Error struct {
Status int
Code string
Message string
Details []api.Detail
RunID string // busy: the run in progress; pending_confirm: the run waiting for confirmation
RetryAfterS int // rate_limited
}
Error is a non-2xx answer of the host, with the codes of spec section 11.
type FenceError ¶
FenceError is a domain fence command (exposure.token, exposure.fence_check) that ended without a result: the host's code (token_foreign, target_not_owned, name_moved, cname_outside, ownership_unchecked, fence_unavailable, unknown_command for an older host, …) and its message.
func (*FenceError) Error ¶
func (e *FenceError) Error() string