Skip to content

PhyCloud

PhyCloud is the trusted-data backplane of PhyWare — an append-only, cryptographically verifiable provenance store for autonomous-systems telemetry. Every event ingested by PhyCloud is sequenced, hashed with SHA-256 over a canonical JSON encoding, and linked into a tamper-evident chain that downstream consumers (the phyware CLI, PhyComp, the admin dashboard, custom audit tooling) can verify offline.

Canonical implementation

The canonical PhyCloud service is the Rust implementation under PhyCloud/rust/:

  • axum + tokio HTTP server, tower-http middleware.
  • sqlx async database layer (SQLite for dev, PostgreSQL for production) with embedded sqlx::migrate!() schema migrations.
  • argon2 password hashing, jsonwebtoken for JWT, tracing-subscriber for structured JSON logs.
  • Single static binary, small container image, no Python runtime.

The historical Python MVP was removed in

269, one release

cycle after the #218 cutover. Operators who still need to migrate should follow the operator migration guide.

Quick start

The repo-root docker-compose.yml now builds the canonical phycloud service from the Rust Dockerfile:

# Bring up Postgres + the canonical Rust PhyCloud service.
docker compose up -d phycloud

# Health check
curl -sf http://localhost:8000/health

For local development without Docker:

source SetEnv.sh
cd PhyCloud/rust
PHYCLOUD_AUTO_MIGRATE=true cargo run --release

Feature surface

