Skip to content

stack-encrypt: move the JsonDocument EQL simulators (find, children, subtree, node) out of the public API #1755

Closed

Description

@coderdan

Background

Stack Encrypt is the Rust library that encrypts values for CipherStash. Stack Encrypt can store an encrypted JSON document in PostgreSQL as an index of encrypted entries, one entry per node of the document.

Encrypt Query Language (EQL) is the SQL library CipherStash installs in the customer's database. The EQL functions eql_v4.json_tree_* search that index. These functions never decrypt anything. Reading part of a document takes three steps:

  1. Your app derives a token for the path to read.
  2. The database runs an EQL function with that token, such as eql_v4.json_tree_children. EQL returns the matching encrypted entries.
  3. Your app checks each entry and decrypts it.

Problem

JsonDocument has four public methods that do step 2 in Rust instead of in the database:

Method What it copies
find(token) How EQL finds the entry a token names
children(token) eql_v4.json_tree_children
subtree(tokens) eql_v4.json_tree_subtree
node(slot) Builds the row the database would return for one entry

The methods are in packages/stack-encrypt/src/json/mod.rs. Tests and doc examples use them so they can run without PostgreSQL.

These methods confuse readers of the API:

  • The methods look like part of the normal way to read a document, but an app never calls them in production. The database does this work.
  • Doc examples call them without saying they stand in for the database. A reader cannot tell which steps happen in Rust and which happen in EQL.
  • Each one is public API, so changing it later is a breaking change.

Nothing marks them as test helpers today.

Proposal

  1. Move the four methods into a module whose name says what they are, such as stack_encrypt::eql_simulator.
  2. Put the module behind a Cargo feature that is off by default, such as eql-simulator.
  3. Turn the feature on for the crate's own tests and doc examples, and for the EQL encryption test crate in packages/eql/tests/encryption.
  4. Start the module's documentation by saying that it copies what EQL does in the database, and that production code does not use it. Name the SQL function each method copies.
  5. Keep a crate-private find for the library's own use: decrypting a whole document calls it.
  6. In every doc example that uses the module, add one comment that shows the real SQL query.
  7. Add a "Breaking" entry to the stack-encrypt CHANGELOG that tells users how to upgrade.

Relationship to other work

The review of #1751 found this problem. #1751 adds JsonSubtreeKey::open_child, the real step 3 for one child, and its doc examples use children and node.

Activity

  1. added a commit that references this issue on Nov 23, 2026
    22f1d3a
  2. self-assigned this
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions