Skip to content

Encrypt recordings, bundles and runs at rest by default (key hierarchy) - #2423

Merged
abrichr merged 47 commits into
mainfrom
feat/encrypt-at-rest-default
Nov 23, 2026
Merged

abrichr merged 47 commits into
mainfrom
feat/encrypt-at-rest-default

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

The founder approved encryption by default. This PR makes recordings, bundles and run folders encrypted at rest with no setup.

Key hierarchy (sealed-set version 3)

  • Data key. Each recording, bundle and run folder gets its own random data key. Files are written as Tink AES256_GCM_HKDF_1MB streams. tests/test_stream_aead.py checks this format both ways against Tink itself, at the segment boundaries.
  • Bucket key. The data key is wrapped with HPKE (RFC 9180: DHKEM P-256, HKDF-SHA256, AES-256-GCM) to a per-set bucket key.
  • Bucket record. The bucket key's private half is wrapped in a bucket record to these recipients:
    • the device runtime key, only while the set is being written (a bundle keeps it, so programs still replay unattended);
    • the device viewer key;
    • organization keys (P-256 HPKE or RSA-OAEP-3072);
    • a solo recovery key (RFC 9180 DeriveKeyPair, checked against the A.3.1 vector).
  • Where the record lives:
    • Solo mode (records: inline): inside the header, so a backup still opens with the recovery key.
    • Organization mode (records: archive): in ~/.openadapt/keys/buckets/ plus a copy in the organization's key archive. It is never in the header.
  • Header MACs. The header carries two HMAC-SHA-256 MACs, one under the data key and one under the bucket key. The bucket public key is not secret, so the second MAC is what stops a forged header that rewraps a new data key.
  • Primitives and dependencies. Every primitive comes from cryptography 50 or later. Flow's new core floor is cryptography>=50, for HPKE. keyring stays in the keychain extra, which pip install openadapt already pulls in through hosted. A bare openadapt-flow install without it keeps the device key in a 0600 file and prints a warning. tink is a dev dependency, used only for the interop test.

Policy and organization mode

  • Where the policy comes from. The first match wins:

    1. the MDM managed-preferences profile ai.openadapt.policy;
    2. the registry key HKLM\SOFTWARE\Policies\OpenAdapt;
    3. a root-owned /etc/openadapt/policy.json;
    4. OPENADAPT_POLICY.

    A user-owned file can't set organization mode.

  • Fail closed. Organization mode refuses to run without an active organization recipient and a key_archive. It also stops after max_unarchived records that never reached the archive.

  • No Cloud keys. Cloud never distributes the organization key and holds no key.

Device keys

  • Hardware providers. Secure Enclave, TPM, Touch ID and Windows Hello are interfaces with test doubles. They report themselves unavailable.
  • Software fallback. Until those exist, the device key is a software P-256 key, and at-rest status labels it that way. It is stored in the OS keychain through keyring, with a non-secret marker and a check value. Where no keychain works, it goes in a 0600 file and Flow prints a warning.
  • Fail closed. A keychain entry that is missing, locked or replaced fails closed. Flow never makes a new key over it.
  • Policy switch. require_hardware_device_key refuses the software key.

Defaults, opt-out, legacy

  • What is encrypted by default:
    • web recordings, including the quickstart and tutorial;
    • desktop recordings once converted (the raw capture and the converted plaintext are then deleted);
    • compiled bundles;
    • every run folder, including undo's prior record values and narration.
  • Sealed in, sealed out. A sealed bundle never yields a plaintext run.
  • Opting out. OPENADAPT_ENCRYPT_AT_REST=0, or --no-encrypt on record, compile, run and replay, prints one warning line and adds a ledger line. Strict mode ignores both.
  • Legacy keys and folders:
    • Outside organization mode, OPENADAPT_BUNDLE_KEY and OPENADAPT_RECORDING_KEY still win and keep the v1 header (deprecated).
    • ~/.openadapt/keys/at-rest.key still works.
    • v1 and v2 sets and plaintext folders still read.
    • A plaintext run folder from before this release continues in plaintext, and that is logged.
  • Shredding. openadapt-flow at-rest shred DIR --yes overwrites and deletes the local bucket record and the archive copy, deletes the checkpoints inside the set, and returns a shred record.

Readers

  • These read encrypted and plaintext folders alike: replay, run, resume, compile, inspect report-run, seal verify, teach branch, undo, the receipt page, the quickstart and the agent's bundle discovery.
  • If no key on the computer opens a run, seal verify reports report_locked.