Area Endpoints Notes
Health & readiness GET /health, GET /health/ready
Bootstrap POST /bootstrap, GET /bootstrap/status First-run super-admin key issuance
Events POST /api/v1/events, POST /api/v1/events/batch, GET /api/v1/events, GET /api/v1/events/{id} Append-only, hash-chained per tenant. Requires events:write to ingest, events:read to query
Sources GET /api/v1/sources, GET /api/v1/sources/{id}/latest, GET /api/v1/fleet/status Fleet rollups (collapses the 4N+1 dashboard round-trip). Requires sources:read
Authentication POST /auth/login, POST /api/v1/auth/password/*, POST /api/v1/auth/sessions/* JWT, API keys, password (argon2id), sessions
OAuth 2.0 POST /oauth/token, POST /oauth/introspect Federated PhyComp integration
Admin (tenants, keys, licenses) POST/GET/DELETE /api/v1/admin/{tenants,keys,licenses} Super-admin gated
Users POST/GET /api/v1/users/{invite,accept-invite,me,…} Invite-based onboarding
Evidence lockers POST/GET /api/v1/lockers*, POST /api/v1/verify Cryptographic evidence escrow
License validation POST /api/v1/admin/licenses/validate PhyTrace SDK license check
Data retention GET/PUT /api/v1/admin/tenants/{id}/retention, …/retention/run, …/legal-holds, GET /api/v1/storage, GET /api/v1/verify/archive Per-tenant hot-store retention with archiving to a data lake. See Data retention

Tenant isolation

Every /api/v1/events*, /api/v1/sources* and /api/v1/verify request must carry a Bearer API key or JWT. Each key belongs to one tenant, and a request only ever sees that tenant's events and sources. Each tenant's events form their own hash chain, so sequence numbers start at 1 per tenant and GET /api/v1/verify checks one tenant's chain. Each source (device) also has its own chain, so GET /api/v1/verify?source_id=… checks one device's events without gaps from the tenant's other sources. Event and source ids only need to be unique within a tenant.

Chain heads are stored in the database and advanced in the same transaction as each insert, so several PhyCloud instances can serve one database.

A full OpenAPI document is served at GET /openapi.json (and a Swagger UI at GET /docs) by the Rust service.

Provenance model

Each ingested event is tagged with:

  • ingested_at — server timestamp.
  • sequence_number — strictly monotonic ordering key.
  • content_hash — SHA-256 of canonical-JSON-encoded event payload.
  • previous_hash — the prior event's content_hash, forming a tamper-evident chain.
  • source_verified — the required envelope fields were present. This is not a cryptographic check.
  • signature_status / signer_key_id — the result of checking the event's provenance signature against the source's enrolled device key; see Devices.

PhyCloud also stores each event's place in its source's own chain (a per-source sequence number and the previous event's hash from that source). Events stored before source chains existed are not part of one, so a source's chain starts at its first event after the upgrade.

Trusted timestamps

ingested_at is PhyCloud's own clock. To prove when events existed without trusting that clock, PhyCloud can ask an independent RFC 3161 time-stamping authority (TSA) to sign a running digest of each tenant's events. Each timestamp covers every event since the tenant's previous timestamp:

chain_digest = H(... H(H(previous chain_digest || h1) || h2) ... || hn)

where h1 … hn are the events' content hashes in sequence order and the first timestamp starts from 32 zero bytes. Rewriting any covered event, even with its chain links repaired, changes the digest the TSA signed.

Setting Default Meaning
PHYCLOUD_TSA_URL unset TSA endpoint (application/timestamp-query). Unset: no timestamps
PHYCLOUD_TSA_CERTS unset PEM file with the TSA's signing certificate, or the CA that issues it. Required with a URL
PHYCLOUD_TSA_INTERVAL_SECS 300 Seconds between rounds. A round stamps only tenants with new events

PhyCloud checks every token before storing it: the request was granted, the hash and nonce match, the CMS signature is valid, and the signing certificate is trusted, was valid at the token's time and allows time stamping. Tokens are stored exactly as returned.

Method Path Scope Returns
GET /api/v1/verify/timestamps events:read The tenant's timestamps, newest first, with each token (base64 DER)
GET /api/v1/events/{event_id}/timestamp events:read The timestamp covering the event, a fresh check of its token, digest_matches (whether the stored events still give the signed digest), a walk of the covered events, and existed_by (the TSA's time) when all hold
POST /api/v1/admin/timestamps/run admin:tenants Runs a round now: {"stamped": n, "failed": n}

A token can also be checked without PhyCloud. It covers the timestamp's chain_digest; recompute that from the events' content hashes as above, then:

base64 -d token.b64 > token.der
openssl ts -verify -digest <chain_digest> -in token.der -token_in -CAfile tsa.pem

Signed evidence manifests

When an evidence locker is sealed, each copied event's signature, sequence and TPM attestation results are recorded with it, along with the periods its sources were offline or missing (heartbeat absences). GET /api/v1/evidence/{locker_id}/manifest returns them in a manifest that PhyCloud signs with an ES256 key:

  • What's signed: the canonical JSON of the manifest, without its signature member. The signature is hex r‖s.
  • Verification key: GET /api/v1/evidence/signing-key (public); its key_id is the hex SHA-256 of the DER public key.
  • Checking it offline: phyware cloud evidence verify-manifest manifest.json --public-key key.pem checks the signature, the Merkle root and the event count without calling PhyCloud.

Manifest version 3 (lockers sealed from issue #460 on) also lists the devices' public keys with their lifecycle, a received_hash of each event as its device sent it, and uses an RFC 9162 Merkle root, which fixes the order of events. Lockers sealed earlier keep their sorted-pairs root and still verify.

Set PHYCLOUD_MANIFEST_SIGNING_KEY to a P-256 PKCS#8 PEM private key, for example openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256. If the configured key can't be read, PhyCloud refuses to start. With no key set: - In dev mode: a per-process key is generated, so manifests can't be verified after a restart. - Otherwise: manifests are returned unsigned, with signature_error saying why.

Evidence packages

GET /api/v1/evidence/{locker_id}/package (or phyware cloud evidence package) returns the whole locker as one NDJSON file: the signed manifest, then every event as stored and, for signed events, exactly as the device sent it. PhyCloud keeps that copy for every signed event, including batch-signed ones, and seals it into the locker. The open verifier from PhyUDM checks a package without PhyCloud:

udm verify lk_abc123.evidence.ndjson --trust-key phycloud-manifest.pem

It checks the manifest signature against the key you pin, the Merkle root, each event's content hash and chain link, and re-checks every device signature itself, so an investigator, insurer or regulator does not have to trust PhyCloud's verdict. The format is PhyUDM's spec/evidence-package.md.

The Rust service emits bit-identical hashes to the legacy Python MVP for the same input — verified by replay-style compatibility tests in PhyCloud/rust/tests/provenance_compat.rs.

Architecture

flowchart LR
    A[PhyTrace SDK] -->|UDM events| B[PhyCloud — Rust]
    C[phyware CLI] -->|query / admin| B
    D[PhyComp] -->|fetch + introspect| B
    E[Admin dashboard] -->|browse + manage| B
    B -->|persist| F[(PostgreSQL / SQLite)]

Further reading

  • Operator migration guide — Python → Rust cutover steps.
  • PhyCloud/rust/README.md — canonical service README.
  • Password authentication — non-SSO login flow.
  • Data retention — policies, data lakes, legal holds and verification.
  • Migration epic #201 — historical context.
  • Cutover issue #218 — this release's tracking issue.