From 42c56fdfef2cb8caecf5ff4bd81ee2d686b0e4de Mon Sep 17 00:00:00 2001 From: Martin Bertschler Date: Sat, 26 Sep 2026 17:48:08 +0200 Subject: [PATCH 1/5] design: propose native encryption with age, one content layout and seekable packs --- design/README.md | 3 + design/native-crypt.md | 584 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 587 insertions(+) create mode 100644 design/native-crypt.md diff --git a/design/README.md b/design/README.md index d3840c7..b226223 100644 --- a/design/README.md +++ b/design/README.md @@ -17,6 +17,9 @@ each time. - [`native-mirror.md`](native-mirror.md) — *implemented in #217*: one planner shared by every layout, a small transport, and every `local` and plain `sftp` destination written without rclone. +- [`native-crypt.md`](native-crypt.md) — *proposed*: age encryption with a + required recovery key, rclone crypt removed, packed as the one content + layout, and seekable packs. ## How to use this folder diff --git a/design/native-crypt.md b/design/native-crypt.md new file mode 100644 index 0000000..79d4004 --- /dev/null +++ b/design/native-crypt.md @@ -0,0 +1,584 @@ +# Native encryption: age, one content layout, and seekable packs + +*Proposed.* This is step 3 of replacing rclone with squirrel's own code. +Peer sync dropped rclone in #210, #211 made the mirror's evidence honest, and +[native-mirror.md](native-mirror.md) (#217) moved every `local` and plain +`sftp` destination onto squirrel's transport. What still needs rclone is +encryption, and the s3, b2 and gcs backends. This design removes rclone's crypt +overlay. The S3 transport follows it on its own branch. + +## Summary + +- **One content layout.** The content-addressed layout is retired: it was the + packed layout with every file stored as an object, which `pack_threshold = 0` + still gives. +- **Encryption belongs to the packed layout.** A `crypt` block is accepted on + a packed destination and refused on a mirror. An + encrypted mirror needs a tool to read any file, yet its tree discloses every + path, size and modification time. It also can't gate offload. +- **Squirrel encrypts every artifact itself, in the + [age](https://c2sp.org/age) format** (`age-encryption.org/v1`), to hybrid + post-quantum recipients (ML-KEM-768 with X25519). Recovery without squirrel + needs the stock `age` command, zstd and tar. +- **Two recipients, both required.** The *agent identity* lives on the machine + that pushes. The *recovery recipient* is a public key whose private half, the + *recovery kit*, is printed once and kept offline. Every file opens with + either one. +- **The naming key is random** and lives on the destination, in + `.squirrel-naming`, encrypted to both recipients. It no longer comes from a + password. +- **rclone never sees plaintext again.** `local` and `sftp` encrypted + destinations become native. On s3, b2 and gcs, rclone moves ciphertext that + squirrel produced, until the S3 transport replaces it. +- **Packs become seekable.** A pack is written as a run of zstd frames of about + 1 MiB. The placement map records each member's frame, so restoring one file + reads one frame instead of the whole pack. Stock `zstd -d | tar -x` still + reads a pack end to end. +- **Objects are padded** with Padmé before encryption, so a large file's size + shows only to within a few percent. It costs about 1% of storage on a + media-heavy archive. + +## Why not rclone's format + +rclone crypt did the job, but squirrel inherited its limits: + +- **Truncation goes unnoticed.** The format has no end-of-file marker, so a + file cut at a 64 KiB block boundary decrypts cleanly as a shorter file. + Objects are saved by squirrel's BLAKE3 check on restore; manifest segments, + placement maps and snapshots only by parsing. +- **One key for everything, derived from a password** with fixed scrypt + parameters. Anyone holding the ciphertext can guess passwords offline, and a + password change means re-encrypting every file. +- **One implementation.** The format is specified by rclone's documentation and + read by rclone. +- **Source modification times leak.** rclone carries each file's mtime onto + the stored copy. + +age fixes each of these: + +- It has a frozen, published specification, test vectors, several independent + implementations, and a command-line tool in most distributions. +- Its payload is ChaCha20-Poly1305 in 64 KiB chunks, with a fresh key per file + and a flagged last chunk, so truncation fails authentication. +- ChaCha20 is fast on NAS processors without AES instructions. +- It encrypts each file to any number of recipients. +- Since v1.3 it has post-quantum recipients. Backups are the data a + "record now, decrypt later" attacker wants. + +Considered and rejected: libsodium's secretstream in a format of squirrel's own +(better context binding, but squirrel would own a format and its recovery tool), +Tink streaming encryption (keyset machinery built for services, no general +decrypt command), OpenPGP (GnuPG and RFC 9580 modes don't interoperate, large +attack surface), and staying byte-compatible with rclone crypt (the weaknesses +above). Kopia bundles content addressing, packing and encryption the same way +this design does; squirrel keeps what kopia doesn't offer: recovery with stock +tools, and BLAKE3 evidence that gates offload. + +## Scope + +**In scope:** + +- retiring the content-addressed layout; +- the `crypt` block's new shape, and its refusal on mirrors and kopia; +- the encryption layer under both artifact stores (the transport, and rclone as + a byte mover); +- keys: generation, the recovery kit, recipient pinning, and changing + recipients; +- `.squirrel-naming` and the names derived from it; +- evidence, verify, restore and recover on encrypted destinations; +- Padmé padding of objects; +- seekable packs, encrypted or not, with ranged reads on every transport; +- the recovery procedure without squirrel. + +**Out of scope:** + +- **The S3 transport.** It follows on its own branch and replaces + `rclone rcat`/`rclone cat` underneath the artifact store. +- **Rewrapping existing artifacts** to a changed recipient set (open + question 1). +- **Mirrors, kopia, and peer sync.** An encrypted mirror is refused; kopia + encrypts its own repository; peer sync runs between machines that hold the + plaintext anyway. + +In the [reference setup](reference-setup.md), `cloudbox` becomes an encrypted +packed destination written natively over sftp, and `s3archive` +stays packed and encrypted, with rclone moving its ciphertext. + +## What changes for the operator + +- **The `crypt` block names keys, not passwords:** + + ```toml + [destinations.offsite.crypt] + identity = { env = "SQUIRREL_OFFSITE_IDENTITY" } # AGE-SECRET-KEY-PQ-1…, the agent's key + recovery = "age1pq1…" # public; its private half is the recovery kit + ``` + + `password`, `password2` and `obscured` are gone. Several destinations may + name the same keys. +- **`squirrel destination keygen`** creates both keys. It shows the recovery + kit, asks for it back to prove it was stored, and prints the block above. +- **Encrypted mirrors are refused** at config load, with a message naming the + packed layout. +- **`layout = "content-addressed"` is refused** at config load, naming + `layout = "packed"` with `pack_threshold = 0` as the way to keep an object + per file. +- **`local` accepts `crypt`,** so an encrypted USB disk works. +- **Existing encrypted and packed destinations must start over.** Squirrel + isn't in production, so there is no reader for the rclone format or for + single-frame packs: point the destination at a fresh root, or wipe it and run + `destination reset`. A database that already records packs starts over; the + migration refuses it. +- **Recovery without squirrel** needs age v1.3 or newer (older clients need the + `age-plugin-pq` compatibility plugin), zstd and tar. The procedure is in + [formats](../docs/src/content/docs/reference/formats.md). +- **An encrypted destination discloses less:** no source modification times, + and no path on any layout. Object sizes show only to within a Padmé bucket. + Counts and timing stay visible (section 1). + +## 1. What an encrypted destination holds + +Every file squirrel writes under an encrypted root is an age file. Names are +fixed, keyed, or carry only a run id: + +``` +/ + .squirrel-naming # age: scheme, naming key, recipient set + objects/ # age: the content, padded + packs/ # age: zstd frames of a tar + packs/map- # age: placement map (JSONL) + /.squirrel-volume # age: volume marker + /index/run- # age: manifest segment (JSONL) + /.squirrel-index/index-