Repository navigation
Conversation
The live json_tree oracle checked a fixed corpus and a fixed list of needles. The only randomized containment check compared the projection with an in-memory model of jsonb containment, never with PostgreSQL, so nothing generated was ever answered by the database itself. postgres_containment_over_generated_documents_is_jsonb_containment stores 300 generated documents encrypted beside their plaintexts and asks 500 needles: random values, sub-documents pruned from stored documents, and those sub-documents with one edit. For every needle the rows the encrypted @> and <@ select must be the rows jsonb @> and <@ select over the plaintexts, as PostgreSQL computes them. It runs once with the planner held to the GIN index and once with every index path off, and checks each @> plan with EXPLAIN. <@ may differ only where the SQL says it does (a stored root scalar inside a needle root array), and the test asserts that is the whole difference. It also checks -> at 20 generated key paths: the entry exists exactly where jsonb #> finds a node, and a leaf opens to the value jsonb holds there. The seed is fixed (1336), logged on every run, and replaced by EQL_JSON_TREE_SEED. A failure prints the seed, the needle and every stored document the two answers disagree on. test:encryption:postgres passes --show-output so the seed line reaches the CI log. Claude-Session: https://claude.ai/code/session_01XQN1QpaWVDGjHEg39KEJF3
|
Contributor
|
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
Comment |
This branch has not been deployed
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.
Summary
EQL v4's
json_treecolumn lets PostgreSQL answer JSON containment (@>, "does this document contain that one?", and<@, the reverse) over encrypted documents. The promise is that it answers exactly as PostgreSQL's ownjsonboperators would answer over the plaintexts. Until now that promise was checked against live PostgreSQL only for a fixed, hand-picked set of documents. The only randomized check compared against a Rust model ofjsonbcontainment, never against PostgreSQL itself.This PR adds a seeded property test that generates a few hundred documents and several hundred queries, and checks every answer against PostgreSQL's real
jsonbanswer, on both the index path and the sequential-scan path. It is test-only.Changes
packages/eql/tests/encryption/tests/json_tree.rs: new testpostgres_containment_over_generated_documents_is_jsonb_containment, plus its generator.1/1.0/1e0,100/1e2,0/-0.0,0.5/5e-1). It also has strings that look like numbers, booleans or null, booleans, null, empty{}and[], root scalars and root arrays. A census asserts that each of these appears, so a later change to the generator cannot quietly drop one.public.eql_v4_json_treecolumn, and as plaintextjsonb. For every needle, the set of row ids that encrypted@>selects must equal the set thatjsonb @>selects over the plaintext. PostgreSQL computes thejsonbanswer in one statement.<@is checked the same way. The only allowed difference is the documented one, a stored root scalar inside a needle root array. The test asserts that this is the whole difference and that the case actually occurs.enable_seqscan = offand once with every index path off. Each@>plan is checked withEXPLAIN: it must be a bitmap scan on the GIN index in the first run and a plainSeq Scanin the second.<@has no index path, because GINjsonb_path_opsonly serves@>, so it runs as a scan both times.->path extraction (small add-on): at 20 generated key paths ($.a,$.a.b, …), the encrypted column has an entry exactly wherejsonb #>finds a node. A leaf opens (decrypts) to the valuejsonbholds there, compared with PostgreSQL'sjsonb =.EQL_JSON_TREE_SEEDoverrides it. A failure prints the seed, the needle, and every stored document the two answers disagree on.packages/eql/mise.toml:test:encryption:postgresnow passes--show-output, so the seed and summary line appear in the CI log even when the test passes. No other suite in that loop prints.Encryption uses the test crate's fake key source, so no CipherStash credentials are needed. The new test is
#[ignore]like the other PostgreSQL tests, sotest:encryption:postgres(--ignored) runs it, and in CI that is therust-encryption-postgresjob intest-eql.yml.Verification
Locally, against the EQL tasks' own Postgres (
mise run postgres:up postgres-N, port 7432), with the v4 bundle built from this tree:mise run test:encryption:postgreson PostgreSQL 17: every suite passes. The new test logged: 300 documents, 500 needles, 354 needles matching some row (17,028 matches), 162 root scalars excluded from<@, 117 leaves opened and 196 containers found by->, about 13.4 s.json_treesuite on PostgreSQL 14.24, 15.19 and 16.15: all 6 tests pass. The new test takes 15–17 s on each.<@exclusion. It failed with 68 disagreements, and each one named the seed, the needle and the stored documents (for example,row 97: 10.0matched by the needle[10,10,[{},{}]]). That confirms the failure report is usable. The change was reverted.cargo fmt --checkandcargo clippy --locked -p eql-bindings -p eql-encryption-tests --all-features --all-targets -- -D warningsare clean.vitestoverscripts/__tests__/eql-*andcrates-ci(the tests that parsepackages/eql/mise.tomland the workflows) pass.CI: the
Rust encryption with PostgreSQL 17job (job 120517712608) ranpostgres_containment_over_generated_documents_is_jsonb_containment ... ok, and the log shows the seed line and the same counts as the local run (seed 1336, 500 needles, 17,028 matches, 162<@exclusions), in 10.1 s. On a pull request,test-eql.ymlruns PostgreSQL 17 only. The 14–16 matrix runs on a push tomainand on the nightly schedule, so for this PR, versions 14–16 were checked locally only (above).No changeset: test-only.
Related
Refs #1336 (stacked on it: base
feat/json-tree-gates).https://claude.ai/code/session_01XQN1QpaWVDGjHEg39KEJF3