cloudagent

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 40 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 cloudagent is `conch cloud agent`: the program that runs inside a Conch Cloud machine, beside its conch server. It is the VM's side of the conch-cloud contract (conch-cloud/contract: openapi.yaml's /v1/vm/* endpoints and PROTOCOL.md §3–§8): it says hello to the control plane with the machine token the host injected, reports what the agents are doing so the machine can sleep, joins the relay as the room's gateway and carries conch's own protocol to the local server, and hands agents their secrets and git its credentials without writing either down.

Index

Constants

View Source
const (
	WokeBoot   = "boot"
	WokeDisk   = "disk"
	WokeMemory = "memory"
)

What woke_from may say.

View Source
const (
	DefaultBootPath = "/run/conch-cloud/boot.json"
	DefaultStateDir = "/var/lib/conch/cloud"
	DefaultKeyPath  = DefaultStateDir + "/noise.key"
	// DefaultAgentSocket is the agent's own socket (local.go) when it runs
	// as root: in /run, so it goes with the boot.
	DefaultAgentSocket = "/run/conch/cloud-agent.sock"
)

Default places on a cloud machine (PROTOCOL §3.1, §4).

View Source
const CommandHello = "hello"

CommandHello (1.4.0) asks for hello again: the machine is waking, so this VM resumed from a memory sleep without knowing (PROTOCOL §3.1).

View Source
const CommandPauseAgents = "pause_agents"

CommandPauseAgents is the unattended cap's pause (PROTOCOL §5).

View Source
const Contract = "1.4.0"

Contract is the conch-cloud contract version this agent speaks: sent as Conch-Contract on every call, and as cloud.contract.<Contract> among the capabilities in hello (PROTOCOL §1).

View Source
const ContractCapability = "cloud.contract." + Contract

ContractCapability is how hello says which contract the VM implements.

View Source
const UnitName = "conch-cloud-agent.service"

UnitName is the systemd unit the control plane restarts after every inject (conch-cloud's sshx boot script: systemctl restart conch-cloud-agent).

Variables

View Source
var ErrFatal = errors.New("the control plane refused this machine")

ErrFatal wraps an answer to hello that asking again cannot change: the request is wrong, the machine's key is not the one clients pinned, or the control plane does not speak this contract.

View Source
var ErrUnauthorized = errors.New("the control plane refused this machine's token")

ErrUnauthorized is the control plane refusing the machine token. Each inject mints a new token and the old one stops working at once, so this is what an agent left over from an earlier inject sees.

Functions

func Ask

Ask asks the agent's socket one question: what `conch cloud git-credential` does for git.

func ExitCode

func ExitCode(err error) int

errExit is what Run's caller reads to choose an exit status.

func GitCredential

func GitCredential(args []string, in io.Reader, out io.Writer) error

GitCredential is git's credential helper on a cloud machine (`conch cloud git-credential`; git's credential.helper protocol: get reads the request on stdin and answers username and password). The password is the machine token, asked of the agent over its socket, from memory.

func Install

func Install(ctx context.Context, o InstallOptions) (string, error)

Install makes this machine one the control plane can start an agent on: the unit, enabled, and the state directory. It is what a machine image runs once (scripts/cloud-image.sh); it does not start the agent, which waits for boot.json anyway.

func LoadKey

func LoadKey(path string) (key noise.DHKey, made bool, err error)

LoadKey is the machine's Noise static key (PROTOCOL §3.1): made once, kept on the machine's own disk at path, 0600, and the same for the life of the machine — clients pin its public half, and the control plane marks a machine that shows a different one as broken. made says it was made just now, which is how a first boot is told from a wake.

A key file anyone else could read is refused, not repaired: whoever could read it could have answered as this machine, so it is no longer this machine's alone, and making a new one would fail the pin anyway.

func TunnelHandler

func TunnelHandler(opts Options) (http.Handler, error)

TunnelHandler is what a machine serves inside the tunnel — /bridge to the conch server at opts.ServerSocket, /exec as opts.User — without the rest of an agent. conch's client side (internal/cloud) tests itself against it, so the gateway it is checked against is the machine's own and not a copy that could drift from it.

func Unit

func Unit(exe string) string

Unit is the systemd unit that runs exe as the cloud agent.

KillMode=process because the agent starts the machine's conch server, which is the person's — its panes are their agents — and every inject restarts the agent: with the default, systemd would end the server and every pane with it. Exit statuses 3 (the token was refused) and 4 (the machine was) are not restarted, since restarting cannot change them and the next inject restarts the unit anyway; a missing boot.json is waited for, so the unit can be enabled at boot, before the host has injected one. Anything else (a boot.json it refuses, say) is restarted, 5 s apart at first and up to 5 minutes apart (systemd 254 and later; an older one warns about the two keys and keeps 5 s).

Types

type API

type API struct {
	Base string // boot.json's api
	HTTP *http.Client
	// contains filtered or unexported fields
}

API is the control plane as the VM calls it: the machineToken calls of openapi.yaml, each with Conch-Contract and the token.

func NewAPI

func NewAPI(base, token string, hc *http.Client) *API

NewAPI is the API at base, called with token.

func (*API) Activity

func (a *API) Activity(ctx context.Context, act VMActivity) ([]VMCommand, error)

Activity is one POST /v1/vm/activity. A server speaking 1.1.0 or later answers 200 with commands; 204 is a 1.0.0 server, with none.

func (*API) Env

func (a *API) Env(ctx context.Context) (map[string]string, error)

Env is GET /v1/vm/env: the env-mode secrets, for an agent being started.

func (*API) Hello

func (a *API) Hello(ctx context.Context, h VMHello) (VMConfig, error)

Hello is one POST /v1/vm/hello.

func (*API) Push

func (a *API) Push(ctx context.Context, p VMPush) error

Push is POST /v1/vm/push.

func (*API) PushTargets

func (a *API) PushTargets(ctx context.Context) ([]PushTarget, error)

PushTargets is GET /v1/vm/push/targets.

func (*API) SetToken

func (a *API) SetToken(token string)

SetToken replaces the machine token, after a new inject.

func (*API) Token

func (a *API) Token() string

Token is the machine token calls are made with: the git credential helper hands it to git, from memory.

type Agent

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

Agent is one run of conch cloud agent.

func New

func New(opts Options) (*Agent, error)

New is an agent with opts, its defaults filled in.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context) error

Run is the agent until ctx ends or something it cannot carry on from: a token the control plane refuses (ErrUnauthorized), a machine it refuses (ErrFatal), or a server that cannot be started.

type AgentActivity

type AgentActivity struct {
	Agent   string `json:"agent"`
	State   string `json:"state"`
	Project string `json:"project,omitempty"`
}

AgentActivity is one agent in an activity report.

type Boot

type Boot struct {
	MachineID    string `json:"machine_id"`
	API          string `json:"api"`
	MachineToken string `json:"machine_token"`
	ConchVersion string `json:"conch_version"`
}

Boot is /run/conch-cloud/boot.json, as the control plane's inject writes it (PROTOCOL §4): which machine this is, the API to call, the token to call it with and the conch release the machine should run.

func ReadBoot

func ReadBoot(path string) (Boot, error)

ReadBoot reads and checks boot.json. The token in it is the machine's whole identity to the control plane, so a file anyone else on the machine could read — or one somebody else owns — is refused rather than used: the host writes it root-only, 0600, and anything wider means something other than the host made it.

type InstallOptions

type InstallOptions struct {
	Executable string // conch; default this one
	UnitDir    string // default /etc/systemd/system
	StateDir   string // default DefaultStateDir
	User       string // the machine's user, which must exist; default conch
	// Systemctl runs systemctl; nil runs the real one, and is skipped on a
	// machine without systemd.
	Systemctl func(ctx context.Context, args ...string) error
}

InstallOptions are where Install writes; the zero value is the machine's.

type Options

type Options struct {
	BootPath     string
	KeyPath      string
	StateDir     string
	ServerSocket string // the conch server's; default: User's
	ServerLog    string
	AgentSocket  string // the agent's own (local.go)
	User         *User  // nil: this process's own user
	Executable   string // conch, to start the server and as git's credential helper
	HTTP         *http.Client
	Logf         func(format string, args ...any)
	// GitConfig sets one system-wide git setting (git.go); nil is git
	// config --system.
	GitConfig func(ctx context.Context, args ...string) error
	// ExecKillAfter is how long an /exec script whose client went has to
	// end on its SIGHUP before it is killed; 0 is execKillAfter.
	ExecKillAfter time.Duration
}

Options are where an agent finds things. The zero value is a cloud machine's (PROTOCOL §4): boot.json in /run/conch-cloud, the key in /var/lib/conch/cloud, and the person's side running as user conch when the agent is root. Tests point each somewhere of their own.

type Problem

type Problem struct {
	Status            int    `json:"status"`
	Type              string `json:"type"`
	Title             string `json:"title"`
	Detail            string `json:"detail,omitempty"`
	Code              string `json:"code"`
	ContractSupported string `json:"contract_supported,omitempty"`
	RetryAfter        int    `json:"retry_after,omitempty"`
}

Problem is an error the control plane answered (RFC 9457, openapi.yaml Problem).

func (*Problem) Error

func (p *Problem) Error() string

type PushMessage

type PushMessage struct {
	Type    string `json:"type"` // waiting
	Machine string `json:"machine"`
	Pane    string `json:"pane"`
	Name    string `json:"name,omitempty"`
	Project string `json:"project,omitempty"`
}

PushMessage is what a notification says, inside the encryption: which machine and pane, and enough words to say who is waiting. The contract leaves the plaintext to conch; this is the phone gateway's message (phone.PushMessage) with the machine named, since a device is told about every machine of the account.

type PushPayload

type PushPayload struct {
	DeviceID   string `json:"device_id"`
	Ciphertext string `json:"ciphertext"`
}

PushPayload is one encrypted notification for one device.

type PushTarget

type PushTarget struct {
	DeviceID           string `json:"device_id"`
	Kind               string `json:"kind"`
	P256dh             string `json:"p256dh"`
	Auth               string `json:"auth"`
	MaxCiphertextBytes int    `json:"max_ciphertext_bytes"`
}

PushTarget is one device subscription to encrypt a push to (PROTOCOL §8).

type SleepPolicy

type SleepPolicy struct {
	IdleSeconds          int `json:"idle_seconds,omitempty"`
	UnattendedMaxSeconds int `json:"unattended_max_seconds,omitempty"`
	ArchiveAfterSeconds  int `json:"archive_after_seconds,omitempty"`
}

SleepPolicy is VMConfig.sleep. The control plane decides sleep; the VM only keeps it to say so in its log.

type User

type User struct {
	Name  string
	UID   int
	GID   int
	Home  string
	Shell string
	// Groups are the user's supplementary groups (docker, say), which a
	// process started as it keeps: without them Go clears them all.
	Groups []uint32
}

User is who the person's side of the machine runs as: the conch server, its panes, and the scripts /exec runs (PROTOCOL §3.4, §4: user conch, home /home/conch). The agent itself runs as root under systemd, since boot.json and the system's git configuration are root's; everything it starts for the person runs as this user instead.

func CurrentUser

func CurrentUser() (*User, error)

CurrentUser is the user this process runs as.

func LookupUser

func LookupUser(name string) (*User, error)

LookupUser is name as the system knows it.

type VMActivity

type VMActivity struct {
	Agents          []AgentActivity `json:"agents"`
	ClientsAttached int             `json:"clients_attached"`
	ProcessesBusy   bool            `json:"processes_busy"`
}

VMActivity is POST /v1/vm/activity's body.

type VMCommand

type VMCommand struct {
	Type   string `json:"type"`
	Reason string `json:"reason,omitempty"`
}

VMCommand is something the control plane asks the VM to do (1.1.0).

type VMConfig

type VMConfig struct {
	MachineID   string      `json:"machine_id"`
	RelayURL    string      `json:"relay_url"`
	RoomSecret  string      `json:"room_secret"`
	Sleep       SleepPolicy `json:"sleep"`
	GitProxy    string      `json:"git_proxy,omitempty"`
	EgressProxy string      `json:"egress_proxy,omitempty"`
}

VMConfig is what hello answers (openapi.yaml VMConfig).

type VMHello

type VMHello struct {
	ConchVersion string   `json:"conch_version"`
	Capabilities []string `json:"capabilities"`
	ServerKey    string   `json:"server_key"`
	WokeFrom     string   `json:"woke_from,omitempty"`
}

VMHello is POST /v1/vm/hello's body (openapi.yaml VMHello).

type VMPush

type VMPush struct {
	Urgency  string        `json:"urgency,omitempty"`
	Payloads []PushPayload `json:"payloads"`
}

VMPush is POST /v1/vm/push's body.

Jump to

Keyboard shortcuts

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