ssh

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 31 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 ssh is the fixed-capacity provider (providers delta C): jobs run on one host the owner already has, reached over the system OpenSSH client, with a number of slots instead of a price.

Index

Constants

This section is empty.

Variables

View Source
var (
	// AgentSpec builds the agent's spec from the job.
	AgentSpec func(j *provider.JobSpec) agent.Spec
	// ResolveAgentFile returns the sha256 and local path of the agent binary for an architecture:
	// its bytes are what the provider sends over the session (providers delta C.4 item 4).
	ResolveAgentFile func(e *config.Effective, core *config.Provider, arch string) (sha, path string, err error)
)

The orchestration sets these (as RunPod's and Sprites' AgentSpec).

View Source
var ErrStreamEnded = &provider.ErrTransient{Why: "tail stream ended without a done frame"}

ErrStreamEnded: the tail's session ended before the agent's done frame (a dropped link); the caller reopens it from the last offsets.

Functions

func CheckTunnelSshd

func CheckTunnelSshd(out string) []provider.DoctorLine

CheckTunnelSshd judges the output of `sshd -T` for the tunnel account: one fail line per option that is not as C.6.3 wants it, else a single ok line.

func GitFloorLine

func GitFloorLine(version, changelog string) provider.DoctorLine

GitFloorLine judges the host's `git --version` output and the part of its package changelog that names the CVE (empty when the package has none): ok at git >= 2.45.1 or when the changelog names CVE-2024-32002, else a fail line `ssh-git`.

func KnownHostsLine

func KnownHostsLine(hostKey string) string

KnownHostsLine is the one line of the pinned known_hosts file: `bitc-ssh <type> <key>`. The alias makes it independent of the host and port (providers delta C.2.2).

func ParseHostKey

func ParseHostKey(s string) (typ string, err error)

ParseHostKey checks the host_key of the host file: an authorized_keys-style line (the type, the base64 blob, an optional comment). It returns the key type, or the reason it is not usable (providers delta C.10): ssh-dss and ssh-rsa under 3072 bits are refused.

func ParseResourceID

func ParseResourceID(id string) (host string, slots []int, name string, ok bool)

ParseResourceID splits a resource id: the slots must ascend, each in 1..64.

func ResourceID

func ResourceID(host string, slots []int, name string) string

ResourceID is <host>/s<i>[+s<j>...]/<name> (providers delta C.3.5).

func SlotsArg

func SlotsArg(slots []int) string

SlotsArg renders slots as the gate writes them: "1" or "1+2".

Types

type Class

type Class int

Class is what the ssh client's stderr says about how far a session got.

const (
	ClassOther   Class = iota // not a pre-session line: the session may have been up
	ClassConnect              // no connection was made: refused, timeout, no route, DNS, key exchange cut
	ClassHostKey              // the host presented another key than the pinned one
	ClassAuth                 // the host refused the identity
)

func ClassifyLoose

func ClassifyLoose(code int, stderr string) (Class, string)

ClassifyLoose is for the steps before the resource point, where nothing of this job exists on the host: the whitelisted line may sit among others (the host-key mismatch prints a banner).

func ClassifySession

func ClassifySession(code int, stderr, user, host string) (Class, string)

ClassifySession matches the client's result against the pre-session whitelist of providers delta C.5.1 item 3: only exit 255 with stderr that is exactly one of the listed lines (with LogLevel=ERROR) proves that no channel and no request existed. Anything else, a second line or other text included, is ClassOther: the session may have been up.

type Lease

type Lease struct {
	Slots []int
	// contains filtered or unexported fields
}

Lease is a set of held slot locks.

func (*Lease) Release

func (l *Lease) Release()

Release drops the locks (idempotent).

type Parsed

type Parsed struct {
	Install, Pool, Size, Job8 string
	Expires                   time.Time
}

Parsed are the fields of a resource name (<prefix>-<install16>-<pool>-<size>-<job8>-<E>).

func ParseName

func ParseName(prefix, name string) (Parsed, bool)

ParseName reads a name with this prefix; the pool is whatever lies between install16 and size.

type Provider

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

Provider is the ssh provider: slots on one host the owner already has (providers delta C).

func NewProvider

func NewProvider(core *config.Provider, eff *config.Effective) (*Provider, error)

NewProvider builds the provider from its host section.

func (*Provider) DoctorLines

func (p *Provider) DoctorLines(ctx context.Context) []provider.DoctorLine

DoctorLines are the provider's own `doctor --remote` checks (providers delta C.8): the pinned key, the host's arch and slots, every item of `check-host --doctor` (relayed as the host prints it) and the tunnel account.

func (*Provider) Estimate

func (p *Provider) Estimate(_ context.Context, j *provider.JobSpec) (config.Micros, error)

Estimate is usd_per_hour x (E - now), which is $0 by default (providers delta C.3.3).

func (*Provider) Fetch

Fetch downloads artifacts.tar.gz from a.Offset over exec, capped (resumable by offset).

func (*Provider) Info

func (p *Provider) Info() provider.Info

func (*Provider) Launch

func (p *Provider) Launch(ctx context.Context, j *provider.JobSpec) (provider.Handle, error)

Launch leases slots, checks the host, prepares the slots and attaches (providers delta C.5):

slot locks; probe; install; check-host; `slot-boot --prepare` (the resource point); then
`slot-boot --run`, the one call that carries job input (the attach point).

Everything before --prepare leaves nothing on the host (provider.Unmade). A --prepare that never got past session setup is the same; any other --prepare failure is an ErrPreAttach naming the slot group. A --run that never got past session setup is an ErrPreAttach too; every other --run outcome without the `started` ack is attached, and nothing falls back after it.

