Skip to content

docs(guides): add a guide for moving off CipherStash - #113

Open
calvinbrewer wants to merge 2 commits into
mainfrom
cj/cip-4166-add-a-guide-for-moving-off-cipherstash-decrypt-and-exit
Open

calvinbrewer wants to merge 2 commits into
mainfrom
cj/cip-4166-add-a-guide-for-moving-off-cipherstash-decrypt-and-exit

Conversation

@calvinbrewer

Copy link
Copy Markdown
Contributor

Summary

Adds /guides/moving-off-cipherstash, the reverse of /guides/migration.

  • Sequence: add plaintext columns, dual-write, resumable decrypt backfill, verify coverage, build plaintext indexes, switch reads, stop writing and drop the EQL columns, optionally uninstall EQL. Includes a rollback-by-stage table.
  • Worked example: a resumable, idempotent bulkDecrypt backfill script (Stack SDK + pg), with a per-value failure path and an IS NULL guard against racing live writes. The guide says the CLI has no reverse-migration command yet and that the page will describe one when it exists. It documents no CLI command that does not exist.
  • Type mapping: each EQL domain family back to its Postgres type, including searchable JSON, plus the index replacement table.
  • Integrations: Stack SDK/Supabase, Proxy (nothing to undo on the query side), Drizzle and Prisma (schema types revert).
  • Lock contexts: decrypt as each user (one client per user), or decrypt on read; service credentials cannot decrypt locked values; plaintext loses per-user access control.
  • ZeroKMS dependency: plan the exit inside the notice period. Key export is in future tense ("is in development", "will remove").
  • Reference: /reference/stack/usage had no bulk documentation, so this adds a "Bulk operations" section (bulkEncrypt, bulkDecrypt, bulkEncryptModels, bulkDecryptModels). The generated TypeDoc API reference is not in the repo, so the section is hand-written.
  • Also: nav entry in content/docs/guides/meta.json, a cross-link from /guides/migration, and an IA.md checklist entry.

One deviation from the issue's step list: I added a dual-write step before the backfill. It mirrors the forward migration, and without it any row written after the backfill passes it is uncovered. The guide says to skip it only if all writers can be paused.

Verified against source

SDK and CLI (cipherstash/stack at 6ed8a232b, @cipherstash/stack 1.1.1):

  • bulkDecrypt(payloads): payload Array<{ id?, data: Encrypted | null }>, returns Result<Array<{ id?, data } | { id?, error }>>; input order preserved; nulls skipped and returned as data: null; empty input returns []; per-value errors via the fallible FFI primitive (encryption/index.ts, operations/bulk-decrypt.ts, types.ts).
  • bulkDecryptModels(models, table, lockContext?) returns one Result with no per-value entries; the lock context is positional or chained, not both (encryption/client-v3.ts, operations/mapped-decrypt.ts).
  • bulkDecrypt does no Date reconstruction; dates come back as stored strings (client-v3.ts, skills/stash-encryption).
  • .withLockContext({ identityClaim }) is accepted by bulkDecrypt; it needs an OidcFederationStrategy client; one client per user because the strategy caches a token; AccessKeyStrategy is invalid; the WASM entry has no lock context (identity/index.ts, skills/stash-auth, skills/stash-zerokms).
  • Import path for Encryption, encryptedTable, types is @cipherstash/stack/v3; OidcFederationStrategy is exported from the package root (src/index.ts, src/encryption/v3.ts, also at the 1.0.0 tag).
  • EQL domain families and their plaintext kinds (packages/test-kit/src/catalog.ts, packages/eql/src/v3 domain list, existing EQL reference pages). Index extractor recipes from the existing /reference/eql/indexes page.
  • EQL uninstall is exactly DROP SCHEMA IF EXISTS eql_v3 CASCADE; DROP SCHEMA IF EXISTS eql_v3_internal CASCADE;, and public.eql_v3_* domains and the columns typed with them survive (packages/eql/tasks/uninstall-v3.sql, tests/sqlx/tests/v3_uninstall_tests.rs, packages/eql/README.md).
  • Backfill script: type-checked against the current SDK source, and the SQL (cursor query, unnest batch update, IS NULL guard, bigint/date/numeric/boolean/jsonb/timestamptz array casts, resume, per-value failure, exit code) was run against a real Postgres 15 with a stubbed bulkDecrypt. The catalog queries in the uninstall step were also run against Postgres.
  • Dev server renders all three changed pages (HTTP 200, no MDX errors).

Batch size: the issue says default 500. Confirmed in cipherstash-client 0.42.2 (the version protect-ffi pins): DEFAULT_KEYS_PER_REQ = 500, DEFAULT_CONCURRENT_REQS = 5, decrypt groups payloads by keyset and chunks each group at that size. protect-ffi does not override either default. The SDK itself has no batch-size option; a call with more than 500 values is split by the client, not rejected. The guide words this as "up to 500 values per request by default".

Not verified or taken from the issue

  • "Decryption is never charged." Taken from the issue. The only supporting evidence I found is apps/dashboard/autumn.config.ts in cipherstash-js-suite, which tracks decryption_operations with a 1 trillion/month grant on every plan. Please confirm the wording with whoever owns pricing.
  • Key export is described only as "in development", future tense, per the issue. No source to check.
  • Numeric precision. Stack types numeric/real/double as JavaScript number. The guide warns about precision loss beyond a double and tells readers to compare against their system of record. I did not test precision behavior.
  • EQL does not record varchar(n), numeric(p,s), timestamp vs timestamptz, or json vs jsonb. The guide tells readers to take these from their pre-encryption schema.
  • Locked values that nobody can decrypt: the guide says choose between deleting them and keeping the encrypted column. I did not find a documented admin recovery path, so it does not mention one. How a lock-context denial surfaces inside a bulkDecrypt batch (per-value error vs whole-call failure) is not confirmed from source, so the guide does not claim either.
  • Proxy: the guide states only what the existing Proxy pages say (statements that reference no encrypted column pass through unchanged; an unmappable SELECT returns the raw payload). The column-swap option is a Postgres technique, not something I ran against Proxy.
  • Drizzle/Prisma: schema revert described from the existing integration pages; I did not run either ORM. The Prisma schema syntax is described in prose, not shown.
  • Stale docs, partly fixed: the first snippet in /reference/stack/usage imported encryptedColumn/encryptedTable from @cipherstash/stack and used .equality(). The package root exports neither (also true at the 1.0.0 tag). I changed it to @cipherstash/stack/v3 with types.TextEq("email") so the new bulk section can reuse users and encryption. Other pages, such as the wasm-inline import line in the Supabase edge-functions page, may have the same problem; I did not audit them.

Checks

  • bun run types:check: passes.
  • bun run validate-content: passes.
  • bun run lint: my files are clean. Two pre-existing format errors remain on origin/main (content/docs/security/meta.json, scripts/fixtures/stash-manifest.json).
  • bun run validate-links: no findings for the new or edited pages except /reference/stack/api-reference, which is generated at prebuild (generate-docs clones from GitHub) and is absent locally, as for every other page that links to it. I did not run the full next build because its prebuild needs network.

Closes #107

Linear: https://linear.app/cipherstash/issue/CIP-4166

🤖 Generated with Claude Code

calvinbrewer and others added 2 commits October 13, 2026 11:08
Add /guides/moving-off-cipherstash, the reverse of the data migration
guide: add plaintext columns, dual-write, resumable bulkDecrypt backfill,
verify coverage, switch reads, drop encrypted columns, optionally
uninstall EQL. Covers the EQL domain to Postgres type mapping, index
replacement, Proxy/Drizzle/Prisma differences, lock contexts, and the
ZeroKMS dependency.

Add a Bulk operations section to the Stack usage reference for
bulkEncrypt, bulkDecrypt, bulkEncryptModels, and bulkDecryptModels, and
correct the schema import in the usage example.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
public-docs Ready Ready Preview Oct 13, 2026 5:11pm UTC

Request Review

@freshtonic freshtonic left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.

Potential follow-up for this - should we have a test that validates an agent can follow the instructions?

This branch was successfully deployed

1 active deployment
Preview — 197047b6 Deployed Oct 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a guide for moving off CipherStash (decrypt and exit)

3 participants