After Dark Systems / Service Automation HubCompletely Programmable Infrastructure

OpenSAH / Transfer documentation

Transfer API and agent lifecycle

Control-plane requests, grant validation, helper events, and the distinction between transfer and processing.

Scope and authority

This page summarizes the sahxfer v1 contract. The wire reference includes the exact grant and helper fields. Endpoint presence alone does not prove a deployed agent supports transfers. HTTP status/envelope details not fixed by these sources must be checked against the deployed server; no new API is defined here.

Interface Purpose
GET /api/v1/hosts/resolve?name=<host> Resolve an exact host within caller authority
POST /api/v1/xfer/grant Authorize a bounded single-file transfer
Helper fd 3 Initial grant, renewal and cancellation
Helper fd 4 Ready, active and terminal result events

Use Authorization: Bearer for an origin-bound device-login credential or X-API-Key, never both. TLS uses certificate verification. Credentials do not belong in query strings or UDP fields.

Grant request

Field Meaning
host_id Resolved target host
purpose xfer:put, xfer:get, or admin-only xfer:root
dir put or get; must agree with purpose
root, path Absolute authorized root and confined relative file path
size, sha256 Exact bytes and content identity; get requires agent preparation
overwrite Explicit replacement permission
transport Requested transport; the server chooses the response

Example shape for a put request (replace illustrative host and digest):

{
  "host_id": "HOST_ID",
  "purpose": "xfer:put",
  "dir": "put",
  "root": "/srv/app",
  "path": "app.tar.gz",
  "size": 123456789,
  "sha256": "REPLACE_WITH_64_LOWERCASE_HEX_CHARACTERS",
  "overwrite": false,
  "transport": "udp"
}

This is an illustrative schema example, not a ready-to-send request. For get, use the CLI's preparation flow; do not invent a source size or digest.

Grant response and checks

The response carries grant/transfer IDs, bound path and content, peer endpoints, selected profile/transport, byte cap, first-packet expiry, idle and hard deadlines, AEAD identifier, a 32-byte key and a 16-byte route token. The latter two are secrets, not diagnostic fields. The client verifies grant binding before sending payload. HTTPS-issued grant material stays in memory; only the explicit bootstrap workflow writes a grant file.

expires_at is the first-packet deadline, not the transfer's total lifetime. Authentic traffic refreshes the idle timer. The hard cap and agent lease remain independent stopping conditions. A requested transport does not authorize a fallback or an upgrade to the dc profile.

Agent and helper lifecycle

  1. The server authorizes intent and supplies a signed lease to the agent.
  2. The agent verifies identity, host, action, deadline, replay protection and material binding before launching the helper as the correct user.
  3. The helper reads one bounded JSON grant line on fd 3 and reports ready on fd 4.
  4. Authentic transfer activity produces active events; these do not mean persisted completion.
  5. The agent sends renew or cancel messages. EOF on fd 3 cancels. A renewal cannot silently change the file or key binding.
  6. The helper reports a final result, including status, reason, byte count and committed; hash is present only when committed.

The initial grant line has a 64 KiB cap and rejects unknown fields. Read the protocol for exact JSON keys, event variants, timing and lease payload semantics. recv does not drop privileges itself; that is the spawning agent's responsibility.

Refusals and retry decisions

Class Examples Handling
Authorization/path scope_denied, root_denied, bad_root, bad_path Correct authority or input; do not retry unchanged
Availability agent_offline, agent_unsupported Check host and deployed capability
Limits too_large, rate_limited, cap_reached Respect policy; do not split work to bypass it
Destination exists Inspect destination; replacement requires explicit intent
Integrity/protocol hash_mismatch, protocol Stop and investigate; never accept partial output
Expiry/cancel expired, idle, cancelled Reconcile possible completion and obtain a new grant if retrying

These names span control and transfer layers; they are not a new shared HTTP error envelope. The wire ABORT table defines numeric data-plane codes. There is no v1 cross-process resume. A retry starts at zero with fresh grant material. After uncertain completion, inspect the authoritative result and destination before permitting overwrite.

Agent file API

sahsync uses a different contract: a ticket opens a sequential file session on the agent WebSocket. Read the complete file protocol for ticket scopes, ready limits, stat/list/read/write/hash operations and errors. An xfer grant cannot be substituted for a file ticket.