Skip to main content

Module encrypted

Module encrypted 

Source
Available on crate feature encryption only.
Expand description

Encryption at rest for what a task carries.

EncryptedTaskStore wraps a TaskStore, sealing every part before the wrapped store sees it and opening it again on the way out (GDPR Art. 25(1) and 32(1)(a)).

§What is sealed

Every Part of a task’s history, its status message and its artifacts, and of every event in its log, is replaced by a sealed data part (see SEALED_MEDIA_TYPE) holding the whole original part — content, metadata, filename and media type — under an authenticated cipher. Each part is bound to where it is stored: the tenant partition, the task, the record or the log position, the message or artifact id, and its index there. A part that was altered, moved to any other such place, sealed under a key the cipher does not hold, or stored unsealed fails the read; nothing is returned unauthenticated.

§What is not

  • The structure around the parts, because the stores query it: task, context, message and artifact ids, roles, states, timestamps, artifact names and descriptions, message extensions and referenceTaskIds, and the metadata of tasks, messages, artifacts and events. Keep personal data out of those fields. Part counts and sizes are visible too.
  • The shape of a record. The binding covers each part, not the set of them: whole messages or artifacts reordered or removed, parts removed from the end of one, parts exchanged between two messages (or two artifacts) with the same id, or a store rolled back to an earlier record, all still open.
  • Push-notification configs, which live in their own store; with the sqlite or postgres feature, Aes256GcmCipher is also a PushConfigCipher for the SQL push-config stores’ with_cipher.
  • The audit trail (with_audit), which records a digest of each event as written, before sealing: a reader of the audit store can confirm a guess of a short event’s content, unless the audit log protects its records too (AuditLog::with_privacy, audit feature).

§Failures

A part that does not open fails the whole read: a list page holding it, and a subscription’s replay of the log it is in. Keep every key that sealed a stored value in the ring for as long as the value is stored.

Two replicas writing one task at once (which tests/multi_replica.rs shows can happen) used to leave the PostgreSQL store holding an artifact part at a position other than the one it was sealed for, and the record failed to read. The SQL stores’ appends are compare-and-append since 2026-10-18 (release audit F5), so a stale append is rewritten whole instead (tests/artifact_compare_and_append.rs).

§Cost

A write seals what it stores. An artifact or status delta first goes to the wrapped store’s try_save_artifact_delta or try_save_status_delta with only the parts that write stores sealed — the appended tail or the pushed artifact, and the status message — and every other part replaced by a placeholder that never opens; only if the store cannot write the delta in place is the whole task sealed and written. So an artifact streamed in n chunks costs n seals on the shipped stores (measured: 100 chunks, 100 seals; 5,250 before this, when every write sealed every part — release audit F7), and a store that does not override the try_ methods costs what every store did before. save and save_appending_history still seal the whole task.

Aes256GcmCipher refuses to seal past its limit (2^32 by default; see its nonce budget), so a write past it fails rather than risks a repeated nonce.

§Turning it on over existing data

A part written before the wrapper was installed is not sealed, and is refused. accept_unsealed_parts reads such parts as they are written, for migrating a store in place; while it is set, anyone who can write the store can plant an unsealed part that is read as genuine. Remove it once every record has been rewritten.

Structs§

Aes256GcmCipher
AES-256-GCM (NIST SP 800-38D) through ring, over a keyring: one active key seals, every key in the ring opens, so a key can be rotated without re-encrypting what is stored.
EncryptedTaskStore
A TaskStore that seals every part before the wrapped store holds it.

Constants§

AES_256_KEY_LEN
The length of an AES-256 key.
DEFAULT_SEAL_LIMIT
The most values one Aes256GcmCipher seals before refusing: 2^32, the bound SP 800-38D §8.3 sets for a key used with random 96-bit nonces.
MAX_KEY_ID_LEN
The longest key id, in bytes: its length is stored in one byte.
SEALED_MEDIA_TYPE
The media type of a sealed part.

Traits§

ContentCipher
Seals and opens part content for EncryptedTaskStore.