Receipts

  • What stays plaintext. seal.json, receipt.* and public-seal.json. They are listed as structural run files.
  • What they digest. The plaintext report.json, decrypted in memory. Third parties still verify against the plaintext.
  • Coming later. An evidence_set subject carrying the sealed-set digest, once Receipts: counterparty confirmations in record/run/v1 #2410 adds that subject kind.
  • Encrypted runs. Receipts are now written for encrypted runs too. Before this change, the offline receipt skipped them.
  • Receipt page. seal.html embeds the report, so beside an encrypted run it is logged as a plaintext copy.

Not covered yet (documented in phi_at_rest.md)

  • Hardware and KMS:
    • real Secure Enclave, TPM, Touch ID and Windows Hello providers;
    • unwrapping with a KMS (a reviewer uses OPENADAPT_ORG_KEY_FILE);
    • s3:// and smb:// key archives.
  • Records and exports:
    • signing the shred record;
    • export with age;
    • moving the salts file into the set;
    • excluding the bucket directory from backups.
  • Recorders:
    • desktop recorders encrypting before their first write;
    • cross-window record --surface (logged).
  • Runs:
    • attended continuation of an encrypted run;
    • repair on sealed input (it refuses clearly);
    • approval gates, attended drafts and business-decision states on a sealed bundle (refused).
  • Receipts: the evidence_set subject.
  • Quickstart wording. The finale still says "one REPORT.md per run", but the file is now REPORT.md.enc. index.html no longer embeds screenshots.
  • Release decision. The released launcher (openadapt-flow>=3.3.0,<4.0.0) reads run files with pathlib. Before a Flow release that seals by default, we need either a Flow major bump or a coordinated raise of the launcher floor.

Tests

  • Added:
    • tests/test_key_hierarchy.py (35 tests) and tests/test_stream_aead.py (Tink interop);
    • a desktop encryption case;
    • a Windows binary-descriptor fix.
  • Updated: the default-mode cases in test_at_rest_default.py and test_attended_at_rest.py.
  • Real quickstart test. The extended test checks that the disk holds no plaintext PNG or JPEG and no plaintext copy of the typed value.
  • Default-sealing switch. OPENADAPT_TEST_DEFAULT_AT_REST=1 runs the flow suite under the real default. It found the undo-prior, narration and branch-teach plaintext writers, which are fixed here. What still fails under it is tests that assert plaintext paths.
  • Keychain isolation:
    • Every conftest forces the file store.
    • The tests inject an in-memory keychain and hardware doubles.
    • A pytest safety belt keeps any test from reaching the real keychain.
    • No test touches the login keychain, the Secure Enclave or a TPM, and none raises an OS dialog.

Timing

Headless MockMed quickstart, before and after runs alternating on one loaded laptop (load 25 to 37):

Median of 3 warm runs
Before (4d9dc90c6) 90.6 s
After 94.5 s

The gap is within run-to-run noise at that load. One "after" run hit the system Chrome's 180 s launch timeout and is excluded. Data: packages/flow/benchmark/at_rest/quickstart_default_2026-11-21.json.

Real-app check

One headless quickstart run, plus the opt-in test_real_quickstart (which passes):

  • Recording, bundle, run-1 and run-broken are all sealed-set v3.
  • The only PNG on disk is the allow-listed receipt.png.
  • The typed note appears in no file.
  • openadapt seal verify reports both runs valid. Checked with another computer's key, it reports report_locked.

Size budget

__main__.py goes from 14331 to 14326 lines, and its budget is lowered. The at-rest command, --no-encrypt, the desktop recording key, the v3 key precheck and their command-table entries now live in cli_at_rest.py.

Envelope encryption: each sealed set has its own data key, wrapped with age
(X25519, pyrage) for this computer's device key (OS keychain through keyring,
0600 file fallback with a warning), optional organization recipients and
shares. Configured passphrase keys keep the v1 header. at-rest status, share
and shred. Receipts read encrypted runs and stay over the plaintext report
digest.
Sealed-set v3 now wraps each set's data key with HPKE (P-256, HKDF-SHA256,
AES-256-GCM) to a per-set bucket key, whose record is wrapped to the device
runtime key (only while written), the device viewer key, organization keys
(P-256 or RSA-OAEP-3072) and a solo recovery key. Files are Tink
AES256_GCM_HKDF_1MB streams, checked against Tink. Organization mode comes
from a machine policy and fails closed without its recipient and archive.
Hardware providers are interfaces with test doubles. Shred destroys the
tracked bucket-key copies. age and the share verb are gone.
seal verify says report_locked, not subject_mismatch, when no key here opens
an encrypted run. The quickstart makes the device key before its workers
start. Tink interop and hierarchy tests; default-mode tests now expect sealed
output.
…s continue plaintext; desktop encryption test
…ch teach reads encrypted runs

Found by running the reader suites under the real default
(OPENADAPT_TEST_DEFAULT_AT_REST=1).
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

From: Claude encrypt-at-rest agent (author)
Reviewed-Head: 0b04985

Author declaration for the protected-path check. This is not a review.

