Skip to content
Draft
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
88 changes: 88 additions & 0 deletions .github/workflows/integration-azure-key-vault.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Integration — stack-kms-azure (Azure Key Vault)

# stack-kms-azure against real Azure Key Vault and, optionally, Managed HSM
# (tests/live.rs). Microsoft publishes no Key Vault emulator, so unlike the
# LocalStack and Vault jobs in tests-crates.yml this needs a real key and real
# credentials. Every other stack-kms-azure test runs in tests-crates.yml,
# against fixtures and an in-process emulator.
#
# OPT-IN. The job runs only when the repository variable
# STACK_KMS_AZURE_LIVE_KEY is set, so the workflow is inert until someone sets
# up the Azure side. To turn it on:
#
# 1. Create an RSA key (2048 bits or more) in a Key Vault, for this test
# only. Optionally, create an oct-HSM AES-256 key in a Managed HSM too
# (a Managed HSM is billed by the hour, so this part is optional).
# 2. Create an app registration (service principal) with a client secret.
# Give it the role "Key Vault Crypto Service Encryption User" on the key
# and nothing else ("Managed HSM Crypto Service Encryption User" on the
# HSM key, if there is one).
# 3. Set the repository variable STACK_KMS_AZURE_LIVE_KEY to the key
# identifier (https://<vault>.vault.azure.net/keys/<name>), and, for the
# HSM, STACK_KMS_AZURE_LIVE_HSM_KEY
# (https://<hsm>.managedhsm.azure.net/keys/<name>). Set the repository
# secrets STACK_KMS_AZURE_TENANT_ID, STACK_KMS_AZURE_CLIENT_ID and
# STACK_KMS_AZURE_CLIENT_SECRET.
#
# Once the variable is set, a missing or empty secret FAILS the job (the
# pre-flight in _test-kms-live.yml): a credentialed job that skips for want
# of a secret reads exactly like one that passes.
#
# The job itself is _test-kms-live.yml, shared with integration-gcp-kms.yml.
# This file keeps the triggers, the opt-in, the fork-PR condition and the
# names of the variables and the secrets.
#
# Fork PRs have no secrets, so the job skips them; every other event runs.
# Enforced by scripts/__tests__/workflow-dispatch-job-conditions.test.mjs.

