Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]
### Changes
- Sign-out can retire the session key. `POST /session/retire` takes a UCAN the session `did:key` signs to this node, with exactly `tinycloud.session/retire` on `urn:tinycloud:session:self`, no proofs, a nonce, and an expiry no more than 120 seconds away. An optional JSON body `{"delegations": ["<delegation>", ...]}` carries up to 8 of the session's root delegations, each encoded as `POST /delegate` takes it in its `Authorization` header. **The client must send every root it holds for the session key, for all its spaces, including any it signed but never posted.** Each must be to the retiring key or the whole request is refused; each is admitted exactly as `/delegate` admits it, inside the retire, so the retire covers it and posting it later cannot bring the key back. A refused one answers `401 session_retire_invalid: delegation <i>: <reason>` and nothing is written. A carried root that has already expired is skipped and its index listed in `skipped`; one not valid yet is checked but not stored, and the retire lasts at least until it expires. It answers `200 {"did","retiredAt","recorded","expiresAt","skipped"}` (`skipped` only when non-empty); a repeat call answers the first `retiredAt`. `"recorded": false` (no `expiresAt`) means this node holds no live grant for the key and none was carried, so nothing was written. A bad request gets `401 session_retire_invalid: <reason>`, and more than `session_retire.rate_limit_per_minute` (default 10) requests per minute from one IP get `429`. Once retired, on this node:
- the key can no longer use any delegated authority (authority it holds as a root, over a space or network it owns itself, is not delegated and is unaffected);
- a delegation it signs that this node had not stored before the retire is refused;
- no renewal lease is registered and no renewal stamp is issued for a delegation it holds.

These refusals answer `401 session_retired: <reason>`. **Sign-out does NOT end the delegations the key made before it, or their descendants; they keep working until they expire. Revoke ends them.** Signed KV URL tickets and open hook streams the key obtained before the retire keep working for up to 300 seconds after it. A retire is recorded only when this node holds a live grant for the key (a delegation, renewal stamp or active renewal lease whose end is still ahead), counting the roots carried with it, so the route cannot fill the table. A retire is kept at least `session_retire.ttl_secs` (default 30 days; `0` refuses to start) and until the latest-expiring delegation, renewal stamp or active renewal lease this node holds for the key ends; a delegation without an expiry keeps it for good, and a delegation or lease to the key stored after the retire extends it. So the key never comes back while anything stored can still grant it authority. Expired rows are pruned. **Sign-out covers only the grants this node holds or was given in the request: a root the client does not send and this node does not hold is not covered**, and posting it later makes the key usable here again until it expires. The node stores only its own retires: **a host that starts hosting the space after the sign-out never gets the marker** and accepts the key until its session root expires (follow-up TC-3673). Adds the `session_retire` table and a nullable `delegation.first_seen_at` column, set when this node first stores a delegation; existing rows stay NULL and count as stored before any retire. Details: TC-3443.
- `POST /delegate` and `POST /revoke` refuse a validly signed request that has no standing, or is outside its signed time window, before taking any lock. Before, it took the guards of the delegation chain it cited, queued for the write order of the spaces it named and, on PostgreSQL, held a pooled connection in an open transaction until it was refused. Now it is refused at once:
- a delegation whose issuer has no applicable authority for its requested capabilities;
- a revocation by someone who may not revoke its target, or of a target that is not stored;
Expand Down
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The SDK checks this endpoint during sign-in and requires an exact protocol versi
| `POST` | `/signed/kv` | Yes | Create an expiring signed URL for an exact KV object read |
| `GET` | `/signed/kv/<ticketId>` | Signed URL ticket | Fetch a KV object, including single byte ranges |
| `POST` | `/delegate` | Yes | Create capability delegations |
| `POST` | `/session/retire` | Session-key UCAN | Sign out: retire the session key that signed the request |
| `GET` | `/peer/generate/<space>` | No | Generate space host key pair |
| `GET` | `/healthz` | No | Health check |
| `GET` | `/admin/stats` | `NODE_STATS_READ_TOKEN` bearer | Distinct owner addresses that hold data beyond automatic sign-in records and vault metadata (read-only; disabled unless the token is set, at least 32 bytes) |
Expand Down Expand Up @@ -271,6 +272,8 @@ The following common options are available:
| storage.staging | TINYCLOUD_STORAGE_STAGING | Set the mode of content staging, options are "Memory" and "FileSystem" |
| keys.type | TINYCLOUD_KEYS_TYPE | Set the type of host key store, options are "Static" |
| spaces.allowlist | TINYCLOUD_SPACES_ALLOWLIST | Set the URL of an allowlist service for gating the creation of Space Peers |
| session_retire.ttl_secs | TINYCLOUD_SESSION_RETIRE__TTL_SECS | Minimum seconds a `/session/retire` is kept; default `2592000` (30 days); `0` refuses to start. A retire also lasts until the latest-expiring delegation, renewal stamp or active renewal lease the node holds for the key ends (forever for a delegation without an expiry). |
| session_retire.rate_limit_per_minute | TINYCLOUD_SESSION_RETIRE__RATE_LIMIT_PER_MINUTE | `/session/retire` requests allowed per client IP per minute; default `10`. Over it answers `429`. |
| spaces.registry_v2 | TINYCLOUD_SPACES__REGISTRY_V2 | Optional signed registry v2 origin for current per-space hosting authorization and read/write mode |
| spaces.registry_cache_max_age_seconds | TINYCLOUD_SPACES__REGISTRY_CACHE_MAX_AGE_SECONDS | Seconds the last confirmed registry record keeps admitting reads and writes during a registry outage; `0` (default) turns it off, at most `300`, requires `registry_v2` |
| telemetry.enabled | TINYCLOUD_TELEMETRY__ENABLED | Enable Prometheus latency metrics on the configured Prometheus port |
Expand Down Expand Up @@ -455,6 +458,58 @@ If the TinyCloud Protocol instance is not able to find or establish a connection

