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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `/invoke`: a KV invocation that writes (`kv/put` or `kv/del`) and also reads (`kv/get`, `kv/list`, `kv/metadata` or `tinycloud.capabilities/read`) is refused with the same `501` as before, but now before any work: nothing is written and the signed request is not spent. Before, the write committed and only then was the invocation answered `501`, since `/invoke` returns one outcome. Internal callers that still mix the two get their reads after the write commits, holding no database transaction, row lock or write order. A `kv/get` answers the value the invocation wrote. If such a read fails, the error says the write was saved. Details: TC-2986.
- `POST /delegate` and `POST /revoke` check the signature (and, for a renewal lease, the signature of the stored original it renews) before taking any lock. A forged or slow-to-verify request no longer holds the delegation's chain guards, its spaces' write order or a database transaction while it is checked; it is refused at once. A renewal lease whose original is not stored is also refused before any lock. Inside the transaction only the signed time window is checked again. A resubmitted delegation that is already stored is now also signature-checked before it is answered as existing. Details: TC-2986.
- Add opt-in PostgreSQL checkpoint parts for SQL persistence, with explicit artifact/account capacities and streamed hydration. A database stored in parts loads in bounded statements and is not held to the single-row read limit (`storage.sql.max_artifact_read_bytes`); a load that keeps the whole database in memory (a DuckDB export) still waits for one of the large-transfer slots. Details: TC-2917.
- Policy/v3: minting a session and registering a policy no longer re-verify signatures or re-run the claim, presentation, credential admission and allow evaluations while holding their spaces' write order and row locks. Under the locks they check that the challenge, registration and roots are unchanged; those decisions were made before the locks, at the same time, from the same inputs. Refusal codes are unchanged, except that `credential-evaluation-changed` and `policy-evaluation-changed` can no longer occur. Details: TC-2986.
- SQLite stamp replay deadlines now use the same timestamp encoding as cleanup (TC-2920).
- PostgreSQL database artifacts use uncompressed external storage for new writes to avoid repeated decompression during chunked reads (TC-2917). Existing large artifacts require an operator re-toast; verify both storage settings after rollout and follow `scripts/tc2917-README.md` if lock contention deferred the migration.
- Encryption: v2 column format with key ids, per-purpose keys and recorded format metadata. Optional strict reads are off by default. Details: TC-2516, TC-2517.
Expand Down
32 changes: 30 additions & 2 deletions tinycloud-core/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2408,6 +2408,18 @@ where
&self,
tx: &DatabaseTransaction,
delegations: Vec<Delegation>,
) -> Result<TransactResult, TxError<B, K>> {
self.delegate_batch_in_transaction_verified(tx, delegations, &PreVerified::default())
.await
}

/// As [`Self::delegate_batch_in_transaction`], with the signatures
/// `verified` holds checked before `tx` opened (TC-2986).
pub async fn delegate_batch_in_transaction_verified(
&self,
tx: &DatabaseTransaction,
delegations: Vec<Delegation>,
verified: &PreVerified,
) -> Result<TransactResult, TxError<B, K>> {
if let Some(seed) = self.secrets.renewal_seed() {
let renewer_did = crate::renewal::renewal_identity_from_seed(seed).0;
Expand All @@ -2422,7 +2434,7 @@ where
));
}
}
transact(
transact_verified(
tx,
&self.storage,
&self.secrets,
Expand All @@ -2436,10 +2448,20 @@ where
&[],
self.delegated_sql_caveats,
self.named_keys,
verified,
)
.await
}

/// Check `delegation`'s signature outside any transaction (TC-2986), for
/// [`Self::delegate_batch_in_transaction_verified`].
pub async fn preverify_delegation(
&self,
delegation: &Delegation,
) -> Result<PreVerified, TxError<B, K>> {
PreVerified::delegation(&self.conn, delegation, self.encryption.as_ref()).await
}

pub async fn revoke(&self, revocation: Revocation) -> Result<TransactResult, TxError<B, K>> {
// TC-2986: the signature is checked before any lock.
let verified = PreVerified::revocation(&revocation).await?;
Expand Down Expand Up @@ -4321,13 +4343,19 @@ async fn stored_revocation_target<C: ConnectionTrait>(db: &C, target: Hash) -> R
/// signature never runs under a space lock. A hash names exact signed bytes,
/// so a check cannot carry over to other bytes.
#[derive(Default)]
pub(crate) struct PreVerified(HashSet<Hash>);
pub struct PreVerified(HashSet<Hash>);

impl PreVerified {
pub(crate) fn contains(&self, hash: &Hash) -> bool {
self.0.contains(hash)
}

/// Both sets of checked signatures.
pub fn union(mut self, other: PreVerified) -> Self {
self.0.extend(other.0);
self
}

/// Check `delegation`'s signature on `db`, outside any transaction; for a
/// renewal lease, also the signature of the original it renews.
pub(crate) async fn delegation<C: ConnectionTrait, S: StorageSetup, K: Secrets>(
Expand Down
Loading
Loading