ADR-0015: Protect Payloads at the External Object Boundaryπ
Statusπ
Accepted design; general-purpose external object offload is not implemented in the current source tree. The typed trace-artifact archive is separate.
Contextπ
Payload bytes stored in a third-party object service need application-level protection before they leave the owning service's trusted storage boundary. Database row security, transport encryption, and provider-side encryption do not make an external object service an authority for domain data or plaintext access.
Decisionπ
When ContextUnity implements external object offload, it encrypts payload bytes before writing them to an S3-compatible service. The external service stores ciphertext only. Local storage may use a separate explicitly configured posture; a prod-like path must not silently fall back to plaintext.
The payload and its reference have separate contracts:
- The payload is encrypted and integrity-checked.
- The reference contains bounded opaque location and protection metadata, not plaintext or long-lived key material.
- Tenant, project, purpose, and schema identity are bound to the protected object.
Invariant: An external object service never receives plaintext and never owns the tenant policy, encryption keys, or domain pointer.
Intended ownership boundaryπ
- Brain or the originating domain service classifies the payload, authorizes offload, and owns the durable logical pointer.
- Worker performs bounded streaming and object I/O. It does not select cryptographic policy, persist long-lived keys, or commit the domain pointer.
- Shield owns cryptographic authorization and key material. It does not perform object placement or own domain records.
- The external object service stores ciphertext and has no policy or pointer authority.
Required behavior if implementedπ
An offload implementation must validate source identity and bounds, protect bytes through an authorized Shield path, write to an operator-approved destination, verify ciphertext, and commit the logical pointer only after the owner validates a protection receipt. Ciphertext chunk authentication binds immutable payload identity (tenant, project, purpose, object_id, schema_version, chunk_index) under a per-object data-encryption key (DEK), while the signed receipt and reference carry (wrapping_key_epoch, wrapped_dek). Reads must reauthorize the logical reference and validate identity, wrapping-key epoch, receipt signature, and ciphertext integrity before returning bounded plaintext.
Routine wrapping-key (KEK) epoch rotation re-wraps wrapped_dek under the new wrapping_key_epoch and commits a newly signed protection receipt through the owner's version-checked pointer update without rewriting immutable object ciphertext; post-rotation reads must still authenticate and decrypt the existing ciphertext. Emergency DEK or object-compromise rotation writes and verifies replacement shadow ciphertext under a fresh DEK before the pointer owner performs a version-checked update, keeping the prior object and key epoch available until no live reference needs them. Object-addressing or deduplication does not replace the owner's pointer update.
Current implementation boundaryπ
The current source tree does not define production types or a caller for this general-purpose external object-offload design. No general-purpose encrypted external object reference or object protection receipt is implemented. Worker's S3TraceArtifactArchive uses S3-compatible storage for protected execution trace artifacts under a separate typed lifecycle; it does not implement this ADR's general-purpose flow.
Shield's live Encrypt and Decrypt RPCs protect typed execution trace artifacts through ProtectExecutionTraceArtifactRequest and UnprotectExecutionTraceArtifactRequest. They do not implement this ADR's external object workflow. See ContextShield Service Architecture and ADR-0014 for the current trace-artifact boundary.
Invariant: Documentation and callers must not treat this ADR's external object flow as a current API or runtime capability.
Alternatives consideredπ
- Encrypting every Brain record would change search and indexing behavior. This decision applies at the storage trust boundary.
- Object-service encryption alone would make payload protection depend on the object-service account and provider configuration. The decision requires application-controlled protection.
- Large plaintext objects over unary ContextUnit RPCs would exceed the intended transport and memory bounds. The decision uses bounded streaming.
Consequencesπ
- A future implementation needs source contracts, a production caller, configuration resolution, authorization checks, storage behavior, failure-path tests, and local/production parity before the offload flow can be described as implemented.
- The design applies to external object placement and does not change the live typed execution trace artifact protection path.
Non-goalsπ
- Encrypting ordinary Brain fields while they remain in Brain-owned storage.
- Selecting an object-store provider, deduplication scheme, backup policy, or tenant key model.
- Giving Worker durable key or domain-record authority.