Device enrollment, inventory and credential lifecycle
- Work record: #21, cloud epic #4.
- Baseline: ADR-0005, local safety authority, site authorization, configuration identity.
- Implementation: dashboard HTTP boundary, lifecycle service, Postgres store, schema migration.
Implemented boundary and authority
arbi.enrollment/1.0 is an app-owned device authentication boundary, distinct from human Gredice sessions and from arbi/1.0 actuator messages. This initial implementation admits only isolated test/preview simulation installations. Production rows, hardware provisioning, actuation, updates and recording are disabled. Cloud admission is a prerequisite for later command/state handlers; it does not override local edge policy, Pico stopping or pod interlocks, and it dispatches no actuator command.
Validated arbi.configuration/1.0 inputs supply stable physical component/assembly references, hardware revisions, configured firmware/update declarations, signal ownership and unavailable measurements. Provisioning copies only that inventory and its configuration/hardware identity, not private site geometry. Devices have separate immutable registry IDs. Reports retain observed software revision, applied configuration revision, declared capabilities, last-seen time, current boot/session identity and retired boot/session history. Configured inventory and device-reported observations remain distinguishable. Neither establishes physically verified installation.
Passive parts have no firmware, identity or credential. Drivers/peripherals remain inventory; this slice grants local identities only to Pico/pod modules. Driver-local encoders still provide no measured position/tension to Pico; unavailable signals retain their reasons and have no invented numeric readings. The service accepts capability reports only when they exactly match the configured metric/quality projection.
Human commissioning and recovery
The server selects configuration.write for mutations and diagnostics.read for inventory, using the accepted SiteRequestBoundary. Every request checks signed identity, current site/account membership, exact browser origin, CSRF request marker and durable authorization acknowledgement. Only a currently authorized human may commission or recover an edge. UI mode and service/delegated device credentials cannot grant that permission.
| Action | Method | Strict request body / behavior |
|---|---|---|
challenge |
POST | componentId, Ed25519 publicKey, expectedDeviceId, purpose; creates a 120-second challenge bound to realm, site, physical component, current configuration, human and session |
complete |
POST | challengeId, signature; requires the same current human/session and proof by the candidate device key; atomically consumes challenge, creates identity and records transition |
revoke |
POST | deviceId; revokes every credential and local descendant, retiring current boot/session identity |
inventory |
GET | Deliberate redacted projection, including historical devices and truthful component/signal inventory |
Initial purpose=enroll requires expectedDeviceId=null and an unused slot. Replacement and service-recovery require the latest predecessor's exact device ID and a new, never-used key. Factory reset has no anonymous enrollment bypass: an engineer must use the same fresh proof-bound recovery flow. Lost response/replayed completion cannot reissue a credential or recreate authority; a deliberate new recovery is required. Competing completions or replacement attempts cannot overwrite a later identity.
Replacement retains the physical componentId, predecessor/device/credential history and retired boot/session identities. It creates a new device ID and key binding; it never transfers the old credential. Replacing an edge also revokes delegated descendants. A new edge must deliberately delegate new local identities before reuse. Hardware/configuration changes need their separately authorized configuration workflow; this API does not silently revise hardware identity or calibration during replacement.
Device proofs, rotation and local delegation
Every device generates and retains its own Ed25519 private key. Only its canonical base64url DER/SPKI public key crosses the API. There is no shared fleet secret, private-key upload, reusable bearer secret or server signing key. Issuance returns opaque device/credential IDs, binding metadata and expiry only through completion/rotation/delegation responses. Diagnostics omit credential IDs and all keys/proofs. Public credential IDs are selectors, never authority by themselves.
Protected PostgreSQL key fingerprints have a global unique constraint within the cloud database, retained across rotation/revocation/replacement. Even a valid second site commissioning grant cannot reuse another identity's key; concurrent cross-site attempts cannot race this constraint. Separate environment databases/issuers and device-generated keys remain the deployment isolation requirement.
Device requests use POST device, with no browser origin or human Authorization header. Exact envelope fields are version, realm, siteId, deviceId, credentialId, sequence, issuedAtMs, expiresAtMs, action, payload, signature. Integers must be nonnegative safe JavaScript integers. Proof input is UTF-8 arbi-device-proof/1.0: followed by the canonical SHA-256 configurationDigest of the complete envelope excluding signature. The action, payload, realm/site, key selector, sequence and lifetime are therefore bound together. Requests expire within 30 seconds, cannot be future-issued and must increase the persistent sequence for that credential. The sequence is specific to this authentication envelope; it does not replace protocol stream counters.
| Device action | Exact payload | Result |
|---|---|---|
connect |
identity, previousIdentity, configRevision, softwareRevision, capabilities |
Reconciles a new boot/session with exact current predecessor and applied config; retired/same boot and stale reconnect cannot regain authority |
state |
identity, configRevision, softwareRevision, capabilities |
Admits authenticated inventory observations, without implementing telemetry history or device effects |
commands |
identity, configRevision |
Validates current command-consumer identity and returns an empty simulated command page; future jobs must remain behind this gate |
rotate |
identity, publicKey, overlapMs, newKeyProof |
Requires both existing and new keys, issues a separate credential and bounds predecessor expiry |
delegate |
identity, componentId, expectedDeviceId, publicKey, newKeyProof |
Requires current edge plus candidate-module proof; registers a new Pico/pod identity bound to that edge and physical module |
Use the committed enrollmentProof, rotationProof, delegationProof helpers for exact proof objects. A commissioning signature covers the full returned proof (including the server challenge). Rotation/delegation use separate proof purposes and bind the request sequence and candidate key; the edge also signs the full envelope containing that proof.
Credentials expire after 24 hours. Rotation overlaps are explicit from zero through five minutes; old expiry is shortened and never extended. A second rotation while two credentials remain active is denied. Historical keys cannot be reused. Revocation denies both overlapping credentials immediately on the next authoritative request. Expired credentials cannot rotate themselves; recovery needs a fresh current human grant and new device/key identity. There is no unattended recovery that bypasses revocation.
Local delegated identities have scope=local-module, a parent edge ID and no cloud permissions. Direct cloud connect/state/commands/rotation calls using a module credential are denied. This registry defines their trust binding; local transport/handshake and physical pairing are owned by #23, not implemented as a cloud actuator path here.
Persistence and failure behavior
The selected durable boundary is Neon PostgreSQL through server-side pooled pg connections. The app has an explicit migration and provisioning interface; no deployment secrets/default provider configuration or automatic fixture fallback exist. Unconfigured Next.js routes return redacted 503 responses.
An immutable (environment, namespace, site) primary key and SELECT ... FOR UPDATE serialize authority transitions across connections. The same transaction owns replay counters, consumed challenge, revocation/replacement, inventory updates and transition audit. Failed audit or state persistence rolls back the entire transition and denies admission. Statement/lock/idle transaction timeouts are bounded; the server's pool must also bound connection acquisition. Authorized inventory reads recheck membership and use protected storage. Errors contain only fixed codes/correlation IDs; raw bodies, key/proof material and provider exceptions are never logged or echoed.
The accepted audit 1.0 contract is used without expanding its action vocabulary. Every persisted audit event passes the bounded parseAuditEvent validator. Human authorization and device state/command admission use standalone authorization.check evidence. Successful registry policy operations record a correlated intent plus cloud service-outcome under authorization.check; a successful proof-bound connection uses identity.login. All have effect=none, and none claims actuator completion or local configuration activation. Detailed enrollment/rotation/replacement kinds remain in a separate redacted app-owned lifecycle journal, joined by the outcome event ID. This avoids putting undeclared fields or proof material into closed audit metadata. Authorization acknowledgement precedes the handler; lifecycle intent/outcome is committed atomically with the transition. Failed transitions create no successful lifecycle result.
The cloud emitter has a distinct process/boot/session identity and a site-scoped decimal-string uint64 audit sequence persisted with each event. Each new emitter boot starts a new stream; independent cloud instances do not share counters. A failed write can leave a visible source-sequence gap. This is an emitter stream counter, not a commit/recovery cursor; credential replay counters remain authoritative in PostgreSQL. Source UTC/uncertainty and collector receipt remain null because this slice has no calibrated UTC uncertainty or separate ingestion adapter; monotonic source time is available. Local lifecycle atMs is a server-clock observation, not proof of global chronology. There is no audit/export endpoint exposing protected registry keys, and adding one must use the same deliberate projections and current authorization.
Requests are limited to 16 KiB and a five-second body-read deadline. A site supports 64 configured components, 32 live challenges, 512 historical devices, 64 historical credentials per device, 512 retired boot identities per device and a 2 MiB registry. Capacity limits deny further writes rather than discarding revocation/replay history. Larger installations/history archiving require a reviewed migration; deleting a registry to recover capacity is not an authorized reset.
Evidence and limits
The lifecycle suite runs against embedded PostgreSQL/PGlite using committed synthetic configuration and ephemeral test-generated keys. It covers unauthorized/cross-site/session-bound enrollment, replay/competing completion, expiry, current membership/session revocation, wrong proof, signed request tampering, cross-realm/site credentials, bounded overlap and expiry, stale/reboot identity, stale configuration/capability claims, local-only delegation, passive inventory, descendant revocation, replacement/recovery history, redacted diagnostics/audit/errors, oversized requests and failed persistence. A file-backed restart verifies persisted revocation/history/replay sequence, not physical power-loss durability.
The separate host PostgreSQL suite, launched by pnpm --filter @arbi/dashboard test:postgres, starts its own temporary cluster with only a filesystem socket. Independent connections compete to complete one enrollment and mutate one revision; only one succeeds. An injected audit constraint verifies rollback with unchanged persisted authority; independent emitters have independently scoped sequences. Local execution used PostgreSQL 15.19; CI runs this test separately from the embedded suite. The Next.js route adapter is exercised through its Fetch request interface and the production build emits the mounted dynamic HTTP route. pnpm --filter @arbi/dashboard test:http starts a temporary loopback server from that build and verifies unprovisioned reads/commissioning return only a redacted, uncached 503.
Run owning lint/typecheck/test/host-Postgres/build plus pnpm docs:check, pnpm protocol:check and git diff --check. These are source and isolated host-prototype evidence. Live Gredice/Neon/Vercel setup, provider connectivity/restore, edge key storage, physical commissioning, OS corruption/power loss, firmware handshakes, installed operation and qualified safety review remain unverified. #28, #29 and #47 own later jobs/transport/cloud operations; this slice enables none of them implicitly.