Skip to content

TC-3554 next release: root_wrap blob, remove epoch-0 runtime dependence (DO NOT MERGE) - #669

Closed
samgbafa wants to merge 7 commits into
mainfrom
feat/tc-3554-root-wrap
Closed

samgbafa wants to merge 7 commits into
mainfrom
feat/tc-3554-root-wrap

Conversation

@samgbafa

@samgbafa samgbafa commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

DO NOT MERGE. Draft. Nothing deploys from this PR.

Next node release for TC-3554: the node identity (KMS root epoch 0 app root) is sealed once in the database and opened from there on every later boot, so runtime no longer depends on the KMS serving epoch 0 or on the key-recovery sidecar.

Stacked on feat/tc-3554-restore-build (f835b52, 027cdfc, c59c10c are not on main); will be rebased onto main once #668 merges. The new work is the last commits below.

Commits

  1. 659ea844 feat(node): seal the epoch-0 root in root_wrap; transport optional once sealed
    • root_wrap(id SMALLINT PK CHECK id = 1, wrapped, node_did, kms_root_epoch, created_at), migration m20261120_000000_root_wrap (PG + SQLite, shared create_table()).
    • K_wrap = dstack GetKey("tinycloud/keys/primary-wrap") (current root). AES-256-GCM, random 12-byte nonce, AAD = "tinycloud/root-wrap/v1" || app_id || pinned DID. Keys and plaintext zeroized.
    • Boot (DstackKmsEpoch): parse pins → connect → CREATE TABLE IF NOT EXISTS root_wrap → read.
      • Absent: fetch through the transport with the full verifier → INSERT … ON CONFLICT DO NOTHING → re-read.
      • Present: no sidecar/KMS call, even if a transport is configured.
      • Then unseal → DID == pinned expected_did → EXPECTED_NODE_DID. Only after that do migrations and renewal_identity run.
    • No blob and no transport refuses with a clear message. Fail closed everywhere; never falls back to the current root as identity.
  2. c3454c45 deploy(compose): docker-compose.dstack-postgres.yaml, DstackKmsEpoch pins with no sidecar and no transport. Deploy only after a blob exists in prod. KMS_ROOT_PUBKEY is still the UNSET_ placeholder (P2).
  3. 49c3b65f fallback renewal_identity reset, reverted by f7887be0: renewal_identity still holds the original renewer, so there is no from-state; ruled off the deploy path. Net tree carries no reset code or config.

Ordering nuance

Deciding "blob present?" needs the database, so the first database action is connect + CREATE TABLE IF NOT EXISTS root_wrap + read, before the DID check. The ON CONFLICT DO NOTHING insert happens only after the fetched root passes the full verifier. Nothing else (other migrations, renewal_identity, any write) runs before the DID check. Integration tests assert the only table present after any refusal is root_wrap.

Risk

K_wrap comes from the current KMS root. If Phala rotates the root again, the blob stops opening and the node refuses to start. Recovery: delete the row and boot once with a transport (documented).

Verification (local)

  • cargo test -p tinycloud-node --features dstack --test kms_epoch_identity: 18 passed (new: sealed root boots without sidecar; tampered blob; unsealed other-DID ordering; no blob + no transport). The renewal-reset test was reverted with the fallback.
  • cargo test -p tinycloud-node --features dstack --lib: 1137 passed. --test sql_identity_cli: 1 passed.
  • cargo test -p tinycloud-core --lib: 1218 passed before the revert (root_wrap 7, of which the PG concurrent-insert test skips locally and runs on Actions).
  • cargo clippy -p tinycloud-node -p tinycloud-core --all-targets -- -D warnings: clean. With --features tinycloud-node/dstack it is clean apart from a clippy::items_after_test_module in routes/encryption.rs:874, which was already there and is untouched here (allowed for that run only).
  • cargo fmt --all --check: clean.

Test files touched (for the test-edit ruling)

  • tinycloud-node-server/tests/kms_epoch_identity.rs: changed existing tests.
    • assert_never_asked_for_a_key is now assert_never_asked_for_the_node_key. It allows only GetKey(tinycloud/keys/primary-wrap).
    • Fetch-failure tests check "only root_wrap exists, empty" instead of "database never opened". The did_mismatch_* tests are renamed …_before_any_other_database_write.
    • no_transport_configured_refuses_before_any_call is replaced by no_blob_and_no_transport_refuses_startup.
    • New tests: a_sealed_root_boots_without_the_sidecar, a_tampered_blob_refuses_startup_without_fallback and an_unsealed_root_with_another_did_refuses_before_any_other_write.
  • tinycloud-node-server/src/dstack_kms.rs (unit tests):
    • exactly_one_transport_must_be_configured is now at_most_one_transport_may_be_configured: no transport parses as None.
    • New tests: a_wrapped_root_opens_to_the_pinned_identity and a_wrapped_root_is_refused_unless_every_check_passes.
  • tinycloud-core/src/root_wrap.rs: new module with new tests.

test-ruling: TC-3554

Details: TC-3554

