Skip to content

docs(stack-encrypt): ADR-0016, a context is a field path and named parts - #1772

Draft
coderdan wants to merge 1 commit into
nextfrom
docs/adr-context-parts
Draft

coderdan wants to merge 1 commit into
nextfrom
docs/adr-context-parts

Conversation

@coderdan

Copy link
Copy Markdown
Contributor

Summary

Stack Encrypt is CipherStash's Rust encryption engine. Every value it encrypts is tied to a context: the place the value was written for, such as a table, a column and a tenant. A value decrypts only under the context it was encrypted under.

Today the parts of a context are called scopes and bindings. Those words read as isolation and access control, and neither is: a row ID stored in the row restricts no reader, and a tenant ID is not a secret. This pull request adds a decision record (an ADR) that names the parts by what they protect, and amends three earlier records to match. It changes no code.

After it, a part of a context is one of three kinds:

  • A policy restricts who can read a value. ZeroKMS, the CipherStash key service, checks it: for example a claim in the reader's token, or a time limit.
  • A label is a fact that is safe to show, such as a row ID. It proves a value was written for that row. It restricts no reader.
  • A partition splits data into groups, such as tenants. It keeps one group's values and search terms apart from another's. It restricts no reader.

Changes

New: packages/stack-encrypt/docs/adr/0016-a-context-is-a-field-path-and-named-parts.md

  • A context is a field path and a list of named parts. Every part has one wire name, the same in every language SDK.
  • Policy is a sealed trait: only the key provider's own types implement it, so an application cannot call something a policy that nothing checks. Label and Partition are open.
  • The built-in parts: NotBefore, NotAfter, ForSub, ForTenant, TenantId<T>, RecordId<T> and Note<T>.
  • At encryption, the field path, the partitions and the labels go into key derivation in a fixed order, each part as its wire name and its value. A policy goes to the key provider with the key request.
  • A refinement adds a label or a policy to a value that is already stored, by changing its key tag. Nothing is encrypted again.
  • Every entry point takes named parts. The untyped Scope and Bind are removed, and a query narrows with .partition(..).
  • A record nested in another, with a scope of its own, no longer takes the outer record's names into its context.
  • How Go declares parts: struct tags label=, partition= and policy=, and one Cipher.With(..) method.
  • What every SDK takes from the record, and what Stack Encrypt requires of a key provider.

Amended: ADR-0004 (one context per target)

  • Scopes and bindings become named parts.
  • The kind and name of a part now decide its place in a derivation.
  • A nested record with its own scope keeps the outer names out.

Amended: ADR-0006 (descriptors, and Describe is open)

  • Describe is removed. Nothing takes it as a bound.
  • The Label struct is renamed FieldPath, so the name Label is free for the trait.

Amended: ADR-0010 (what a stored value authenticates)

  • A part present at encryption is authenticated by the leaf, as before.
  • A part added by a refinement is authenticated by the key tag, not by the leaf.
  • A label refinement can be undone by someone who can write the row. That is by design, and the record says so.

Verification

  • This is documentation only. I ran no build and no tests.
  • No script or workflow reads the ADR files: grep -rn 'docs/adr' scripts/ .github/workflows finds nothing.
  • The one commit is signed and authored by the human author: git log --format='%h %G? %an' origin/next..HEAD prints G.
  • No changeset: the change touches no published package's surface.

Related

Review notes

Start with the Summary and decisions 1, 2 and 5 of ADR-0016. The rest follows from them.

These points were not each decided one by one, so check them:

  • Two wire names follow the pattern. not_after, for_sub, tenant_id, record_id and note were agreed. not_before and for_tenant are mine.
  • context_from is left unchanged. It reads a field path from the plaintext, and a field path is a label and a partition. Go's context_field tag is removed, as agreed.
  • A part that is both a partition and a label is ordered with the partitions. The record needs one rule, and this keeps the query context a prefix of the stored context.
  • The number is 0016. The open pull request docs(stack-encrypt): key vendor backend design (CIP-5203) #1645 adds files numbered 0014 and 0015.

Deferred, with the reason:

  • The CONTEXT.md glossary still defines "scope" and "binding". It describes the code as it is, so it changes with the code.
  • The three plan documents from docs: define Stack Encrypt API redesign plan #1365, and the context contract in the language integration guide, are edited in a follow-up.
  • Three things are not decided: the name of a policy whose value the caller supplies, a label for data that is not safe to show, and whether keysets are removed.

ADR-0004's scopes and bindings sort a part of a context by whether a
query can supply it. That does not say who can read a value. A binding
stored in the row restricts no reader, and a tenant ID is not a secret,
yet both words read as access control. A part also has no name, so two
parts with one value are one context, and a part cannot be added to a
value after it is encrypted.

ADR-0016 names the parts. A part is a policy, a label or a partition,
and only a policy restricts readers. `Policy` is sealed to the key
provider's own types, so an application cannot call something a policy
that the key provider does not check. `Label` and `Partition` stay open.
The field path, the partitions and the labels go into key derivation in
a fixed order, each part as its wire name and its value. A refinement
adds a label or a policy afterwards by changing the key tag. The record
also says how Go declares parts, and what every SDK takes from it.

Three records are amended to match. ADR-0004 loses scopes, bindings and
the outer names in a nested record's context. ADR-0006 loses the open
`Describe` trait, and its `Label` struct becomes `FieldPath`, which is
the type #1663 asks for. ADR-0010 says a part added by a refinement is
authenticated by the key tag and not by the leaf.

No code changes. The plan documents, #1566, #1567, #1683 and #1572
follow separately.
@changeset-bot

changeset-bot Bot commented Nov 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: cafd0f7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

coderdan added a commit that referenced this pull request Nov 23, 2026
ADR-0016 (PR #1772) decides that a context is a field path and named
parts: policies, labels and partitions, with one wire name each. The
plan takes its words, its wire names and its rules, and gives the
TypeScript form: the built-in parts as functions, parts listed on a
record or read from a field, keyset.with(..) to carry them, and
.partition(..) on a query. A bare value in .withContext is a note.

Phase 2 now waits for the engine to have named parts, not for a design.
Phase 1 writes only values with no parts, which are the two forms the
ADR says keep their stored bytes, so .withContext moves to phase 2.
Refinements are in phase 3, with #1567.

This branch has not been deployed

No deployments
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.

1 participant