client

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 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 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

Constants

This section is empty.

Variables

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

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

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

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

func IsCode

func IsCode(err error, code string) bool

IsCode reports whether err is a host Error with the given code.

func ResultOf

func ResultOf[T any](run api.Run) (T, error)

ResultOf decodes the result of a finished run into T (for example api.OSRunResult). A run without a result is an error.

Types

type Client

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

Client calls the host. It is safe for concurrent use.

func New

func New(socket string) *Client

New returns a Client for the socket path.

func (*Client) Audit

func (c *Client) Audit(ctx context.Context, since int64, limit int) (api.AuditPage, error)

Audit returns one page of the host audit log with seq greater than since.

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

func (c *Client) BoxAgentCheck(ctx context.Context, ca, requestID, actor string) (api.Run, error)

BoxAgentCheck runs box_agent.check with the certificates (PEM) agents pin now. A host older than the command answers 404 unknown_command.

func (*Client) Close

func (c *Client) Close()

Close drops idle connections.

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

func (c *Client) DownloadBackup(ctx context.Context, backupID string) (io.ReadCloser, int64, error)

DownloadBackup opens GET /v1/backups/{id}/content. The caller closes the body. Backups that hold secrets answer 403 contains_secrets.

func (*Client) DownloadExport

func (c *Client) DownloadExport(ctx context.Context, exportID string) (io.ReadCloser, int64, error)

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

func (c *Client) Events(ctx context.Context, runID string, after uint64) *Stream

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

func (c *Client) ExposureListIP(ctx context.Context, ip, requestID, actor string) error

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

func (c *Client) ExposureTokenForget(ctx context.Context, domain, requestID, actor string) error

ExposureTokenForget runs exposure.token_forget (review r2 M-A): the host takes the domain off its fence list (idempotent).

func (*Client) GetRun

func (c *Client) GetRun(ctx context.Context, runID string) (api.Run, error)

GetRun returns GET /v1/runs/{id}.

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

func (c *Client) Info(ctx context.Context) (api.Info, error)

Info returns GET /v1/info.

func (*Client) ListRuns

func (c *Client) ListRuns(ctx context.Context, limit int) ([]api.Run, error)

ListRuns returns the newest runs, newest first.

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

func (c *Client) NetConfirm(ctx context.Context, runID, requestID, actor string) (api.Run, error)

NetConfirm runs net.confirm for the awaiting net.apply run runID.

func (*Client) NetRevert

func (c *Client) NetRevert(ctx context.Context, runID, requestID, actor string) (api.Run, error)

NetRevert runs net.revert 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) OSCheck

func (c *Client) OSCheck(ctx context.Context, requestID, actor string) (api.Run, error)

OSCheck runs os.check.

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

func (c *Client) OSRebootCancel(ctx context.Context, requestID, actor string) (api.Run, error)

OSRebootCancel runs os.reboot.cancel.

func (*Client) OSTimezoneSet

func (c *Client) OSTimezoneSet(ctx context.Context, zone, requestID, actor string) (api.Run, error)

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

func (c *Client) StateBackups(ctx context.Context) (api.BackupList, error)

StateBackups returns GET /v1/state/backups.

func (*Client) StateContainers

func (c *Client) StateContainers(ctx context.Context) (api.ContainersState, error)

StateContainers returns GET /v1/state/containers.

func (*Client) StateHPTouches

func (c *Client) StateHPTouches(ctx context.Context) (api.HPTouchesState, error)

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

func (c *Client) StateHost(ctx context.Context) (api.HostState, error)

StateHost returns GET /v1/state/host. A host older than host.self_update answers 404 unknown_command.

func (*Client) StateNet

func (c *Client) StateNet(ctx context.Context) (api.NetState, error)

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

func (c *Client) StateOS(ctx context.Context) (api.OSState, error)

StateOS returns GET /v1/state/os. A host that has never checked answers 404 no_check_yet.

func (*Client) StatePackages

func (c *Client) StatePackages(ctx context.Context) (api.PackagesState, error)

StatePackages returns GET /v1/state/packages: the Debian packages installed on the box. An older host answers 404 unknown_command.

func (*Client) StatePorts

func (c *Client) StatePorts(ctx context.Context) (api.PortsState, error)

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

func (c *Client) StateTime(ctx context.Context) (api.TimeState, error)

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.

func (*Error) Error

func (e *Error) Error() string

type FenceError

type FenceError struct {
	Code    string
	Message string
}

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

type Stream

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

Stream reads the SSE events of one run. After a dropped connection it reconnects with Last-Event-ID, so no event is delivered twice and none is skipped (except those the host dropped: then events carry Truncated).

func (*Stream) Close

func (s *Stream) Close()

Close releases the connection.

func (*Stream) Next

func (s *Stream) Next() (api.Event, error)

Next returns the next event, io.EOF after the run's final state event, or an error.

Jump to

Keyboard shortcuts

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