Expand description
The library behind stratum, the client for a Stratum node: the
administrator’s commands on the loopback API, and a tenant’s commands
through the gate.
Pre-release: this is 0.1.0-alpha. The commands, output and API may
change before 0.1.0, and nothing built on it has been deployed yet.
A Stratum node serves an administrative API on loopback only. stratum
talks to that API over plain HTTP and holds the operator’s own Nostr key;
it never sees the node key or the node’s state volume, except that
stratum setup reads the bootstrap token file the operator points it at.
A tenant uses the same binary with their own key to join a node and to
read, write and export their pod through the node’s gate.
- URLs.
LoopbackUrlacceptshttp://URLs whose host is an IPv4 address in127.0.0.0/8,[::1]orlocalhost, and nothing else: Step 1 has no TLS.localhostis connected to127.0.0.1without a name lookup. - Operator keys.
generate_key_filewrites a fresh key as onensec1…line to a file created exclusively with mode0600;load_key_filerefuses symbolic links and modes wider than0600. The secret is never printed, logged or returned as text. - Changes.
parse_changesreads--set path=valuearguments typed by the schema instratum-node-config. - Commands.
Sessionruns each command against one node:status,config(schema,show,preview,apply),setup,sign-challenge,audit checkpoint,backup,invite(create,list,revoke),member(list,show,repair,cancel,suspend,resume,archive,remove; seeSuspendOptionsandRemoveOptions),application(add,list,withdraw,approve,disable; seeApplicationAction) andinstallations. Every authenticated request is signed withNostrSecretKey::sign_request_with_nonceover the exact URL, method and body bytes sent, with a fresh random nonce so no two signings are the same event. - Tenant commands.
join,pod(ls,get,put,rm,acl get,acl put),export,profile initandprofile showtake aGateTarget: the node’sCanonicalOrigin, which every request is signed for and named inHost, and a loopbackConnectAddressthe request is sent to over plain HTTP. Every pod path is checked as aPodPathbefore anything is sent. - Applications.
app(catalogue,install,list,show,jobs,run,withdraw,cleanup,resume) installs and withdraws applications in the tenant’s own pod.install(InstallOptions) checks the offered grant by rendering it again withrender_offered, reads the ACL that governs each granted container, builds its new ACL (the owner’s control, existing rules kept, inheritedacl:defaultrules materialised, the offered rule), refuses any statement it does not evaluate and anyControlfor the application, previews the diffs andOPERATOR_STATEMENT, writes each ACL conditionally after rereading what governs it, reads it back, and consents only if every read-back matches.withdrawandcleanupedit the installation’s authorisation out of each ACL withIf-Matchand report each container as it is cleaned. Turtle is parsed withoxttl. Everyappcommand shows a withdrawn grant whose cleanup is not yet reported. - The public profile.
joinandprofile initwrite the card/pods/<pk>/profile/cardand its public-read ACL with the exact texts ofprofile_cardandprofile_acl, reading first and creating only what is missing (ProfileInitOptions).profile showreads anyone’s card with an unsigned request and needs no key. - Exit codes. Failures are
CliErrors, each mapped to a stable code inexit;CliError::hintadds advice for the codes that need it.
The crate targets Unix: key files rely on Unix permission bits.
§Example
use stratum_node_cli::{Output, OutputFormat, Session};
let output = Output::new(OutputFormat::Human);
let session = Session::new("http://127.0.0.1:7460".parse()?, Some("operator.nsec".into()), output);
let code = session.status().unwrap_or_else(|err| {
output.error(&err);
err.exit_code()
});
std::process::exit(i32::from(code));Modules§
- exit
- The process exit codes of
stratum, stable across releases.
Structs§
- Apply
Options - Options for
Session::config_apply. - Bootstrap
Token - The bootstrap token: 64 lowercase hex digits proving entitlement to claim a node.
- Canonical
Origin - A node’s canonical origin: the one origin every signed tenant URL names.
- Connect
Address - A
--connect <host:port>value: a loopback literal and an explicit port. - Export
Options - Options for
Session::export. - Gate
Target - Where a tenant command sends its requests: the canonical origin it signs for, and the local plain-HTTP address it connects to.
- Install
Options - Options for
Session::app_install. - Invite
Options - Options for
Session::invite_create. - Join
Options - Options for
Session::join. - Loopback
Url - A plain-HTTP URL whose host is a loopback literal, kept in canonical form.
- Output
- The terminal writer used by every command.
- Parse
Connect Error - A
--connectvalue was not<loopback host>:<port>. - Profile
Init Options - Options for
Session::profile_init. - PutOptions
- Options for
Session::pod_putandSession::pod_acl_put. - Remove
Options - Options for
Session::member_remove. - Session
- One node, one optional operator key file and one output format: the
context every
stratumcommand runs in. - Setup
Options - Options for
Session::setup. - Suspend
Options - Options for
Session::member_suspend.
Enums§
- Application
Action - An administrator transition of an application.
- CliError
- Why a
stratumcommand failed. - Confirmation
- Whether a command that changes the node may proceed without asking.
- KeyFile
Error - Why an operator key file could not be created or loaded.
- Output
Format - How results are written to standard output.
- Parse
Change Error - Why a
--setargument could not be parsed. - Parse
Origin Error - The reasons an origin is refused by
CanonicalOrigin. - Parse
UrlError - The reasons a URL is refused by
LoopbackUrl. - Private
File Error - Why a private file could not be created or read.
- Scheme
- The scheme of a canonical origin.
- Token
File Error - Why the bootstrap token file could not be read.
- Write
Condition - The condition a
PUTis sent under.
Constants§
- DEFAULT_
ENFORCEMENT_ WAIT - The default for
member suspend --wait: longer than the node’s 310 second fallback, after which a suspension isenforcedeven if the gate never polled. - DEFAULT_
URL - The default node URL: the loopback address the controller listens on by default.
- DEFAULT_
WAIT - The default time
joinwaits for the pod to be provisioned. - MANIFEST_
FORMAT - The
formatmember of an export manifest. - MANIFEST_
FORMAT_ VERSION - The
format_versionmember of an export manifest. - MANIFEST_
SUFFIX - The suffix appended to the archive’s file name for the manifest.
- MAX_
EXPORT_ BYTES - The most bytes of resource content an export holds before it stops: 64 GiB.
- MAX_
EXPORT_ ENTRIES - The most entries an export holds before it stops: containers, resources and ACLs together.
- MAX_
INVITATION_ LIFETIME - The longest invitation lifetime the node accepts: 30 days.
- OPERATOR_
STATEMENT - The statement
app installprints before it asks (ADR D12, contract “The client previews”).
Functions§
- generate_
key_ file - Creates a new operator key file holding a freshly generated key.
- load_
key_ file - Loads an operator key file written by
generate_key_file. - parse_
changes - Parses
--set path=valuearguments into configuration changes, typed by the schema instratum-node-config. - parse_
duration - Parses a duration written as a whole number of seconds, or a number
followed by
s,m,hord.