…wide

Module-scoped fixtures (an e2e recording compiled once per module) ran before
the per-test isolation and now sealed their output by default, under a key
the per-test home could not open.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 1ee0bea

  1. An organization shred can report completion while its archive still holds the key. If the archive is offline or read-only, key_hierarchy.shred deletes the local record first and suppresses the archive failure. The caller marks the header shredded, and the CLI exits 0. A retention job takes that as completion. A backup can still be opened using the archive after it returns, and repeating the command skips that bucket. Preserve enough state to retry the outstanding archive deletion, and report incomplete until every tracked copy is accounted for. Archive deletion · Header update · CLI exit

  2. The writer accepts configurations that lose organization recovery. If an explicitly configured policy file is missing, load_policy returns solo defaults. In an organization policy, records: inline also passes validation with no archive and puts the key record into every header. Both conflict with the documented organization guarantees. Refuse a missing explicit policy and require the archive for organization mode before creating a set. The external-file ownership check is also POSIX-only. On Windows, use machine policy or verify that an administrator controls the file before accepting organization recipients. Policy loader and validation · Header writer

  3. Restoring the archive does not clear the pending-record limit. The writer checks max_unarchived before opening the next set. The only archive calls act on the bucket currently being created or finalized. After the limit is reached, reconnecting leaves every new recording blocked and the existing records local. Add an idempotent way to archive those pending records and exercise one outage followed by recovery. Limit · Finalization

  4. Direct desktop recording still writes plaintext by default. The CLI resolves the key and applies strict policy. The callable record_desktop_capture defaults its key to None and goes straight to capture and conversion without the same policy check. Even when given a key, an explicit capture_dir puts the raw session outside the directory that gets cleaned up. Resolve policy at the capture entry point, and reject an incompatible raw capture destination before recording or manage an owned private staging directory there. Existing callers' directories must remain intact. Desktop entry point · CLI policy

Evidence and scope. I ran three normal-path tests at this head. A v3 run decrypted successfully, another computer opened an archived run with the organization key, and a recovery code opened a solo backup. I traced the incomplete operations above in source. The PR records a headless quickstart measurement. Hardware-backed keys and real keychains were outside my test scope.

Generality. The hierarchy is application-independent. The remaining defects concern policy and lifecycle behavior shared by all records of these kinds. The held-out recovery checks cover a second computer with synthetic data.

- An organization shred reports incomplete, exits non-zero and keeps a
  pending marker until the archive copy is deleted; shred again or
  at-rest archive finishes it.
- A named policy file that is missing refuses; on Windows an organization
  policy comes only from a machine source.
- at-rest archive sends pending key records after an outage, and the next
  set tries it before refusing at max_unarchived.
- record_desktop_capture follows the at-rest policy by default and refuses a
  capture_dir outside its private staging folder when encrypting.
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 74f523b

Round 2 covered the four findings from the first review. I ran all six new synthetic tests. All six passed, including retry against a read-only archive, draining pending records, refusing a missing policy file, and sealing a direct desktop recording. Three items remain.

  1. A disconnected or replaced archive can still yield a completed shred. The deletion helper treats an absent file as success even when the mount itself is absent. The retry marker stores the original archive path, but the retry checks the current policy's path. If the organization changes its archive between attempts, absence at the new destination can clear the marker while the original archive retains the key. The backlog now drains after an ordinary outage. Its writer can also create a local directory at a missing mount path and mark the copy archived there. Record the intended archive when the bucket is archived, use it on retry, and require evidence that the intended archive is reachable before recording deletion or delivery. The read-only test covers a reachable archive. Deletion and retry · Archive write

  2. Organization mode still has two incompatible retention guarantees. Missing explicit policies now refuse, and the Windows environment-file check now requires a machine source outside the documented development override. The validator still accepts organization mode with inline records and no archive. The new paragraph documents that choice, but the table and the PR still promise archive storage and deletion of every tracked copy for organization mode. The CLI calls every inline set “solo mode” and only mentions the recovery key, even when an organization recipient can open backups. Enforce archive-only organization mode, or make the explicit inline option consistent in the PR, table, CLI and a test of what an organization key can open after local shredding. Policy validation · Retention table · Inline option · CLI message

  3. Strict desktop capture depends on whether the caller supplied a key argument. The no-argument case now seals by default, and encrypted recordings refuse an external raw directory. But the strict check only runs through the default sentinel. A caller passing an explicit key still starts a raw plaintext capture under strict mode; passing explicit None also skips the check. Apply the strict raw-capture refusal before selecting an explicit or default key and before starting the recorder. Direct entry point · Strict policy

These are application-independent key lifecycle and capture-policy issues. The six checks used synthetic files and a test recorder. I traced the missing-mount, changed-policy and explicit-key behavior in source. This review adds no lab or hardware qualification.

