Repository navigation
Conversation
The prefix on `c` becomes `rc:1:`, and production data has the old prefix, so a reader has to take both for good. A reader that is already released refuses `rc:1:`. So this release reads both prefixes and still writes `stack-encrypt:1:`. A later release writes the new prefix, after every reader has this one. Both prefixes are in encryption.rs, next to the written one. The Go SDK reads through the guest. The guest links this crate, so Go needs no change. Refs #2040
A program has to upgrade every reader before any writer moves to the new prefix. The changelogs and the changeset say so, so the order is clear to anyone who upgrades. Refs #2040
🦋 Changeset detectedLatest commit: 0e33fd2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true |
coderdan
left a comment
There was a problem hiding this comment.
Review of this pull request at 5b58519f9. No correctness problem in the reader change. There are four small findings. Three are inline. One is here, because its file is not in the diff.
The language integration guide still names one prefix
packages/stack-encrypt/docs/language-integration.md:784 says c is "the ciphertext under the stack-encrypt:1: prefix". That is true of the value shown: a writer wrote it. The guide does not say that a reader takes rc:1: too. Someone who writes a reader for another language from this guide would accept one prefix only. That reader would refuse every value once a writer moves to rc:1:.
| "rc:1:~", | ||
| "rc:1:00000", | ||
| "rc:1:AAAA", | ||
| "rc:1:雪", |
There was a problem hiding this comment.
The six new rc: cases are checked with is_err() only, so any error passes them.
Suppose rc:1: were removed from the prefixes a reader takes. The five rc:1:… cases would still pass. The prefix check would refuse them, where today the body does.
Assert the cause. The rc:1: cases must not contain "unsupported EQL ciphertext producer or version". The rc:2: and stack-encrypt:2: cases must contain it.
There was a problem hiding this comment.
Fixed in 0e33fd2de. Each case now states whether the refusal names the prefix, and the test compares that with the error text. With rc:1: taken out of the reader, the test fails on the rc:1: case, as it should.
| @@ -42,7 +42,8 @@ async fn text_round_trips_through_json_and_both_canonical_directions() { | |||
| // cipherstash-client ciphertext inside the payload; the `eql_v4` | |||
| // domain separates them in the database. Encryption | |||
| // and decryption read one constant, so a round trip cannot notice it | |||
There was a problem hiding this comment.
This comment still says "Encryption and decryption read one constant". After this change, the writer reads CIPHERTEXT_PREFIX and the reader reads a list of two.
The comment also no longer says why the literal is pinned here. Rows already stored have it. A round trip cannot notice the written prefix changing.
There was a problem hiding this comment.
Fixed in 0e33fd2de. The comment now gives both reasons the literal is pinned: stored rows start with it, and a round trip passes whichever prefix the writer writes.
| } | ||
| opensToItsPlaintexts(t, c, frozen.Rows) | ||
|
|
||
| for _, prefix := range []string{"xx:1:", "rc:2:", "stack-encrypt:2:"} { |
There was a problem hiding this comment.
The Go test sends three unknown prefixes through the guest. The Rust unit test also covers RC:1:, rc:1 with no final colon, and no prefix. If the guest build that Go embeds matched the prefix without regard to case, the Go suite would still pass. Add RC:1: and the empty prefix here.
There was a problem hiding this comment.
Fixed in 0e33fd2de. The Go test now sends RC:1: and a value with no prefix through the guest too, and both are refused with the same error.
The refusal list in `text_eq.rs` checked each case with `is_err()`, so any error passed. With `rc:1:` removed from the prefixes a reader takes, the `rc:1:` cases still passed. Each case now states whether the refusal names the prefix. That removal now fails the test. The Go test sends `RC:1:` and a value with no prefix through the guest too. The comment in `text_eq.rs` and the language integration guide now say that a reader takes two prefixes and a writer writes one. Refs #2040
|
The finding about the language integration guide is fixed in |
Summary
EQL (Encrypt Query Language) is the SQL library that stores and queries encrypted values in PostgreSQL. An EQL value is a JSON object. Its
ckey stores the ciphertext: a text prefix, then base64 of a sealed leaf. A sealed leaf is one encrypted value as Stack Encrypt writes it. Stack Encrypt (stack-encrypt) is the Rust encryption crate.Today every value is written with the prefix
stack-encrypt:1:. The prefix will becomerc:1:. Values that are already stored keep the old prefix, so a reader has to take both prefixes for good.A reader that is already released refuses
rc:1:. If a writer moved to the new prefix first, those readers could not open the new values. So the change takes two releases:rc:1:andstack-encrypt:1:. Every writer still writesstack-encrypt:1:.rc:1:.A program upgrades every reader to the first release before any writer moves to the second. No stored value is encrypted again.
Changes
eql-bindings(the Rust crate released with@cipherstash/eql): the reader ofcstrips either prefix and reads the same leaf from the body. Both prefixes are in one place,encryption.rs, next to the prefix that is written. The two prefixes differ in their first character, so at most one matches a givenc. Any other prefix is still refused with the same error as before: "unsupported EQL ciphertext producer or version". The refusal comes before the body is decoded and before any data key is requested.cstill starts withstack-encrypt:1:.eql-bindingsREADME, the[Unreleased]sections of theeql-bindingsand Go changelogs, and a changeset for@cipherstash/eql.Verification
Tests were written first and seen to fail before the reader changed:
eql-bindingsunit tests (src/encryption.rs): a stored body reads to the same leaf under both prefixes. A new value is written withstack-encrypt:1:. A valid body underxx:1:,rc:2:,RC:1:,rc:1orstack-encrypt:2:is refused with the same error as today. A body underrc:1:that is not base64 or not a sealed leaf is refused by the decoder, not by the prefix check. Before the change,a_body_under_the_rc_prefix_reads_as_the_same_leaffailed with "unsupported EQL ciphertext producer or version".eql-encryption-tests(text_eq.rs,v4_types.rs): a freshly sealedTextEqopens to the same text with its prefix swapped torc:1:. A tampered body underrc:1:fails authentication. A valid body under another prefix is refused by name and requests no data key. The frozen rows instored_v4_rows_v1.jsonandstored_v4_json_rows_v1.jsonopen to the same plaintexts with eachcswapped torc:1:in memory. No fixture file changes. Four of these failed before the change.eql_v4_test.go,TestV4ValuesUnderTheRCPrefixOpen): freshly sealed profiles and the frozen rows open underrc:1:. A new value still hasstack-encrypt:1:.xx:1:,rc:2:andstack-encrypt:2:are refused with the same error. Against a guest built from the old reader, it failed withunsupported EQL ciphertext producer or version.Checks run in
packages/eql, after the change:cargo fmt --all --check: clean.cargo clippy -p eql-bindings -p eql-codegen -p eql-encryption-tests --all-features --all-targets -- -D warnings: clean.cargo nextest run -p eql-bindings -p eql-codegen -p eql-encryption-tests --all-features: 623 passed, 63 skipped.cargo test --doc -p eql-bindings --all-features: 18 passed, 3 ignored.RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p eql-bindings --all-features: clean.cargo run -p eql-codegen -- bindings,-- go-eqland with no argument:git statusshowed no change to any generated file.Go, with the guests rebuilt from this branch:
eql,deterministic-kms. Auth guest tests: 24 passed.scripts/go-binding-test.sh languages/golang, nested modules included).TestV4ValuesUnderTheRCPrefixOpenandTestFrozenV4RowsStillOpenwere also run on their own with-v, and both passed.Not run:
#[ignore]: they need PostgreSQL.Related
Review notes
Every place in the repository that reads, writes or mentions the prefix:
packages/eql/crates/eql-bindings/src/encryption.rs,CIPHERTEXT_PREFIXandCIPHERTEXT_PREFIXES_READencryption.rs,CiphertextVisitor::sealedstack-encrypt:1:. Unchanged.encryption.rs,impl Reader for Ciphertextlanguages/golang/encrypt/guest(eqlfeature)eql-bindings, linked by path. No change of its own.packages/eql/srccis present, or that it is a string. It does not read the prefix, so it takesrc:1:already.eql-bindings/schema/v3cipherstash-client, whosechas no prefix. Not a reader of this prefix.languages/typescriptprotect-ffiuseseql-bindingswithout thestack-encryptfeature, so it does not build this code.recipher-jsdoes not useeql-bindings.packages/eql/tests/encryption/fixtures/*.jsonstack-encrypt:1::text_eq.rs,v4_types.rs,languages/golang/encrypt/eql_test.go,languages/golang/encrypt/eql_v4_json_test.go,languages/golang/encrypt/guest/src/ops.rseql-bindings/tests/v4_inventory.rs,languages/golang/encrypt/eql/eql_test.goeql-bindings/README.mdpackages/stack-encrypt/docs/language-integration.mddocs/adr/0002-…anddocs/plans/2026-10-04-plan-builder.mdThe writer still writes
stack-encrypt:1:in this pull request, as the owner decided. A reader from a release before this one refusesrc:1:. So every reader has to be on this release before any writer changes. The second release makes the writer change.