- keys.type = DstackKmsEpoch (dstack builds): RA-TLS client cert signed by the KMS temp CA
  (legacy quote/event-log extensions), GetAppKey for the pinned root epoch over TLS pinned to
  the KMS CA (leaf issued directly by it, special usage kms:rpc). Fail-closed checks before the
  database connects: root_epoch == pin and app_epoch == 0 (both required), low-S k256_signature
  by the pinned epoch root over keccak256("dstack-kms-issued:" || app_id || app_pub), derived
  node DID == keys.legacy.expected_did. No fallback to GetKey or another epoch.
- keys.expected_node_did (any key source): startup refuses another DID before the DB opens;
  resolve_identity_state refuses it for every caller, the control plane included.
- docs/tc-3554-kms-epoch-fetch.md: the protocol OpenKey mirrors (openkey #640).
- tests/kms_epoch_identity.rs: fake guest agent + fake KMS (epochs 0/1) against the real binary.
- backup_identity bails for keys.type = DstackKmsEpoch before resolving (no KMS fetch):
  the epoch-0 root is a migration bridge on an exposed KMS root, re-key instead of exporting.
- Covers the control-plane backup route (service.rs) through backup_identity.
…ecar

- keys.legacy.key_recovery_socket selects Phala's key-recovery sidecar (unix socket GET /v0/key, root_epoch pin, app_epoch=0); kms_url+kms_ca_cert keep the direct RA-TLS transport. Exactly one transport, no runtime fallback.
- Verifier on the sidecar answer: api v0, epochs present and pinned, public_key == pub(key), app_pub recovered from signature_chain[0], signature_chain[1] checked as the KMS issuance signature under the pinned epoch root, DID pin. The chain does not prove path->key; the DID pin does.
- Direct KMS GetAppKey now sends app_epoch 0 explicitly.
- Spec: transport A section, new vectors; fake-sidecar harness cases.
…ional once sealed

- root_wrap table (migration m20261120_000000_root_wrap, PG + SQLite): one row
  (id = 1), wrapped = nonce || AES-256-GCM(K_wrap, root), node_did,
  kms_root_epoch, created_at.
- K_wrap = dstack GetKey("tinycloud/keys/primary-wrap") on the current root;
  AAD = "tinycloud/root-wrap/v1" || app_id || pinned DID. Keys and plaintext
  zeroized.
- DstackKmsEpoch boot: parse pins, connect, CREATE TABLE IF NOT EXISTS
  root_wrap, read. Absent: fetch + full verify through the transport, insert
  ON CONFLICT DO NOTHING, re-read. Then unseal and check the DID against the
  pins, then EXPECTED_NODE_DID, before migrations or any other write. No
  blob and no transport refuses; no fallback to the current root.
- Tests: seal/unseal vector, tampered, wrong AAD, one-row + concurrent
  insert (SQLite, PG when available), DID mismatch after unseal, no blob +
  no transport, sealed root boots without the sidecar, tampered blob, and
  ordering (no migration / renewal_identity before the DID check).

Details: TC-3554
…EPLOY ONLY AFTER A BLOB EXISTS IN PROD)

DEPLOY ONLY AFTER A BLOB EXISTS IN PROD. This compose has no key-recovery
sidecar and no transport: the node opens its epoch-0 root from the database's
root_wrap blob, sealed by a boot of the sidecar compose (45de2e9), and
refuses to start while there is none. Pins unchanged; KMS_ROOT_PUBKEY is
still the UNSET_ placeholder (P2), so this compose refuses to boot until it
is filled in.

Details: TC-3554
keys.legacy.renewal_reset (TINYCLOUD_KEYS__LEGACY__RENEWAL_RESET__
{FROM_RENEWER_DID,FROM_EPOCH,TO_RENEWER_DID}), optional, unset by default.
After the identity checks and migrations, before TinyCloud initializes the
renewer identity, one transaction runs
  UPDATE renewal_identity SET renewer_did = to, epoch = 1
  WHERE id = 1 AND renewer_did = from AND epoch = from_epoch.
to_renewer_did must be the served root's renewer, or startup refuses. Any
other stored state is untouched and startup behaves as today. Logs only
whether it applied.

Tests: core exact-from-state / one-shot / other states untouched / epoch 0
refused; integration (wrong to-DID refuses and leaves the row, exact state
resets to epoch 1, other state bumps as before); config env parsing.

Details: TC-3554
…y reset"

This reverts commit 49c3b65.

renewal_identity still holds the original renewer (Sam's read, 14:44Z), so
there is no from-state to reset, and the reset is ruled off the deploy
path. No dead config path in this release.

Details: TC-3554
@samgbafa

Copy link
Copy Markdown
Contributor Author

Superseded by #670 (same work rebased onto main after #668 / v1.26.14; fallback dropped; compose lockstep). Left open as a draft for the lead to close. Details: TC-3554

@samgbafa

Copy link
Copy Markdown
Contributor Author

Superseded by #670 (same root_wrap work rebased on main 3f66adc / v1.26.14, renewal-reset fallback dropped). Details: TC-3554

@samgbafa samgbafa closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant