# Machine providers

> Let your agent do it: Help me add machines to my Hermitbox fleet through a machine provider. On a trusted operator host, export `HERMITBOX_OPERATOR_API` and `HERMITBOX_OPERATOR_TOKEN` from the protected control environment, never copying a token or a provider credential into this chat. Run `hermitbox node shapes <region> --provider <name>` and show me the shapes. Ask me before you acquire, release or cancel anything: an acquisition rents a host that costs money. Follow the exact steps in https://docs.hermitbox.dev/v0.3.2/guides/add-machines.md.

Add fleet hosts with one command and hand them back when you are done. A machine provider rents a
Linux host on Hetzner or Boat, or takes a machine of yours over SSH, and joins it to the fleet with
the same token flow as any node. Control records each acquisition before it contacts a provider, so
a lost reply never rents a second host.

Hetzner is tested against the live provider in CI. Boat has not yet been verified on a live Boat VM.

## Acquire and release a host

1. Give control the provider's settings and credentials, from the table in
   [control's README](https://github.com/hermitbox/hermitbox/blob/cdd62e6c07e07c2b649b726729b4d8da6b25a737/control/README.md#machine-providers). Provider tokens stay in control's
   environment.
2. On a trusted operator host, with `HERMITBOX_OPERATOR_API` and `HERMITBOX_OPERATOR_TOKEN` set,
   list the shapes a region offers, acquire one, and follow the acquisition until the node joins.
3. Release the node when you no longer need it. A machine you joined over SSH stays yours: control
   never releases it.

```sh
# List a region's shapes from a provider.
hermitbox node shapes <region> --provider hetzner

# Acquire a host; keep the same key when retrying an uncertain answer.
hermitbox node acquire <region> \
  --provider hetzner \
  --shape <catalog-name> \
  --idempotency-key <key>

# Follow an acquisition, then release the node it made.
hermitbox node acquisition <id>
hermitbox node release <node>

# Cancel an unused enrollment and return its known rental.
hermitbox node cancel-acquisition <id>
```

Automatic growth and shrink are off until control runs with `HERMITBOX_AUTOSCALE=on`; control's
README lists the settings that steer it.

## How a rental stays single

A lost create reply becomes uncertain. Reconciliation looks for its deployment and acquisition
labels before any further action; if nothing is visible, it waits rather than risk another paid
host. Boat also receives its native Idempotency-Key. Manual SSH uses a root-owned acquisition
marker and strict host verification.

Only the enrollment token control minted binds a node to an acquisition; labels confer no trust.
One-time join secrets are derived with HMAC-SHA256 from an environment key and the acquisition
UUID, and only their hashes reach Postgres. Provider tokens are never stored in Postgres or exposed
by operator responses.

## Hetzner

Hetzner attaches an existing private network and firewall and runs cloud-init with the join line.
Its dynamic x86 catalog and gross hourly and monthly quotes come from the provider's server-types
and pricing endpoints. Quotes cover the server, not extra public IP charges, traffic, taxes
specific to an account, or other extras. Prices are preserved with acquisition and release events,
never private business constants. See [Hetzner API](https://docs.hetzner.cloud/reference/cloud).

## Boat

Boat exposes VM creation, file and command endpoints, but its published API has no geographic region
selector or live price catalog, so the operator supplies a logical region and an explicit shape and
price catalog. A bootstrap first proves Docker and a working systemd, then installs the configured
private network and verifies a private address before joining. Boat support has not been verified
on a live Boat VM.

Credentials go through Boat's authenticated file endpoint into a 0600 bootstrap file, never the
command-history string, and the file is deleted after execution.
See [Boat API](https://docs.boat.dev/openapi/boat-v1.yaml).

## Manual hosts

Manual hosts require a private IP, an SSH key and a pretrusted `known_hosts` entry. They are joined
with the same token flow but are never returned by control. Unknown provider hosts are reported as
orphans and retained.

Failed, unused acquisitions can be cancelled through the operator API or CLI; cancellation revokes
enrollment under a row lock before deleting a known rental. Joined hosts must use the ordinary
drain and release path.

## Fly Machines

No Fly Machines adapter is shipped. Fly Machines have an exec API and private networking, but
whether a Machine image supports the Docker daemon, kernel controls and systemd that `hermitboxd`
uses as a fleet node is unverified. See [Machines API](https://fly.io/docs/machines/api/) and
[remote builders](https://fly.io/docs/reference/remote-builder/).

## Releases

A release keeps your data: it preserves every live local archive copy in the object store before
removing a placement, not only the latest snapshot. Active sandboxes keep a draining host alive.

These prevent a release: lost or quarantined nodes, manual nodes, unknown observed copies,
insufficient healthy regional minimums, and missing stored copies. Provider deletion is tracked
through uncertainty and retried by the same host identity; Hetzner waits for its GET to return
not-found. No provider timeout declares a node lost.

## Join measurements

A join is measured from the durable acquire timestamp to the first authenticated, reconciled,
runtime-up, nonduplicate heartbeat accepted by Postgres. The trigger binds through the consumed
enrollment token, and CI logs `acquireToHealthySeconds` with its sample count. Percentiles need
repeated independent runs; none are published yet.

## How this is tested

CI's live Hetzner test reads the repository secret `HERMITBOX_HETZNER_TOKEN` only on pushes to
`refs/heads/main`. Branch pushes and pull requests run the other suites without provider
credentials, and the step skips visibly when the secret is absent.

The test creates a temporary network, firewall and SSH keys, restricts public ingress to the
runner's SSH address, and uses strict known-host tunnels for bootstrap, node API and snapshot
storage. It acquires and releases the host with the operator CLI and runs a real sandbox through
the public SDK, with an edge on the runner forwarding the sandbox's agent port through the
tunnel. Cleanup deletes only resources the test created.

The rented host installs the released CLI and joins only on a release-signed bootstrap offer, so
a change to the join script or `daemon.json` takes effect in this test after the next release. A
commit that raises the version skips it with a notice until its release exists.
