Repository navigation
docs(go): typed JSON walkthrough and accurate EQL reference #1402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2e95042
docs(go): add typed JSON walkthrough and correct EQL reference
coderdan be96a9e
fix(go): close example query rows on error
coderdan 657d7d8
docs(go): build embedded guests before source tests
coderdan 311df36
Merge remote-tracking branch 'origin/next' into docs/go-typed-json-do…
coderdan 238ac9a
docs(go): align match release notes with two-letter queries
coderdan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # CipherStash Stack for Go | ||
|
|
||
| This module provides searchable field encryption for Go structs. `stashgen` | ||
| turns `stash` tags into typed encryption, decryption and query methods. The | ||
| `encrypt` package runs the Rust encryption engine in an embedded WASI guest | ||
| with wazero; applications do not need cgo. | ||
|
|
||
| Start with the [SDK guide](encrypt/README.md) for installation, credentials, | ||
| generation and PostgreSQL storage. The [stashgen reference](cmd/stashgen/README.md) | ||
| explains tags, supported field types and generated methods. The | ||
| [typed JSON document example](encrypt/example/json/README.md) walks through | ||
| an EQL v4 table, queries and partial reads. The [credential guide](auth/README.md) | ||
| covers profile, access key and federation strategies. See the | ||
| [Go changelog](CHANGELOG.md) for release and compatibility notes. | ||
|
|
||
| ## Using a released module | ||
|
|
||
| Use Go 1.26.10 or later (or 1.27.3 or later on the 1.27 line). Add the | ||
| generator to your application module, declare a struct with `stash` | ||
| tags, then generate and commit its `*_stash.go` file: | ||
|
|
||
| ```sh | ||
| go get -tool github.com/cipherstash/stack/languages/golang/cmd/stashgen | ||
| go generate ./... | ||
| ``` | ||
|
|
||
| Use a tagged Go module version. Release tags include the embedded WASI guests; | ||
| a checkout or an untagged commit does not. The [SDK guide](encrypt/README.md#building) | ||
| explains how to build them locally. Searchable `encrypt_into` fields require | ||
| EQL v4 in PostgreSQL; the EQL v4 SQL bundle is attached to the matching Go | ||
| release. Go and TypeScript currently use different EQL versions, so follow | ||
| the [EQL column guide](encrypt/README.md#eql-columns) when choosing a schema. | ||
|
|
||
| ## Working in this repository | ||
|
|
||
| From the repository root, install the toolchain pinned by `mise.toml` and | ||
| build the guests before running Go tests: | ||
|
|
||
| ```sh | ||
| mise run wasm:guest:build | ||
| mise run wasm:guest:build:eql | ||
| mise run wasm:guest:build:deterministic | ||
| mise run wasm:guest:build:eql:deterministic | ||
| mise run wasm:auth-guest:build | ||
| mise run go:test | ||
| ``` | ||
|
|
||
| The `.wasm` files are build outputs and are not committed on development | ||
| branches. `mise run go:test:postgres` also runs the PostgreSQL suite against | ||
| the EQL v4 bundle built from this tree; it needs the database named by | ||
| `EQL_TEST_DATABASE_URL`. See `mise.toml` and [AGENTS.md](../../AGENTS.md) | ||
| for the build and release details. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Typed encrypted JSON document example | ||
|
|
||
| This program stores a Go `Profile` struct as one encrypted EQL v4 JSON column. | ||
| It finds a row by containment, compares an ordered path, decrypts a whole | ||
| profile, and opens only the visit times from another query. | ||
|
|
||
| ## Run | ||
|
|
||
| You need Go 1.26.10 or later, PostgreSQL with the EQL v4 SQL bundle installed, a `DATABASE_URL` | ||
| pointing to it, and CipherStash credentials. `stash auth login` writes a | ||
| developer profile; the `CS_*` environment variables also work. The example | ||
| creates a temporary table, so it does not leave data behind. | ||
|
|
||
| From the repository root: | ||
|
|
||
| ```sh | ||
| mise run wasm:guest:build:eql wasm:auth-guest:build | ||
| export DATABASE_URL='postgres://localhost:5432/your_database' | ||
| cd languages/golang | ||
| go run ./encrypt/example/json | ||
| ``` | ||
|
|
||
| For a fresh database, install the `eql-v4-install.sql` asset attached to the | ||
| Go module release before running the program. The guest builds are needed in | ||
| a repository checkout because its WASM files are not committed. A tagged Go | ||
| module version carries them. | ||
|
|
||
| ## Change the model | ||
|
|
||
| The declaration is in `model.go`. `stashgen` writes `customer_stash.go` from | ||
| its `stash` tags. After changing the struct or tags, run this from | ||
| `languages/golang` and commit the changed generated file: | ||
|
|
||
| ```sh | ||
| go generate ./encrypt/example/json | ||
| ``` | ||
|
|
||
| `Profile` uses `encoding/json` for the document shape. The `ordered=$.age` | ||
| tag adds an ordering term for that path. A containment needle made from a | ||
| struct includes every field without `omitempty`, including zero values; | ||
| `main.go` uses a map to name only the member being queried. The prepared | ||
| subtree read returns JSON text, which `encrypt.DecodeJSON[int64]` decodes. | ||
|
|
||
| The example's `SELECT` statements cast parameters to EQL's operand types. | ||
| The age comparison uses the selector derived from the same ordered path as | ||
| its query term. A JSON selector or read token is a capability over a column; | ||
| do not log it. Partial reads authenticate returned entries against the | ||
| prepared request, but do not prove that the database returned every entry. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a fresh checkout, this sequence does not produce the production encryption guests required by
mise run go:test. Inmise.toml, the two deterministic tasks copy their outputs only intoencrypt/testdata/, whereasscripts/go-binding-test.shexplicitly requiresencrypt/wasm/stack_encrypt_guest.wasmandencrypt/eql/wasm/stack_encrypt_guest_eql.wasmand exits before running tests if either is absent. Addwasm:guest:buildandwasm:guest:build:eqlalongside the deterministic builds, and update the identical sequence inCONTRIBUTING.mdas well.Useful? React with 👍 / 👎.