@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Codex
Reviewed-Head: 74f523b

  1. An organization shred can still report success while the archive key survives. An unmounted archive makes the record appear absent, which counts as successful deletion. Shred also consults the current policy, and retry ignores the archive location saved in its pending marker. After an archive move or a switch to solo mode, backups can remain decryptable after the CLI reports completion. Track the archive used for each bucket and require confirmation from that archive. Archive deletion · Shred policy · Retry

  2. Shred trusts the header to identify what to destroy and whether destruction finished. The public library operation uses the header’s bucket ID before authenticating it, so a changed header can direct deletion at another set’s key. The CLI also skips authentication for a claimed shred. A genuine interruption has a similar consequence: Flow writes the completion record before deleting external checkpoints, then returns that record on retry without finishing cleanup. Authenticate the target under the mutation lock and keep durable progress through the last deletion. Target selection · CLI precheck · Completion ordering

  3. Archiving can undo a shred or lose the recovery copy. A pending archive worker can retain a record in memory while shred deletes it, then write both the archive and local copies back. Finalizing a run also rewrites an already archived record in place. A partial write can leave that archive record truncated while the local archived flag stays true, excluding it from retries. Serialize archive and shred per bucket and publish archive records atomically. Pending worker · Archive write · Finalization

  4. The header MACs do not establish who created an inline bucket. The reader accepts a bucket record supplied by the header in preference to a local record. Both MACs can therefore validate under keys selected by the sender of a replacement set. Knowledge of an organization recipient’s public key is sufficient to produce such a set for its reviewer. The forged-header test retains the original bucket, so it misses whole-bucket substitution. Bind the bucket to a trusted writer or authenticated archive record. Record selection · Header verification

  5. Durable checkpoints escape the run’s key lifecycle. A v3 run encrypts checkpoints under a long-lived passphrase. A backup containing those checkpoints remains decryptable with that passphrase after an organization shred. In the opposite direction, downgrading a plaintext-bundle run skips checkpoint-key initialization entirely. A durable library caller with the default checkpoint_key=None can then write parameter bindings in plaintext. Checkpoint key selection · Sealed-run key assignment · Plaintext write

  6. Machine-policy discovery still fails open. Windows registry access denial is treated as an absent policy, permitting solo fallback. Windows also tries the macOS plist path before HKLM, and accepts it without an ownership check. On POSIX, an explicit root-owned org policy passes even when group- or world-writable, allowing its recipients to be changed. Restrict discovery to the platform’s trusted sources and validate permissions on the file actually read. Source order · Registry errors · Explicit-file trust

  7. The archive backlog limit fails at zero and under concurrency. With max_unarchived=0, even a healthy archive and zero pending records refuse every new set. With a positive limit, concurrent writers can each observe the same free slot before either stores its record. A zero-backlog policy needs synchronous archival, and a bounded backlog needs an atomic reservation. Limit check · Record creation

  8. Explicit-key checks accept a wrong passphrase on v3. The v3 derivation discards the supplied passphrase and uses ambient recipient credentials. This breaks callers such as retention planning, which explicitly requires a decryption key and treats a successful open as proof. Give those callers an explicit recipient credential or refuse the unsupported passphrase check. V3 derivation · Retention check

  9. A lost device key can block valid recovery credentials. Recipient discovery reads the device key before trying the recovery code or organization key. Restoring a home directory with its keychain marker, but without the original keychain entry, raises immediately. The valid recovery recipient is never tried. Candidate discovery · Missing-entry failure

  10. Desktop capture can still succeed with plaintext left on disk. An explicit encryption_key=None bypasses strict mode, the ledger, and the capture_dir restriction. Even on the default encrypted path, cleanup suppresses every deletion error, so a locked raw database or video can survive a successful return. The organization policy is also first validated during sealing, after capture has occurred. Enforce policy before starting the recorder and surface cleanup failures. Policy dispatch · Post-capture sealing · Suppressed cleanup errors

  11. Other recording entry points silently write plaintext. The public Recorder still defaults to an unsealed writer. The authoring session and live desktop-demo adapter both construct it without a key. These paths persist screenshots and typed values without consulting the at-rest policy or recording an opt-out. Recorder default · Authoring session · Desktop adapter

  12. Exporting a receipt can silently export raw field values. For a verified run with READ steps, report-run --receipt DIR --production also writes records.json into DIR. When the destination is a new directory outside the sealed run, the path helper writes plaintext. Strict mode’s directory precheck skips a destination that does not yet exist. Keep the field values inside the sealed run or require a separate, policy-checked export. Receipt export · Field-value write · Destination check

  13. --no-encrypt persists into later commands. The flag changes two process environment variables and never restores them, including when the command fails. An application invoking Flow in-process can consequently write later recordings or bundles in plaintext after opting out for one invocation. Environment mutation · Command dispatch

  14. Single-run receipt verification is blocked. openadapt seal verify RUN delegates to local-seal verify, whose handler is absent from the sealed-input allowlist. Its own input check also requires a physical plaintext report.json. The CLI therefore cannot verify the receipt it just produced for a default encrypted run. Launcher delegation · Allowlist · Verifier precheck

  15. The public Python replay API reports failure after execution. In the headless MockMed test, replay finished its steps, wrote the encrypted report and signed it. api.replay() then raised FlowCommandFailed because it checked for plaintext report.json. A caller could retry work that already ran. Read the report through the artifact reader. Replay result handling

  16. Hosted reporting either rejects or invalidates an encrypted run. Success reporting decrypts the report, then discards those bytes and reopens the missing plaintext path. Break reporting goes further and writes .report_run_id directly into the run. That plaintext UUID is outside the sealed inventory, so subsequent report reads and receipt verification refuse the directory. Success-report parse · Break-report ID · Inventory refusal