TinyCloud Protocol is most easily used via the TinyCloud Protocol SDK. See the example DApps and tutorials for detailed information.

### Sign-out: `POST /session/retire` (TC-3443)

A client signs out by retiring its session key. It sends an
`Authorization: Bearer <UCAN>` header (the `Bearer ` prefix is optional). The
UCAN is issued by the session `did:key` (bare or with a `#fragment`) to this
node's DID, carries exactly
`{"urn:tinycloud:session:self": {"tinycloud.session/retire": [{}]}}`, cites no
proofs, has a nonce, and expires no more than 120 seconds from now.

The optional JSON body `{"delegations": ["<delegation>", ...]}` carries the
session's root delegations (at most 8), each encoded exactly as
`POST /delegate` takes it in its `Authorization` header. **The client must
send every root it holds for the session key: one per space, including any
it signed but never posted.** Each must be to the retiring key, or the whole
request is refused. Each is admitted as `POST /delegate` admits it, inside
the retire, so the retire covers it and posting it later cannot bring the
key back; one already stored is fine. If any is refused, the request answers
`401 session_retire_invalid: delegation <i>: <reason>` and nothing is
written. A carried root that has already expired is skipped (it can never be
posted) and its index is listed in `"skipped"`. One not valid yet (its
`nbf` is ahead) is not stored, but its signature and issuer are checked and
the retire lasts at least until it expires.

The node answers `200 {"did": "<did:key>", "retiredAt": "<RFC3339>",
"recorded": true, "expiresAt": "<RFC3339>", "skipped": [<i>, ...]}`
(`skipped` only when an expired root was skipped); a repeat call answers the first
`retiredAt`. `"recorded": false` (and no `expiresAt`) means this node holds no
live grant for the key and none was carried, so nothing was written. A bad
request answers `401 session_retire_invalid: <reason>`; too many requests from
one IP answer `429`. From then on, the key can no longer use any delegated
authority, a delegation it signs that this node had not stored before the
retire is refused, and nothing it holds is renewed. These answer
`401 session_retired: <reason>`. Authority the key holds as a root (a space
or network it owns itself) is not delegated and is unaffected. Signed KV URL
tickets and open hook streams obtained before the retire keep working for up
to 300 seconds after it.

A retire is recorded only when the node holds a live grant for the key (a
delegation, renewal stamp or active renewal lease whose end is still ahead),
counting the roots carried with it. It lasts at least
`session_retire.ttl_secs` and until the latest-expiring of those grants ends,
so it never lapses while the key still holds one; a delegation without an
expiry keeps it for good.

Sign-out covers only the grants this node holds or was given in the request.
**A root the client does not send and this node does not hold is not
covered:** posting it later makes the key usable here again until it
expires. Sign-out does not end the delegations the key made before it, or
their descendants; Revoke ends them. A node that starts hosting the space
after the sign-out does not know about it and accepts the key until its
session root expires (TC-3673).

### UCAN DID verification (TC-1080, TC-1500)

The node verifies a UCAN signature only when it derives the signer's key
Expand Down
28 changes: 28 additions & 0 deletions docs/delegation-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,34 @@ support. On the same `utf8mb4`/default-strict configuration, unmodified
alias migration exists. That separate full-schema prerequisite must be resolved
and exercised before claiming end-to-end support for that configuration.

## Sign-out: Retiring the Session Key (TC-3443)

Signing out posts `POST /session/retire` with a UCAN the session key signs to
the node (`tinycloud.session/retire` on `urn:tinycloud:session:self`, no
proofs, expiry within 120 seconds). Its optional body
`{"delegations": [...]}` carries the session's root delegations, each encoded
as `POST /delegate` takes it; the client must send every root it holds for
the key, for all its spaces, posted or not. Each must be to the retiring key,
and each is admitted exactly as `/delegate` admits it, inside the retire's
transaction, so the retire covers it and posting it later cannot bring the
key back; any refusal writes nothing. The node records the key and the time
only when it then holds a live grant for the key, and says so
(`"recorded"`); a node holding none records nothing. After that, the key can
no longer use any delegated authority, and any delegation it signs that the
node had not stored before the retire answers `401 session_retired:`.
Authority the key holds as a root (a space or network it owns itself) is not
delegated and is unaffected. The record lasts at least
`session_retire.ttl_secs` and until the key's latest-expiring delegation,
renewal stamp or active renewal lease ends. Each delegation records when the
node first stored it (`first_seen_at`), so a child that raced the retire is
refused at invoke. Children the key made before the retire, and their
descendants, keep working until they expire; revoking them ends them.
Sign-out covers only the grants the node holds or was given in the request:
a root the client does not send and the node does not hold is not covered.
Only the nodes that served the retire know about it: a node that starts
hosting the space later accepts the key until its session root expires
(TC-3673).

## Child Delegation (UCAN) Creation

For sharing, child UCANs are created that delegate from the session key to another DID.
Expand Down
1 change: 1 addition & 0 deletions test/w5-policy-runtime-node-e2e/tests/sql_isolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ async fn persist_grant(
facts: Set(None),
serialization: Set(format!("tc780-n1-test-row:{ability}").into_bytes()),
serialization_format: Set(0),
first_seen_at: Default::default(),
}
.insert(conn)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ async fn persist_grant(
facts: Set(None),
serialization: Set(format!("tc119-test-row:{ability}").into_bytes()),
serialization_format: Set(0),
first_seen_at: Default::default(),
}
.insert(conn)
.await?;
Expand Down
Loading
Loading