Repository navigation
feat(ffi)!: decrypt encrypted ledgers via a host capability (#1667, WIT 3.2.0) - #1670
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces host-mediated decryption for GPG-encrypted ledgers in the WASI component, by adding a new WIT import (host.decrypt) and routing loader decryption through an injectable filesystem. This enables .gpg/.asc ledgers to load in sandboxed environments where spawning gpg and accessing the keyring is not possible.
Changes:
- Add
FileSystem::decryptand thread it through the loader pipeline (including a newload_with_fsentrypoint) so decryption can be delegated by sandboxed filesystems. - Bump WIT package
rustledger:ledgerto 3.2.0 and add thehost.decryptimport to the component world. - Implement a component-side filesystem (
HostDecryptFs) that reads ciphertext in-sandbox and calls the importedhost.decrypt, plus parity coverage for the new capability.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger-loader/src/vfs.rs | Adds FileSystem::decrypt with a default gpg --decrypt implementation. |
| crates/rustledger-loader/src/process.rs | Adds load_with_fs to allow injecting a filesystem (used by WASI component). |
| crates/rustledger-loader/src/lib.rs | Routes encrypted reads through self.fs.decrypt(path) and exposes load_with_fs; makes decrypt_gpg_file usable by vfs. |
| crates/rustledger-ffi-wasi/src/helpers.rs | Adds load_file_with_fs so callers can thread an injected filesystem through the canonical loader pipeline. |
| crates/rustledger-ffi-component/wit/world.wit | Bumps WIT package to 3.2.0 and introduces/imports interface host { decrypt(...) }. |
| crates/rustledger-ffi-component/src/lib.rs | Updates component API version constant to 3.2. |
| crates/rustledger-ffi-component/src/convert.rs | Implements HostDecryptFs that calls host.decrypt and injects it into load_file. |
| crates/rustledger-ffi-component/Cargo.toml | Adds rustledger-loader dependency for DiskFileSystem/FileSystem usage. |
| crates/rustledger-ffi-component-tests/tests/parity.rs | Links the new host import and adds a test validating encrypted loads via host decrypt. |
| Cargo.lock | Locks the new crate dependency edge for the component crate. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-07-01)
What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
WIT rustledger:ledger 3.1.0 -> 3.2.0 (adds the host.decrypt import); API_VERSION
-> 3.2.
GPG-encrypted ledgers (.gpg/.asc) were detected but could not be decrypted
through the WASI component: decryption shelled out to gpg (Command::new), which a
WASI guest cannot do (no process spawn, no keyring access), so load failed with
"failed to decrypt". Encrypted ledgers were unusable via the component (rustfava).
Fix follows the WASI capability model + beancount's own architecture: decryption
is a host capability, not something the sandbox does. Decryption is now a
FileSystem trait method (default: gpg subprocess — native CLI unchanged); the
component injects a filesystem whose decrypt reads the ciphertext in-sandbox and
calls the new host.decrypt import, which the embedder satisfies with its keyring
access. Secret keys never enter the guest.
- loader: FileSystem::decrypt (default gpg) + process::load_with_fs (fs injection)
- wit: interface host { decrypt: func(list<u8>) -> result<string,string> }; import host
- ffi-component: HostDecryptFs delegates decrypt to the host import; load_file uses it
- ffi-wasi: load_file_with_fs threads the caller fs
BREAKING (host contract): the component now imports host.decrypt, so an embedder
must provide it in its wasmtime linker (e.g. shelling out to gpg / gpgme). The
native CLI is unaffected.
Tests: an encrypted .gpg file loads via a host-provided decrypt (no gpg/keyring in
the sandbox). 92 loader + 19 FFI parity pass; clippy -D warnings + fmt clean.
Closes #1667
Co-Authored-By: Claude Opus 4.8 <[email protected]>
robcohen
force-pushed
the
feat/wasi-host-decrypt
branch
from
July 1, 2026 20:18
0b29f69 to
38b9074
Compare
Merged
robcohen
added a commit
that referenced
this pull request
Jul 1, 2026
Minor (breaking-FFI) release: WIT contract rustledger:ledger 3.2.0 — the component now imports host.decrypt so encrypted ledgers are decrypted by the embedder (#1667/#1670); embedders must provide the import and regenerate bindings. Also carries the booking/validate diagnostics fixes (#1666, #1668 via #1669): lot-label preserved on reductions, dedicated balance-currency diagnostic, deduped oversell error. Workspace 0.18.0 -> 0.19.0; packages/mcp-server bumped to match. Co-authored-by: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1667. Breaking WIT change:
rustledger:ledger3.1.0 → 3.2.0 — adds thehost.decryptimport; embedders (rustfava) must provide it.Problem
GPG-encrypted ledgers (
.gpg/.asc) were detected but couldn't be decrypted through the WASI component — decryption shells out togpg(Command::new), which a WASI guest can't do (no process spawn, no keyring). Load failed withfailed to decrypt, so encrypted ledgers were unusable via the component (rustfava).Approach — decryption as a host capability (b2)
Grounded in prior art + best practice (see the #1667 discussion): the WASI capability model says the host mediates authority including secrets, and beancount itself decrypts on the host (
gpg --batch --decrypt) then loads the plaintext. So decryption belongs to the host, not the sandbox — and secret keys should never enter the guest.This implements the clean component-model idiom: the component imports a
decryptcapability the host satisfies.FileSystem::decrypttrait method — default shells out to gpg, so the native CLI path is unchanged. Newprocess::load_with_fsfor filesystem injection.3.2.0):interface host { decrypt: func(ciphertext: list<u8>) -> result<string, string> }+import host.HostDecryptFsreads the ciphertext in-sandbox (WASI fs) and callshost.decrypt;load_fileinjects it.load_file_with_fsthreads the caller-provided filesystem.load-filekeeps handling encryption transparently — the keyring authority just lives in the host now.Breaking host-contract change
The component now imports
host.decrypt, so an embedder must provide it in its wasmtime linker — e.g.:rustfava must add this to load encrypted ledgers. The native CLI is unaffected (it uses the loader's default gpg path).
Tests
.gpgfile loads via a host-provideddecrypt(the test host returns a fixed plaintext — no real gpg/keyring needed in CI).-D warnings+ fmt clean; theversion_matches_wit_packagegate confirmsAPI_VERSION 3.2↔ WIT3.2.0.Release
Breaking FFI/WIT → wants a 0.19.0; rustfava then adds the
host.decryptprovider and regenerates bindings.🤖 Generated with Claude Code