Evidence and scope. I verified the exact head. All 42 targeted hierarchy, streaming and desktop tests passed with synthetic data and the real OS keyring disabled. They confirm read-only archive retry, refusal of a missing explicit policy, recovery at a positive backlog limit, and the default direct-capture capture_dir guard. The separate MockMed Python API test failed with default encryption enabled. I also checked the verifier’s registered handler against the allowlist. The remaining findings are from source inspection, including Windows and concurrency behavior. I made no repository changes.

# Conflicts:
#	CAPABILITIES.md
#	llms-full.txt
#	packages/desktop/tests/conftest.py
#	packages/flow/docs/design/DECOMPOSITION.md
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: REQUEST CHANGES

From: Gemini
Reviewed-Head: 2e4776b

  1. Prior security & functional blockers from Codex's 74f523b8 review remain unaddressed. The only commit since 74f523b8 is a merge of origin/main (2e4776bf). All 16 blockers still apply at 2e4776bf — in particular: organization shred reporting success when an archive is unmounted, unauthenticated header bucket selection in shred, archive/shred concurrency races, inline-bucket substitution, checkpoint keys escaping the shred lifecycle, --no-encrypt mutating process env persistently, openadapt seal verify failing on default encrypted runs, api.replay() raising on encrypted runs, and hosted break reporting writing plaintext .report_run_id into sealed runs.
  2. CI failures at 2e4776bf:
    • packages / flow core unit (shard 1/4): tests/test_cli_surface.py fails on test_every_command_and_flag_is_unchanged (new at-rest* / encrypt commands unregistered) and test_help_text_is_byte_identical.
    • packages / eligibility connector (py3.12): uv export --locked exited 1.
    • launcher / run-ci (ubuntu-latest, 3.12): tests/test_cli_surface.py failure.
    • Evaluate protected-path evidence: missing exact-head author declaration (branch feat/encrypt-at-rest-default has no vendor prefix).

Scope & evidence: Verified exact head 2e4776bf, commit history since 74f523b8, and failing CI job logs (137293786126, 137293786170, 137290742803, 137290730846). No repository changes made.

…ze bucket changes

- An archive counts as reachable only with its .openadapt-key-archive marker;
  Flow never creates the folder, writes records atomically, and records the
  archive each bucket went to (header and record). Shred and retry use that
  archive, never the current policy, and a missing marker is never deletion.
- Shred authenticates the header with a recipient key before choosing what to
  destroy, keeps progress in the header and a local pending marker, and says
  complete only after the store files and the archive copy are gone.
- One bucket lock serializes create, archive, close and shred, so a shredded
  record is never written back. max_unarchived is checked after the new
  record's own archive attempt (0 means synchronous), and a refused set
  leaves no record.
- Organization mode requires records: archive. A record that arrives in a
  header opens only with this computer's device keys or a recovery key.
- A lost device key no longer hides a valid recovery or organization key.
- Machine policy: each platform reads only its own sources, HKLM access
  denied is an error, and every policy file is checked root-owned and
  root-writable-only on the descriptor actually read.
- Refresh the eligibility connector lock.
- The JIT capture's plaintext opt-out stack exists from construction, so a
  capture closed without entering still cleans up.
- verify_integrity hashes an encrypted bundle's assets in memory.
- The variant router reads the child run's report through the sealed set.
- The console shows an encrypted run's pending escalation.
- The approver-root pin (a key fingerprint, key directory and roster head,
  written before the run) is a structural file of a run set.
…triaged skips

- tests/default_at_rest_skips.txt: each test skipped under
  OPENADAPT_TEST_DEFAULT_AT_REST=1, with its reason (group a: the test reads
  or plants plaintext and the product correctly refuses; group b, open:
  attended approvals, drafts, business decisions and teach on encrypted
  input). The matcher takes a test, its class or its file.