func (*Provider) List

func (p *Provider) List(ctx context.Context, prefixes []string) ([]provider.Resource, error)

List lists the slot groups that carry a name with one of the prefixes: one Resource per group. Its ID is <host>/s<i>[+s<j>]/<name>; a failure is a refusal of the launch (providers delta C.3.3).

func (*Provider) Output

func (p *Provider) Output(ctx context.Context, h provider.Handle, s provider.Stream, off int64, w io.Writer) error

Output copies a result file from off (spec 8.4 "Host side"), over exec.

func (*Provider) Owner

func (p *Provider) Owner(ctx context.Context, id string) (string, error)

Owner returns the owner tag the slot's owner file carries, "" for a slot group that is free or whose tag is another install's: the proof is the tag itself (HMAC of the name).

func (*Provider) Preflight

func (p *Provider) Preflight(_ context.Context, j *provider.JobSpec) error

Preflight is the network-free eligibility check (providers delta C.5): a size of this host, no services and no root steps (decision 15), a deploy key for a private repo, a payload that fits.

func (*Provider) SlotStatus

func (p *Provider) SlotStatus(ctx context.Context) (provider.SlotStatus, error)

SlotStatus lists the slot groups held now, by any controller (the lease is ahead), for `status`.

func (*Provider) Spend

func (p *Provider) Spend(context.Context) (config.Micros, error)

Spend: a fixed host has no billing API (Caps.Spend is false).

func (*Provider) Start

func (p *Provider) Start(_ context.Context, rt provider.Runtime) error

Start keeps the host's redactor, so the deploy key joins it (Walk calls Start once).

func (*Provider) SweepRules

func (p *Provider) SweepRules() provider.SweepPolicy

SweepRules: a slot group is one resource per job (providers delta C.3.6). An own group with no live reservation on this host is freed once its lease is older than start_timeout, an own group whose only reservation is an orphan at once, and any own group past E; the owner tag must verify (the shared sweep checks it). The agent frees its own slot at D + 10m, so the timer is advised (doctor warns), not mandatory.

func (*Provider) Teardown

func (p *Provider) Teardown(ctx context.Context, id string) error

Teardown frees the slots of a group by name (providers delta C.3.6): the host compares the owner file's name with name under the slots' mutex, so a stale cleanup never touches a later job that leased the same slot. The controller's slot locks are released whatever the answer.

func (*Provider) Watch

Watch follows the job until its EXIT marker and the end of the agent (spec 8.4 host side). A dropped tail is not an error: it is reopened from the last offsets, and when reopening fails twice within 30 s the files are read every 5 s until a reopen succeeds.

type Result

type Result struct {
	Code   int
	Stderr string // the last 64 KiB: everything the ssh client itself printed
}

Result is one finished call of the host's gate.

type Settings

type Settings struct {
	Host, User, HostKey, HostKeyType, IdentityFile, Arch, Resolver string
	Port, Slots                                                    int
	USDPerHour                                                     config.Micros // accounting only
	ConnectTimeout                                                 time.Duration
	MemoryPerSlot                                                  config.Size // 0: no memory.max
	Netns                                                          bool
	Sizes                                                          map[string]Size
}

Settings are the provider-specific keys of [providers.ssh] (providers delta C.2), decoded.

func DecodeSettings

func DecodeSettings(core *config.Provider) (Settings, []string)

DecodeSettings decodes the provider-specific keys strictly and applies the checks of providers delta C.10. It also reads the core fields the rules depend on (max_live, daily_usd, api_key). Each message is the text after `providers.ssh.`.

func (Settings) Argv

func (s Settings) Argv(knownHosts, identity, verb string) []string

Argv is everything after the program name of one ssh invocation (providers delta C.2.2): the host key is pinned (StrictHostKeyChecking=yes, a dedicated known_hosts file with one aliased line, no global file, no key update), no agent or other forwarding is ever requested, only the one identity file is offered, nothing prompts, and the connect has a timeout. No secret is in it: identity is a path. verb is the gate's command line (one argument).

type Size

type Size struct{ Slots int }

Size is one entry of [providers.ssh] sizes: how many slots a job of that size takes.

type SlotLocks

type SlotLocks struct {
	Dir string
	N   int
}

SlotLocks are the controller-side slot flocks, ACCOUNT/remote/ssh/slot.<i>.lock (providers delta C.3.1). A job's process holds them for its ssh attempt only; the host-side lease (the owner file) is the other half and guards a second controller and a dead one.

func (*SlotLocks) Acquire

func (l *SlotLocks) Acquire(need int) (lease *Lease, busy int, err error)

Acquire takes the lowest `need` free slots, all or none. busy counts the slots that were held by someone else; the lease is nil (and nothing stays held) when fewer than `need` were free.

type TailExitError

type TailExitError struct{ Code int }

TailExitError: `agent tail` ended with a nonzero exit status (66: the job's directory is not there yet, which the first tail after the attach can meet). It is transient.

func (*TailExitError) As

func (e *TailExitError) As(target any) bool

func (*TailExitError) Error

func (e *TailExitError) Error() string

Directories

Path Synopsis
Package sshfake is the ssh provider's test double (providers delta C.11): a fake host gate.
Package sshfake is the ssh provider's test double (providers delta C.11): a fake host gate.
gate command
Command sshfakegate is the fake ssh host gate the conformance suite runs in place of ssh (providers delta C.11): `sshfakegate --root DIR -- <gate command line>`.
Command sshfakegate is the fake ssh host gate the conformance suite runs in place of ssh (providers delta C.11): `sshfakegate --root DIR -- <gate command line>`.

Jump to

Keyboard shortcuts

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