on:
push:
branches: [main]
paths:
- packages/stack-kms-azure/**
- packages/stack-kms-vendor/**
- packages/stack-kms/**
- Cargo.lock
- .github/workflows/integration-azure-key-vault.yml
- .github/workflows/_test-kms-live.yml
pull_request:
# Repeated verbatim: GitHub Actions does not support YAML anchors/aliases.
paths:
- packages/stack-kms-azure/**
- packages/stack-kms-vendor/**
- packages/stack-kms/**
- Cargo.lock
- .github/workflows/integration-azure-key-vault.yml
- .github/workflows/_test-kms-live.yml
workflow_dispatch: {}

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
live:
name: stack-kms-azure against Azure Key Vault
if: >-
vars.STACK_KMS_AZURE_LIVE_KEY != ''
&& (github.event_name != 'pull_request'
|| github.event.pull_request.head.repo.full_name == github.repository)
uses: ./.github/workflows/_test-kms-live.yml
with:
crate: stack-kms-azure
name: stack-kms-azure against Azure Key Vault
live-key-variable: STACK_KMS_AZURE_LIVE_KEY
required-secrets: |
azure-tenant-id STACK_KMS_AZURE_TENANT_ID
azure-client-id STACK_KMS_AZURE_CLIENT_ID
azure-client-secret STACK_KMS_AZURE_CLIENT_SECRET
live-env: |
STACK_KMS_AZURE_LIVE_KEY=${{ vars.STACK_KMS_AZURE_LIVE_KEY }}
STACK_KMS_AZURE_LIVE_HSM_KEY=${{ vars.STACK_KMS_AZURE_LIVE_HSM_KEY }}
secrets:
azure-tenant-id: ${{ secrets.STACK_KMS_AZURE_TENANT_ID }}
azure-client-id: ${{ secrets.STACK_KMS_AZURE_CLIENT_ID }}
azure-client-secret: ${{ secrets.STACK_KMS_AZURE_CLIENT_SECRET }}
8 changes: 5 additions & 3 deletions .github/workflows/tests-crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ on:
- packages/stack-kms-aws/**
- packages/stack-kms-vault/**
- packages/stack-kms-gcp/**
- packages/stack-kms-azure/**
- packages/stack-encrypt/**
- conformance/stack-encrypt/**
- packages/stack-encrypt-derive/**
Expand Down Expand Up @@ -52,6 +53,7 @@ on:
- packages/stack-kms-aws/**
- packages/stack-kms-vault/**
- packages/stack-kms-gcp/**
- packages/stack-kms-azure/**
- packages/stack-encrypt/**
- conformance/stack-encrypt/**
- packages/stack-encrypt-derive/**
Expand Down Expand Up @@ -159,15 +161,15 @@ jobs:
# with no `version`, or a crate that uses API its dependency's packaged
# source does not have yet. stack-profile and stack-auth are in the list
# because stack-kms and stack-encrypt depend on them: without them, cargo
# resolves the published versions, which lag the tree. stack-kms-vendor, stack-kms-aws, stack-kms-vault and stack-kms-gcp
# are publishable but staged in release-plz.toml (their
# resolves the published versions, which lag the tree. stack-kms-vendor,
# stack-kms-aws, stack-kms-vault, stack-kms-gcp and stack-kms-azure are publishable but staged in release-plz.toml (their
# first version is published by hand); packaging them here keeps them
# publishable meanwhile. No token.
# `--allow-dirty` tolerates files earlier steps leave in the tree. Once a
# version is on crates.io, cargo warns rather than fails on a dry run of
# it.
- name: Verify the stack-* crates package cleanly for crates.io
run: cargo publish --locked --dry-run --allow-dirty -p stack-profile -p stack-auth -p stack-kms -p stack-encrypt-derive -p stack-encrypt -p stack-kms-vendor -p stack-kms-aws -p stack-kms-vault -p stack-kms-gcp
run: cargo publish --locked --dry-run --allow-dirty -p stack-profile -p stack-auth -p stack-kms -p stack-encrypt-derive -p stack-encrypt -p stack-kms-vendor -p stack-kms-aws -p stack-kms-vault -p stack-kms-gcp -p stack-kms-azure

# stack-kms-aws against a real AWS KMS API: LocalStack, as a service
# (ADR-0014). The `rust` job runs the same test binary, where it skips
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/udeps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
- packages/stack-kms-aws/**
- packages/stack-kms-vault/**
- packages/stack-kms-gcp/**
- packages/stack-kms-azure/**
- packages/stack-encrypt/**
- packages/stack-encrypt-derive/**
- packages/stack-guest-abi/**
Expand All @@ -41,6 +42,7 @@ on:
- packages/stack-kms-aws/**
- packages/stack-kms-vault/**
- packages/stack-kms-gcp/**
- packages/stack-kms-azure/**
- packages/stack-encrypt/**
- packages/stack-encrypt-derive/**
- packages/stack-guest-abi/**
Expand Down
6 changes: 3 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Every npm package except EQL lives under `languages/typescript/`: packages in `l
`cipherstash/encrypt-query-language` repository. Old upstream issue and PR
links are provenance only.
- `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".
- `packages/stack-kms-vendor`, `packages/stack-kms-aws`, `packages/stack-kms-vault`, `packages/stack-kms-gcp`: The key vendor backends (ADR-0013 and ADR-0014 in `packages/stack-encrypt/docs/adr/`). `stack-kms-vendor` is the vendor seam (`KeyVendorBackend`), keyset records, the derived data key mode, the static key backend and the `VendorTransport` HTTP seam (feature `http`: the native reqwest transport). Its `test-support` feature holds the test code every vendor crate shares: the contract suite (`contract`), `FakeVendor`, and the recorded-fixture harness (`replay`: fixture types, `Replay`, `Recording`); a vendor crate's `tests/common/mod.rs` holds only its own emulator, keys and constants. `stack-kms-aws` is the AWS KMS backend: a hand-written JSON client with SigV4 signing in-crate and the AWS credential providers; its LocalStack test runs in `tests-crates.yml`'s `localstack` job. `stack-kms-vault` is the HashiCorp Vault Transit backend: a hand-written Transit client with token, AppRole and Kubernetes auth; its `vault server -dev` test runs in `tests-crates.yml`'s `vault` job. `stack-kms-gcp` is the Google Cloud KMS backend: a hand-written Cloud KMS REST client with CRC32C checks, service account (RS256 JWT, the pure-Rust `rsa` crate, which has the open advisory RUSTSEC-2023-0071) and metadata server credentials; the service account login is the default feature `service-account`, and a build without it holds no RSA code; Google has no Cloud KMS emulator, so its live test runs only in the opt-in, credentialed `integration-gcp-kms.yml`, which is inert until the `STACK_KMS_GCP_LIVE_KEY` repository variable is set. All four are root workspace members, publishable in the `stack-kms-vendor` version group, and staged in `release-plz.toml` (`release = false`) until their first version is published by hand. The `stack-kms-vendor` crate docs hold the capability matrix of every key backend (key lifetime, vendor calls, what the vendor sees and can refuse, credentials, rotation, known limits); change it with the code it describes. TypeScript (`@cipherstash/stack`) cannot use a key vendor backend yet.
- `packages/stack-kms-vendor`, `packages/stack-kms-aws`, `packages/stack-kms-vault`, `packages/stack-kms-gcp`, `packages/stack-kms-azure`: The key vendor backends (ADR-0013 and ADR-0014 in `packages/stack-encrypt/docs/adr/`). `stack-kms-vendor` is the vendor seam (`KeyVendorBackend`), keyset records, the derived data key mode, the static key backend and the `VendorTransport` HTTP seam (feature `http`: the native reqwest transport). Its `test-support` feature holds the test code every vendor crate shares: the contract suite (`contract`), `FakeVendor`, and the recorded-fixture harness (`replay`: fixture types, `Replay`, `Recording`); a vendor crate's `tests/common/mod.rs` holds only its own emulator, keys and constants. `stack-kms-aws` is the AWS KMS backend: a hand-written JSON client with SigV4 signing in-crate and the AWS credential providers; its LocalStack test runs in `tests-crates.yml`'s `localstack` job. `stack-kms-vault` is the HashiCorp Vault Transit backend: a hand-written Transit client with token, AppRole and Kubernetes auth; its `vault server -dev` test runs in `tests-crates.yml`'s `vault` job. `stack-kms-gcp` is the Google Cloud KMS backend: a hand-written Cloud KMS REST client with CRC32C checks, service account (RS256 JWT, the pure-Rust `rsa` crate, which has the open advisory RUSTSEC-2023-0071) and metadata server credentials; the service account login is the default feature `service-account`, and a build without it holds no RSA code; Google has no Cloud KMS emulator, so its live test runs only in the opt-in, credentialed `integration-gcp-kms.yml`, which is inert until the `STACK_KMS_GCP_LIVE_KEY` repository variable is set. `stack-kms-azure` is the Azure Key Vault and Managed HSM backend: a hand-written Key Vault REST client (`wrapkey`/`unwrapkey`, RSA-OAEP-256 or A256KW, the associated data bound by `stack_kms_vendor::bound` because Key Vault has none) with Entra ID client secret, workload identity and managed identity credentials, and no RSA code of its own; Microsoft has no Key Vault emulator, so its live test runs only in the opt-in, credentialed `integration-azure-key-vault.yml`, which is inert until the `STACK_KMS_AZURE_LIVE_KEY` repository variable is set. Both live workflows call one job, `_test-kms-live.yml`; each keeps its triggers, opt-in and fork-PR condition, and its variable and secret names. All five are root workspace members, publishable in the `stack-kms-vendor` version group, and staged in `release-plz.toml` (`release = false`) until their first version is published by hand. The `stack-kms-vendor` crate docs hold the capability matrix of every key backend (key lifetime, vendor calls, what the vendor sees and can refuse, credentials, rotation, known limits); change it with the code it describes. TypeScript (`@cipherstash/stack`) cannot use a key vendor backend yet.
- `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.
- `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.
- `e2e/*`: Cross-package end-to-end tests (package managers, supply chain, Prisma example README)
Expand Down Expand Up @@ -716,7 +716,7 @@ term. `cts-common` and `zerokms-protocol` take caret
requirements, because the published `stack-auth` inherits them, and an
exact pin would stop the suite sharing one `cts-common` with it.

- **Three Cargo workspaces, not one.** The root workspace (the ten stack-*
- **Three Cargo workspaces, not one.** The root workspace (the eleven stack-*
crates and the three node binding crates), protect-ffi's and EQL's. The root
`Cargo.toml` excludes the other two, and they pin their own vitaminc. The
three fuzz crates, the two Go guests and the EQL v4 block ORE timing
Expand Down Expand Up @@ -758,7 +758,7 @@ exact pin would stop the suite sharing one `cts-common` with it.
`MISE_ENV=test` cargo tools — and the live tests), `crap-crates.yml`,
`mutants.yml`, `fuzz.yml`, `miri.yml` and `udeps.yml`.
`scripts/__tests__/crates-ci.test.mjs` fails when a mise task in the root
`mise.toml` or the nine crate `tasks.toml` files loses its last CI caller.
`mise.toml` or the ten crate `tasks.toml` files loses its last CI caller.
- **Auth refresh cancellation soak:** `tests-auth-refresh.yml` runs a short,
seeded, virtual-time soak on every PR and the long run on auth changes and
Version Packages PRs. `release-plz.yml` also requires the long run before
Expand Down
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"packages/stack-kms-aws",
"packages/stack-kms-vault",
"packages/stack-kms-gcp",
"packages/stack-kms-azure",
"packages/stack-encrypt",
"packages/stack-encrypt-derive",
"packages/stack-guest-abi",
Expand Down
6 changes: 4 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ from the stack-* crates), released by `.github/workflows/release-golang.yml`
as `languages/golang/vX.Y.Z` tags. All of these are in scope
for security reports on the same terms as the npm packages above.

Four more Rust crates, **`stack-kms-vendor`**, **`stack-kms-aws`**, **`stack-kms-vault`** and **`stack-kms-gcp`**
(`packages/stack-kms-vendor`, `packages/stack-kms-aws`, `packages/stack-kms-vault`, `packages/stack-kms-gcp`), are prepared for
Five more Rust crates, **`stack-kms-vendor`**, **`stack-kms-aws`**,
**`stack-kms-vault`**, **`stack-kms-gcp`** and **`stack-kms-azure`**
(`packages/stack-kms-vendor`, `packages/stack-kms-aws`, `packages/stack-kms-vault`,
`packages/stack-kms-gcp`, `packages/stack-kms-azure`), are prepared for
crates.io but not yet published. They are in scope on the same terms, and
under the same licence as the stack-* crates below.

Expand Down
Loading
Loading