Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions languages/golang/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ and `languages/golang/encrypt/encrypttest/vX.Y.Z` on the same commit.
`[16]byte` (`github.com/google/uuid.UUID`, say), which is converted to
one. `stashgen` does not yet map a Go type to it.

### Fixed

- **The `encrypt` and `stashgen` READMEs say a query through a cipher with
a binding is refused** (#1862). The refusal is `ErrEncoding`. Query
through a cipher with the same scope and no binding, then open the row
through the cipher with the binding. The READMEs did not say that such a
query is refused.
- **The `encrypt` README's note on the context names bindings** (#1862).
The context binds each value to its scopes and any bindings too. The
note now gives `cipher.Scope(tenant).Bind(rowID)` as a way to tie a
value to its row. A cipher with a binding cannot query. The note also
keeps the `context_field` way. A `context_field` can query within one
context. Before, the note offered only the `context_field`.

## [0.1.0-rc.7] - 2026-11-25

### Upgrading from rc.6
Expand Down
6 changes: 4 additions & 2 deletions languages/golang/cmd/stashgen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,10 @@ Put the column on the left of `@@` (`WHERE name @@ $1::eql_v4.query_text_match`)
`encrypt_into` with any other type is refused with the type's name and the reason it is not produced yet.
Separate columns work today for four indexes: `equality`, `match`, `ore` and `ope`.

A field with `encrypt_into` is stored under its table and column, which is what an EQL value records in its `i`.
A cipher with a scope or a binding (`cipher.Scope(tenant).Bind(rowID)`) seals a struct with an `encrypt_into` field as it seals any other. The scope and the binding come after the column in the field's context, and `i` still holds the table and the column alone. Open the value through a cipher with the same scope and binding, and query it through a cipher with the same scope.
A field with `encrypt_into` is stored under its table and column. An EQL value records them in its `i`.
A cipher with a scope or a binding (`cipher.Scope(tenant).Bind(rowID)`) seals a struct with an `encrypt_into` field as it seals any other. The scope and the binding come after the column in the field's context, and `i` still contains the table and the column alone.

Open the value through a cipher with the same scope and binding. Query it through a cipher with the same scope and no binding, such as `cipher.Scope(tenant)`. A query through a cipher with a binding is refused with `ErrEncoding`, because a binding is in no query context.

## When stashgen stops

Expand Down
48 changes: 35 additions & 13 deletions languages/golang/encrypt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,24 @@ cannot use different ones.

> **Take care**
>
> The context binds each value to its table, its column and the cipher's
> extension. It does not bind the value to its row, so a value copied to
> another row of the same table decrypts there with no error. To bind each
> row to a context of its own, such as its tenant, give the struct a
> `context_field` instead of a `context=` tag:
> The context binds each value to its table, its column, the cipher's
> scopes, and any bindings. Without a binding or a `context_field`, a value
> copied to another row of the same table decrypts there with no error.
> There are two ways to tie a value to its row.
>
> **Bind the value to its row ID.** Encrypt and decrypt through
> `cipher.Scope(tenant).Bind(rowID)`. A value sealed this way opens only
> through a cipher with the same scope and binding. A value copied to
> another row does not open under that row's ID.
>
> A cipher with a binding cannot query: every query method refuses it with
> `ErrEncoding`. Query through `cipher.Scope(tenant)`, then open each row it
> finds through the cipher with that row's binding.
>
> **Give the struct a `context_field`** instead of a `context=` tag. The
> field stays queryable, within one context. The value is tied to the
> context its row stores, such as its tenant, rather than to the row
> itself:
>
> ```go
> type Note struct {
Expand All @@ -228,16 +241,20 @@ cannot use different ones.
> ```
>
> The field's value is the context every other field is sealed under, a
> label such as `"tenants/acme"`. It is stored as it is, in the clear and
> unauthenticated like a passthrough field, so the row names its own
> context. A row's sealed values open only under the context the row
> label such as `"tenants/acme"`. The field is stored as it is, in the
> clear and unauthenticated like a passthrough field, so the row names its
> own context. A row's sealed values open only under the context the row
> stores: a value copied to another tenant's row does not decrypt there.
> A value copied to another row with the same context does decrypt there.
>
> `Encrypt` and `Decrypt` take each row's context from the row.
> `cipher.Context("tenants/acme")` names the context every row through the
> cipher is under: `Decrypt` then refuses a row stored under another tenant
> with `ErrContextMismatch`, before any key is retrieved, and `Encrypt`
> refuses a value whose field says otherwise. A query on such a type derives
> its term under the context the cipher names, and fails without one.
> cipher is under. `Decrypt` then refuses a row stored under another tenant
> with `ErrContextMismatch`, before any key is retrieved. `Encrypt` refuses
> a value whose field says otherwise.
>
> A query on such a type derives its term under the context the cipher
> names, and fails without one. So a query through `cipher.Context("tenants/acme")` finds that tenant's rows.

`Client.DefaultKeyset()` is the keyset a ZeroKMS administrator set for the
client; `Client.Keyset(encrypt.KeysetName(..))` or `Client.Keyset(id)` any
Expand Down Expand Up @@ -749,7 +766,12 @@ The scope and the binding come after the column in the field's context.
The EQL value stores the table and the column alone, in `i`, so:

- open the value through a cipher with the same scope and binding;
- query it through a cipher with the same scope. A binding is in no query;
- query it through a cipher with the same scope and no binding, such as
`cipher.Scope(tenant)`. A binding is in no query context, so a query
through a cipher with a binding is refused with `ErrEncoding`. The
refusal covers every query method, such as `Eq`, `Matches`, and
`Contains`. The query by the scope alone finds the row. Open the row
it finds through `cipher.Scope(tenant).Bind(rowID)`;
- read part of a `JsonSearch` document (`Selector`, `Subtree`, `Children`)
through a cipher with the same scope and binding. The selector or the
tokens derive under the scope alone, as a query does, and the entries
Expand Down
Loading