Skip to content

Commit 7246df1

Browse files
committed
Merge feat/json-tree-data-plan into feat/json-tree-queries-reads
Brings in the vitaminc d7de535c4 pin for vcffi/vcvalue and the go-release guard that refuses a final version while go.mod names a pseudo-version, with the opaque storage profile's two fixes beneath them. Claude-Session: https://claude.ai/code/session_01N7bCqa3ZVJMcEE99RzVqEu
2 parents e91856e + 15f5aea commit 7246df1

14 files changed

Lines changed: 550 additions & 120 deletions

File tree

‎.github/workflows/release-golang.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ name: Release (Go)
2020
# The ref must carry the EQL v4 bundle (packages/eql's v4 build), or the
2121
# build job stops at "Build the EQL SQL bundles". A version with a pre-release
2222
# suffix may be cut from any branch and is published as a GitHub pre-release;
23-
# a final version is cut from main only (scripts/go-release-version.mjs).
23+
# a final version is cut from main only, and not while go.mod pins vitaminc's
24+
# Go bindings at a pseudo-version (scripts/go-release-version.mjs).
2425
#
2526
# Three jobs, split by what they may touch:
2627
#

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Every npm package except EQL lives under `languages/typescript/`: packages in `l
9292
links are provenance only.
9393
- `packages/stack-auth`, `packages/stack-profile`, `packages/stack-kms`, `packages/stack-encrypt`, `packages/stack-encrypt-derive`, `packages/stack-guest-abi`: The Rust crates imported from `cipherstash/cipherstash-suite` with their history — `stack-auth` and `stack-profile` (published to crates.io, one version group), `stack-kms` (published to crates.io from 0.1.0, its own version group, re-exported by `stack-encrypt` as `stack_encrypt::kms`), `stack-encrypt` and `stack-encrypt-derive` (published to crates.io from 0.1.0, one version group; `eql-bindings`' `stack-encrypt` feature depends on them from the registry), and `stack-guest-abi` (`publish = false`). They are the members of the **root Cargo workspace**, with the three node binding crates below. See "Working on the Rust crates".
9494
- `languages/typescript/packages/auth`, `languages/typescript/packages/profile`, `languages/typescript/packages/stack-auth-wasm`: The node bindings of those crates. `@cipherstash/auth` (napi-rs v2) and its six `platforms/*` packages are published to npm from this repository by `release.yml` (`auth-artifacts`, `publish-auth`); a change to what it ships, the `stack-auth` crate included, needs an `@cipherstash/auth` changeset (`require-auth-npm-changeset.yml`). `@cipherstash/profile` and its platforms are private and never published; `@cipherstash/stack-auth-wasm` is private and builds the wasm that `@cipherstash/auth` ships. Their `build` and `test` scripts never invoke cargo; `build:native`, `build:debug` and `test:cargo` do.
95-
- `languages/golang`: The Go module — the SDK `encrypt` with its generated-code support `encrypt/gensupport` and the policy packages `encrypt/policy` and `encrypt/policy/protosource`; the credential package `auth`; the generator `stashgen` and its command `cmd/stashgen`; and `internal` (the shared guest plumbing and the `record` wire model). A wazero host with no cgo. Its two WASI guests (`encrypt/guest`, `auth/guest`) are detached Cargo workspaces built by `mise run wasm:guest:build` and `mise run wasm:auth-guest:build`; `mise run wasm:guest:build:deterministic` builds the seeded TEST build the hermetic Go tests use; the `.wasm` files they embed are gitignored. The stack-encrypt guest has a second build with the EQL types (`mise run wasm:guest:build:eql`, cargo feature `eql`, linking `eql-bindings` by path; `wasm:guest:build:eql:deterministic` is its test build), embedded by `encrypt/eql` and registered on import, so a program whose generated code names an EQL type runs it (ADR-0007, amended). `encrypt/eql`'s types and `Types` table are generated from the EQL catalog by `eql-codegen` (`eql_gen.go`, written by `mise run types:generate` in `packages/eql` and drift-gated by `types:check` and `cargo test -p eql-codegen`). Generated `*_stash.go` files are committed and CI fails when `go generate ./...` changes one. Releases are cut by hand with `.github/workflows/release-golang.yml` (`gh workflow run release-golang.yml -f version=X.Y.Z[-pre] --ref <branch>`): because the guests are gitignored on main and Go fetches a version as the files committed at its tag, the workflow builds them, commits them on a release-only commit no branch points at, tags it `languages/golang/vX.Y.Z` and pushes the tag alone, then attaches the EQL v4 SQL bundle to the GitHub release. The ref must carry the EQL v4 bundle, or the build stops at "Build the EQL SQL bundles". `scripts/go-release-version.mjs` refuses, before anything is built, every version Go would refuse (non-canonical semver, `+build` metadata, a v2+ major on a module path with no `/vN` suffix, a version shaped like a pseudo-version), and a final version dispatched from anywhere but `main`; a pre-release may come from a branch. The build job also refuses a version the Go proxy already lists in `@v/list`, which catches a tag deleted after the proxy fetched it; it never asks the proxy for the version itself before the tag exists, because the proxy would cache "not found" for up to 30 minutes and `verify` would fail after the push. The build checks the `Cargo.lock` of the EQL workspace and both guest workspaces with `--locked` first, since none of those builds passes it. It runs in a job with no write token and hands the guests to a `publish` job that holds `contents: write` and runs only git and gh. `publish` fetches the commit with plain unauthenticated git rather than `actions/checkout`, whose `token` input defaults to the job's writable token, and refuses a release commit whose tree is not the one the build tested. `publish` takes the paths it commits from the workflow's fixed `GUESTS` list, never from the artifact, and refuses a `guests.sha256` that is not exactly one SHA-256 line for each of those three guests: the build job runs third-party code after writing that manifest, so a path read from it could put any file on the tag (`scripts/__tests__/go-release-artifact.test.mjs`). A version is immutable once the Go proxy has fetched it, so a tag is never moved or deleted: if `publish` or `verify` fails after the tag is pushed, use "Re-run failed jobs" on the same run, which keeps a tag that run pushed and creates or completes the release; a new dispatch of the same version is refused. Never tag a main commit by hand: `go get` would fetch a module with no guests.
95+
- `languages/golang`: The Go module — the SDK `encrypt` with its generated-code support `encrypt/gensupport` and the policy packages `encrypt/policy` and `encrypt/policy/protosource`; the credential package `auth`; the generator `stashgen` and its command `cmd/stashgen`; and `internal` (the shared guest plumbing and the `record` wire model). A wazero host with no cgo. Its two WASI guests (`encrypt/guest`, `auth/guest`) are detached Cargo workspaces built by `mise run wasm:guest:build` and `mise run wasm:auth-guest:build`; `mise run wasm:guest:build:deterministic` builds the seeded TEST build the hermetic Go tests use; the `.wasm` files they embed are gitignored. The stack-encrypt guest has a second build with the EQL types (`mise run wasm:guest:build:eql`, cargo feature `eql`, linking `eql-bindings` by path; `wasm:guest:build:eql:deterministic` is its test build), embedded by `encrypt/eql` and registered on import, so a program whose generated code names an EQL type runs it (ADR-0007, amended). `encrypt/eql`'s types and `Types` table are generated from the EQL catalog by `eql-codegen` (`eql_gen.go`, written by `mise run types:generate` in `packages/eql` and drift-gated by `types:check` and `cargo test -p eql-codegen`). Generated `*_stash.go` files are committed and CI fails when `go generate ./...` changes one. Releases are cut by hand with `.github/workflows/release-golang.yml` (`gh workflow run release-golang.yml -f version=X.Y.Z[-pre] --ref <branch>`): because the guests are gitignored on main and Go fetches a version as the files committed at its tag, the workflow builds them, commits them on a release-only commit no branch points at, tags it `languages/golang/vX.Y.Z` and pushes the tag alone, then attaches the EQL v4 SQL bundle to the GitHub release. The ref must carry the EQL v4 bundle, or the build stops at "Build the EQL SQL bundles". `scripts/go-release-version.mjs` refuses, before anything is built, every version Go would refuse (non-canonical semver, `+build` metadata, a v2+ major on a module path with no `/vN` suffix, a version shaped like a pseudo-version), a final version dispatched from anywhere but `main`, and a final version while `languages/golang/go.mod` pins a `github.com/cipherstash/vitaminc/…` module at a pseudo-version (vitaminc's Go bindings have no tags, and a TEMPORARY pin on an unreleased commit must be gone before the module is tagged); a pre-release may come from a branch and may carry such a pin. The build job also refuses a version the Go proxy already lists in `@v/list`, which catches a tag deleted after the proxy fetched it; it never asks the proxy for the version itself before the tag exists, because the proxy would cache "not found" for up to 30 minutes and `verify` would fail after the push. The build checks the `Cargo.lock` of the EQL workspace and both guest workspaces with `--locked` first, since none of those builds passes it. It runs in a job with no write token and hands the guests to a `publish` job that holds `contents: write` and runs only git and gh. `publish` fetches the commit with plain unauthenticated git rather than `actions/checkout`, whose `token` input defaults to the job's writable token, and refuses a release commit whose tree is not the one the build tested. `publish` takes the paths it commits from the workflow's fixed `GUESTS` list, never from the artifact, and refuses a `guests.sha256` that is not exactly one SHA-256 line for each of those three guests: the build job runs third-party code after writing that manifest, so a path read from it could put any file on the tag (`scripts/__tests__/go-release-artifact.test.mjs`). A version is immutable once the Go proxy has fetched it, so a tag is never moved or deleted: if `publish` or `verify` fails after the tag is pushed, use "Re-run failed jobs" on the same run, which keeps a tag that run pushed and creates or completes the release; a new dispatch of the same version is refused. Never tag a main commit by hand: `go get` would fetch a module with no guests.
9696
- `e2e/*`: Cross-package end-to-end tests (package managers, supply chain, Prisma example README)
9797
- `languages/typescript/examples/*`: Working apps (basic, prisma, supabase-worker)
9898
- `docs/plans/*`: Internal design plans. User-facing documentation lives at https://cipherstash.com/docs (not in this repo).

‎languages/golang/CHANGELOG.md‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ listed under **Breaking**. Releases are tagged `languages/golang/vX.Y.Z`.
9292
form for them), a type with only one of `MarshalText` and
9393
`UnmarshalText`, a map key that is not an integer, a string, bytes or
9494
text, and a type that only `MarshalJSON` carries over a struct with
95-
unexported fields. A blob a later release writes is
95+
unexported fields. **Rows already sealed with an `encrypt.Decimal` or
96+
`encrypt.Date` in an opaque struct do not decrypt under this release**,
97+
since no generated file can name the field: before upgrading, decrypt
98+
them with the earlier release, change the field to a string (or to its
99+
parts), and encrypt them again; the earlier release writes JSON, which
100+
this release reads. A blob a later release writes is
96101
`encrypt.ErrStorageVersion`. This takes vcffi from the unreleased
97102
cipherstash/vitaminc#526 by pseudo-version; the storage format is a
98103
compatibility commitment only once vitaminc releases it, so no Go
@@ -242,15 +247,20 @@ listed under **Breaking**. Releases are tagged `languages/golang/vX.Y.Z`.
242247

243248
### Changed
244249

245-
- **vitaminc's Go bindings from cipherstash/vitaminc#526 (temporary).**
246-
`vcffi` and `vcvalue` move to an unreleased commit, for the storage
247-
profile (`vcffi.MarshalStorage`). One encoding changes with them: a nil
248-
pointer to a fixed-width value (`(*int64)(nil)`) is written as a typed
249-
null where it was written as a null. The engine reads a typed null as a
250-
null, and generated code passes an untyped nil for a nil pointer, so
251-
this only shows in the bytes a hand-built `record.Source` or query input
252-
sends. The pin returns to a vitaminc release before this module is
253-
tagged.
250+
- **vitaminc's Go bindings at an unreleased vitaminc commit (temporary).**
251+
`vcffi` and `vcvalue` move to vitaminc `d7de535c4`, the merge of
252+
cipherstash/vitaminc#526 into its `feat/aead-frame-storage-profile`
253+
branch, for the storage profile (`vcffi.MarshalStorage`); vitaminc's Go
254+
bindings have no tags, so the commit is the pin. One encoding changes
255+
with them, and it comes from vitaminc `e9c3837b` (on `main`, in no Go
256+
tag yet), not from the storage profile: a nil pointer to a fixed-width
257+
value (`(*int64)(nil)`) is written as a typed null where it was written
258+
as a null. The engine reads a typed null as a null, and generated code
259+
passes an untyped nil for a nil pointer, so this only shows in the bytes
260+
a hand-built `record.Source` or query input sends. The pin returns to a
261+
vitaminc release before this module is tagged:
262+
`scripts/go-release-version.mjs` refuses a final version while `go.mod`
263+
names a vitaminc pseudo-version.
254264
- **An EQL v4 block ORE term is one hex string.** The `ob` of a value
255265
encrypted into an `_ord_ore` or `text_search_ore` EQL type is
256266
`"ob": "0202…"`, where it was a one-element array, and the EQL v4 bundle

‎languages/golang/cmd/stashgen/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ An `opaque` struct crosses as one storage blob and is one column, read back into
277277
The blob is vitaminc's storage profile, version 1 (`vcffi.MarshalStorage`), the format vitaminc keeps readable across releases and languages.
278278
A field may be any type that both the storage profile and `encoding/json` carry both ways: a scalar or a type defined over one, `[]byte`, slices, maps with string or integer keys, pointers, structs whose fields are all exported, and types with both `MarshalText` and `UnmarshalText`, such as `time.Time`.
279279
`encrypt.Decimal` and `encrypt.Date` have no storage form and are refused in an opaque struct: store them as text, or by their parts.
280+
A row an earlier release sealed with one of them in an opaque struct does not decrypt under this release, because no generated file can name the field: decrypt such rows with the earlier release, change the field's type, and encrypt them again before upgrading.
280281
The generated shape struct tags each field `vc:"name,default"`, so a field added to the opaque struct reads as its zero value from a row sealed before it; a field added to a nested struct type needs a pointer type for the same.
281282
`Encrypt` refuses a string that is not UTF-8 and a value nested more than 128 levels deep, as `encrypt.ErrEncoding`.
282283
`encoding/json` still matters because a row an earlier release sealed holds a JSON document, and `Decrypt` reads it as JSON.

‎languages/golang/encrypt/gensupport/codec.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,13 @@ func Opaque[T any](vals Values, out *T) error {
424424
}
425425
return nil
426426
}
427+
// encoding/json writes a struct as an object, so a JSON document of
428+
// the shape struct begins "{"; a value that begins with neither is not
429+
// one either reader can take, and is said so rather than handed to
430+
// the JSON reader to fail on.
431+
if !bytes.HasPrefix(encoded, []byte("{")) {
432+
return fmt.Errorf("gensupport: %w: the opaque value is neither a storage blob nor a JSON document", encrypt.ErrEncoding)
433+
}
427434
if err := json.Unmarshal(encoded, out); err != nil {
428435
// Its error is not wrapped: encoding/json's text quotes the value.
429436
return fmt.Errorf("gensupport: %w: the opaque value does not decode into a %T", encrypt.ErrEncoding, *out)

‎languages/golang/encrypt/gensupport/gensupport_internal_test.go‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ func TestConvertStaysWithinAFamily(t *testing.T) {
181181
if err := Opaque(Values{OpaqueField: future}, &back); !errors.Is(err, encrypt.ErrEncoding) || !errors.Is(err, vcffi.ErrUnsupportedVersion) {
182182
t.Fatalf("Opaque of a version %d blob: %v", vcffi.StorageVersion+1, err)
183183
}
184+
// A value that is neither a storage blob nor a JSON object (a JSON
185+
// array, a header cut short of its "S", nothing at all) is refused as
186+
// such, by neither reader.
187+
for _, neither := range [][]byte{[]byte("[]"), []byte("VC"), []byte("VC\x01"), {}, []byte("null")} {
188+
err := Opaque(Values{OpaqueField: neither}, &back)
189+
if !errors.Is(err, encrypt.ErrEncoding) || !strings.Contains(err.Error(), "neither a storage blob nor a JSON document") {
190+
t.Fatalf("Opaque of %q: %v", neither, err)
191+
}
192+
}
184193
if err := Opaque(Values{OpaqueField: "not bytes"}, &back); err == nil {
185194
t.Fatal("Opaque accepted a string")
186195
}
@@ -340,6 +349,28 @@ func TestDecryptErrorsHoldNoPlaintext(t *testing.T) {
340349
}
341350
}
342351

352+
// A pointer to a type with MarshalText and UnmarshalText (*time.Time) is
353+
// written as its element's text, nil as null, and read back into a new
354+
// element: what stashgen accepts such a field on the strength of.
355+
func TestAnOpaqueStructCarriesAPointerToATextType(t *testing.T) {
356+
at := time.Date(2026, 10, 26, 5, 3, 16, 0, time.UTC)
357+
type stamped struct {
358+
At *time.Time `vc:"at,default"`
359+
Ats []*time.Time `vc:"ats,default"`
360+
}
361+
blob, err := opaqueBytes(stamped{At: &at, Ats: []*time.Time{&at, nil}})
362+
if err != nil {
363+
t.Fatal(err)
364+
}
365+
var got stamped
366+
if err := Opaque(Values{OpaqueField: blob}, &got); err != nil {
367+
t.Fatal(err)
368+
}
369+
if got.At == nil || !got.At.Equal(at) || len(got.Ats) != 2 || got.Ats[0] == nil || !got.Ats[0].Equal(at) || got.Ats[1] != nil {
370+
t.Fatalf("*time.Time came back as %+v", got)
371+
}
372+
}
373+
343374
// mustStorage is v as a storage blob.
344375
func mustStorage(t *testing.T, v any) []byte {
345376
t.Helper()

‎languages/golang/encrypt/gensupport/gensupport_test.go‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"log/slog"
66
"strings"
77
"testing"
8+
"time"
89
)
910

1011
func TestRedactedHidesSealedFieldsAndSortsShown(t *testing.T) {
@@ -73,3 +74,31 @@ func TestVersionConstantIsTyped(t *testing.T) {
7374
t.Fatalf("GeneratedVersion2 = %d", GeneratedVersion2)
7475
}
7576
}
77+
78+
// Deref is how generated code passes a field declared over a pointer, and
79+
// it is why a nil pointer never reaches the codec typed: the untyped nil it
80+
// gives is == nil, so Seal leaves a null=sql field out and the engine sees a
81+
// plain null elsewhere, while the typed nil itself is not == nil and would be
82+
// sent as a typed null of the pointer's type (see encrypt's typed_nil_test).
83+
func TestDerefGivesAnUntypedNilForANilPointer(t *testing.T) {
84+
// The contrast Deref exists for: the same pointer, as an interface
85+
// value, is not == nil. (Through a call, so the checker does not fold
86+
// the comparison away.)
87+
asAny := func(v any) any { return v }
88+
if asAny((*int64)(nil)) == nil {
89+
t.Fatal("a typed nil pointer is == nil as an interface; this test pins the opposite")
90+
}
91+
if v := Deref((*int64)(nil)); v != nil {
92+
t.Fatalf("Deref((*int64)(nil)) = %#v, want an untyped nil", v)
93+
}
94+
if v := Deref((*time.Time)(nil)); v != nil {
95+
t.Fatalf("Deref((*time.Time)(nil)) = %#v, want an untyped nil", v)
96+
}
97+
n, when := int64(7), time.Unix(1_700_000_000, 0).UTC()
98+
if v := Deref(&n); v != int64(7) {
99+
t.Fatalf("Deref(&7) = %#v, want the int64 7", v)
100+
}
101+
if v := Deref(&when); v != when {
102+
t.Fatalf("Deref(&when) = %#v, want the time", v)
103+
}
104+
}

0 commit comments

Comments
 (0)