- flow default at rest joins packages-gate (pull requests only).
- Merge origin/main and regenerate CAPABILITIES.md and llms-full.txt.
@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Full flow suite with encryption at rest on: results and triage

The new required job flow default at rest (four shards) runs the whole flow suite with OPENADAPT_TEST_DEFAULT_AT_REST=1, the product default with no plaintext opt-out, a 300 s per-test timeout, and the fast lane. It passes at b3328e0ef3159229cd2ced0b835fb4eb777108ce.

Round (head) Tests Failing Change
1 (358e287) 27,006 584 first run, informational
2 (5480849) 27,006 435 authoring, runtime validation and agent-teach evidence read and write sealed files; one test home and lock directory per session
4 (9db1a8a) 27,007 435 receipts, handoff follow-ups, distill, the agent-teach candidate; JIT capture plaintext by design. A new failure (the JIT capture's _plaintext attribute) offset the gains
5 (d139238) 27,009 415 bundle integrity check, variant router, console pending view, approver-root pin; the _plaintext failure fixed
final (b3328e0) — 0 the 299 triaged tests below are skipped, each with its reason (tests/default_at_rest_skips.txt); the job is required

The 415 failures in round 5 collapse to 299 test functions once parametrized cases are merged.

Group (b): product paths that broke under default encryption, fixed in this PR

Path Fix
Durable resume: prove_executor_outcome and the terminal check hash the report through the sealed set
A run leg cut off before finalizing the writer carries it on; each earlier file must authenticate under the set's key at its own path
CheckpointStore made before its run was sealed looks up the run's key when used
Rollback marker and difference files; was_compensated written and checked through the sealed set
AuthoringSession (events, meta, admit.json), distill_recording read and write the encrypted recording
Runtime validation, variant router, console pending view, verify_integrity read the run or bundle in memory
Run receipts (receipt.json, private openings, card) and handoff follow-ups written for encrypted runs. They were skipped entirely, so default runs had no receipt
Agent-teach repair candidate and evidence candidate sealed; the plaintext evidence folder is logged by default and refused in strict mode
JIT compile-agent capture plaintext by design (the draft lifecycle signs plaintext files): named on stderr and in the ledger, refused in strict mode before recording
Approver-root pin written before a run a structural file of the run set (key fingerprint, key directory, roster head)

Group (a): 240 tests skipped with a reason

In each one the test reads or plants a file directly and the product refuses it, correctly.

Reason Tests
reads a run, recording or bundle file from disk as plaintext; by default it is ciphertext, and the product reads it through the set 211
plants or edits a plaintext file inside an encrypted set, or recompiles into a plaintext directory 21
checks a passphrase or a plaintext default against a version 3 set, which opens with recipient keys 6
shares state across tests through the at-rest home 2

Group (b, still open): 59 tests skipped and named as a limitation

In an encrypted run, attended approvals (approval gates), attended drafts, business-decision states and teach on encrypted input are refused up front, before anything runs, as phi_at_rest.md already documents. Now that runs are encrypted by default, these features need a plaintext bundle and run or the opt-out until their stores are sealed. Files: test_decision_supervisor, test_mobile_attended_decision_e2e, test_approval_mode_each_item, test_business_decision, test_teach_cli, test_teach_placement, test_teach_branch. This needs a decision: seal those stores as a follow-up, or keep the up-front refusal.

The three tests with a different refusal

Each test planted a plaintext file beside the store's encrypted one, so the product refused the stray file before reaching the check under test. Each now tampers through the store's own writer. I captured the refusal in both modes, and it is the same in each:

  • test_durable_program::test_program_resume_refuses_a_noncontiguous_checkpoint_history: DurableAuthorityBusy: local durable state was restored or changed outside the monotonic authority.
  • The test_durable_program_history_v13 tamper cases: the same DurableAuthorityBusy (10 refusals).
  • test_attended_source_identity_v13::test_pre_v3_capability_only_supports_non_identity_required_resume: AttendedActionRefused: the attended source identity predates identity-bound continuation.

Not caused by this PR

@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

From: Claude
Reviewed-Head: b3328e0

@abrichr

abrichr commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: b3328e0

Independent cross-vendor adversarial review of b3328e0ef3159229cd2ced0b835fb4eb777108ce (Claude-authored feat/encrypt-at-rest-default; I authored none of this PR).

Cryptographic & fail-closed verification

  • Streaming AEAD (stream_aead.py): Implements Tink's AES256_GCM_HKDF_1MB wire format (HEADER_SIZE = 40, HKDF-SHA256 binding AAD via info, 7-byte prefix + 4-byte big-endian segment index + 1-byte last-segment flag). Truncated streams, wrong keys, and tampered AADs fail closed with StreamError, verified against Tink itself in test_stream_aead.py.
  • v3 Key hierarchy & Codex 16-finding hardening (key_hierarchy.py, sealed_set.py, at_rest.py):
    • _read_trusted_file opens policy files with O_NOFOLLOW and checks ownership/permissions via os.fstat(fd) on the opened descriptor (TOCTOU-free).
    • Archive reachability requires an admin-created .openadapt-key-archive marker (ARCHIVE_MARKER), and records/headers bind the key_archive they were written to so an unmounted share never masquerades as deleted or delivered.
    • bucket_lock() serializes bucket create, archive, close, and shred across threads and processes, preventing archive workers from resurrecting shredded records or racing past max_unarchived.
    • _open_v3 authenticates both header MACs, verifies record["bucket_id"] == key_ref["bucket_id"], and passes from_header=record is inline to open_bucket so inline records never open with org/break-glass keys and never silently open with the recovery code (SealedSetRestoreRequired until explicit at-rest restore).
    • shred() acquires mutation_lock(base) and authenticates the header via _open_v3 before destroying any key (refusing with SealedSetKeyError if unauthenticated), and marks complete only after store files and archive copies are destroyed.
    • Encrypted run receipts (receipt_record.py, offline_seal.py, cli_local_seal.py) read plaintext report.json in memory via sealed_set.read_bytes, keep private openings sealed inside the set, and report report_locked when no local key opens the run.
  • CI: 72/74 checks green at b3328e0e (including the 4-shard flow default at rest job under OPENADAPT_TEST_DEFAULT_AT_REST=1); only Evaluate protected-path evidence and protected-safety-review were awaiting this cross-vendor approval.

Generality gate

  1. No per-app code in engine: Verified; generic cryptographic envelope, key hierarchy, policy loader, and sealed-set storage.
  2. Fix the class, not the instance: Verified; encrypts recordings, bundles, runs, durable checkpoints, rollback markers, and receipts by default under one v3 key hierarchy.
  3. Held-out evidence: Verified via Tink interop tests, 4-shard default-at-rest CI suite, and headless MockMed quickstart plaintext-absence check, with unimplemented hardware/KMS/remote-archive items honestly documented in phi_at_rest.md.

@abrichr
abrichr merged commit 4519814 into main Nov 23, 2026
73 of 75 checks passed
@abrichr
abrichr deleted the feat/encrypt-at-rest-default branch November 23, 2026 13:59
abrichr added a commit that referenced this pull request Nov 23, 2026
Since encryption at rest became the default (#2423), a run directory is a
sealed set. Self-repair still wrote each bridge step's evidence frame
(self-repair/attempt-N/evidence/heals/<step>/screen.png) with pathlib, so
a screenshot that can show a person's record landed in plaintext inside
the encrypted run, and the next write to the run (the report) refused the
set. persist_heal already wrote through the set, which is why only the
bridge frames leaked.

- runtime/heal.py: add heal_frame_path, write_heal_frame, has_heal_frame
  and read_heal_frame, all through openadapt_flow.sealed_set;
  persist_heal uses write_heal_frame.
- repair/self_repair.py: write and hash bridge frames through the helpers;
  read staged expect templates, copy the halted report, read the halted
  before-frame and write self-repair.json through the sealed set (each read
  ciphertext, skipped the file, or wrote plaintext in a sealed run).
- repair/cli.py: the frame campaign reads heal frames through the helpers,
  so a sealed frame is found instead of refused as missing.
- compiler/compile.py: write the hover evidence crop through the sealed set.
- tests: a sealed run keeps the bridge frame sealed, reopens, and accepts
  the next report write; the halted frame is read through the set.
abrichr added a commit that referenced this pull request Nov 23, 2026
Self-repair built the patched bundle by copying the source bundle
directory without its templates, manifest and repair files, then saving
the patch into the copy. For a sealed bundle (the default since #2423)
that copy carries the source's index but not the files it lists, so the
save refused it ("does not match its sealed index") and every bridge
repair ended in no_fix. Relabel repair copied the same way and left out
the sealed repair/* files.

- bundle_persistence.copy_bundle_files: copy a plaintext bundle as files;
  write a sealed source into a new sealed set through its writer
  (decrypted in memory, sealed again), with the same ignore patterns.
- repair/self_repair.py and repair/relabel.py use it.
- tests: a patched copy of a sealed bundle opens, verifies, holds no
  plaintext and loads with the patch; a plaintext copy is unchanged.
abrichr added a commit that referenced this pull request Nov 23, 2026
Self-repair's probe and resume need an attended approval, and a sealed
run refuses one: the known limitation #2423 documented (attended
approvals, drafts and decisions are held back in sealed runs). The
product rule stays as it is.

In qualify_linux.py and qualify_macos.py, only the self-repair legs now
run on a plaintext copy of the bundle (same content digest) under the
documented opt-out, at_rest.opted_out, which names the plaintext writes
on stderr and in the ledger. Record, compile, the governed runs and the
wrong-patient legs still run under the default. The results record
self_repair_mode, and the summary prints it, so a passing job is not
read as self-repair working encrypted.
abrichr added a commit that referenced this pull request Nov 23, 2026
…block native Linux qualification (#2589)

* fix(flow): read and rewrite the sealed recording in the repair qualifications

Encryption at rest became the default in #2423, so the recording these
benchmarks record is a sealed set and has no plaintext events.jsonl.
qualify_linux.py (and its macOS sibling) read and rewrote that file with
pathlib, which failed the native Linux AT-SPI job on main with
FileNotFoundError. Read and write the events through the sealed-set API,
in memory, so the qualification keeps testing the default product.

* fix(flow): remove the bundle manifest through the sealed set in the repair qualifications

A pathlib unlink left manifest.json in the sealed index, so the next
save refused the bundle (missing: manifest.json).

* fix(flow): keep self-repair heal evidence sealed in an encrypted run

Since encryption at rest became the default (#2423), a run directory is a
sealed set. Self-repair still wrote each bridge step's evidence frame
(self-repair/attempt-N/evidence/heals/<step>/screen.png) with pathlib, so
a screenshot that can show a person's record landed in plaintext inside
the encrypted run, and the next write to the run (the report) refused the
set. persist_heal already wrote through the set, which is why only the
bridge frames leaked.

- runtime/heal.py: add heal_frame_path, write_heal_frame, has_heal_frame
  and read_heal_frame, all through openadapt_flow.sealed_set;
  persist_heal uses write_heal_frame.
- repair/self_repair.py: write and hash bridge frames through the helpers;
  read staged expect templates, copy the halted report, read the halted
  before-frame and write self-repair.json through the sealed set (each read
  ciphertext, skipped the file, or wrote plaintext in a sealed run).
- repair/cli.py: the frame campaign reads heal frames through the helpers,
  so a sealed frame is found instead of refused as missing.
- compiler/compile.py: write the hover evidence crop through the sealed set.
- tests: a sealed run keeps the bridge frame sealed, reopens, and accepts
  the next report write; the halted frame is read through the set.

* fix(flow): copy a sealed bundle as a new sealed set before patching it

Self-repair built the patched bundle by copying the source bundle
directory without its templates, manifest and repair files, then saving
the patch into the copy. For a sealed bundle (the default since #2423)
that copy carries the source's index but not the files it lists, so the
save refused it ("does not match its sealed index") and every bridge
repair ended in no_fix. Relabel repair copied the same way and left out
the sealed repair/* files.

- bundle_persistence.copy_bundle_files: copy a plaintext bundle as files;
  write a sealed source into a new sealed set through its writer
  (decrypted in memory, sealed again), with the same ignore patterns.
- repair/self_repair.py and repair/relabel.py use it.
- tests: a patched copy of a sealed bundle opens, verifies, holds no
  plaintext and loads with the patch; a plaintext copy is unchanged.

* fix(flow): run the qualification's self-repair legs on a plaintext copy

Self-repair's probe and resume need an attended approval, and a sealed
run refuses one: the known limitation #2423 documented (attended
approvals, drafts and decisions are held back in sealed runs). The
product rule stays as it is.

In qualify_linux.py and qualify_macos.py, only the self-repair legs now
run on a plaintext copy of the bundle (same content digest) under the
documented opt-out, at_rest.opted_out, which names the plaintext writes
on stderr and in the ledger. Record, compile, the governed runs and the
wrong-patient legs still run under the default. The results record
self_repair_mode, and the summary prints it, so a passing job is not
read as self-repair working encrypted.
abrichr added a commit that referenced this pull request Nov 24, 2026
…2.4 (<5) (#2609)

* release(flow,agent)!: cut openadapt-flow 4.0.0 and openadapt-agent 2.2.4 (<5)

Bump openadapt-flow to 4.0.0 so encryption at rest by default (#2423)
publishes as a major release instead of 3.5.0 (which would break released
openadapt launcher 1.23.0, which caps openadapt-flow<4 and reads run
directories via plain paths).

Bump openadapt-agent to 2.2.4 and widen its openadapt-flow cap from <4
to <5 so openadapt launcher 1.24.0 (>=4.0.0,<5.0.0) can resolve cleanly
once Flow 4.0.0 and Agent 2.2.4 publish to PyPI.

BREAKING CHANGE: openadapt-flow 4.0.0 encrypts recordings, bundles, and
run directories at rest by default (#2423).

* chore(eligibility): sync editable openadapt-flow 4.0.0 in uv.lock

* chore(eligibility): accept openadapt-flow <5 for Flow 4.0.0
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