Skip to content

fix(stack-kms-vendor): let a key router hold at most one vendor by type - #1562

Draft
freshtonic wants to merge 1 commit into
james/kms-vendor-dispatchfrom
james/kms-router-one-vendor
Draft

freshtonic wants to merge 1 commit into
james/kms-vendor-dispatchfrom
james/kms-router-one-vendor

Conversation

@freshtonic

Copy link
Copy Markdown
Contributor

Summary

A cipher may use ZeroKMS (CipherStash's key service) plus at most one key vendor backend: a customer's own key service, such as AWS KMS. The decision log said the KeyRouter type enforced this. It did not: the ZeroKMS side of the router took any key source, and a router is one. So a router that held a second router, and a second vendor, compiled. This PR makes the type hold the rule. No runtime behaviour changes.

Changes

  • stack-kms: new marker trait ZeroKmsKeySource, implemented for StackKms (the real ZeroKMS client) and its two test sources.
  • stack-kms-vendor: KeyRouter::new and KeyRouter::zerokms_only ask for it. No router implements it. A compile_fail doc test shows a nested router does not compile.
  • Go guest: MaybeZeroKms implements it.
  • Decision log: corrects the claim, and lists it as fixed.
  • Changeset: @cipherstash/auth patch.

Verification

  • The compile_fail doc test passes with the bound. With the bound removed it fails ("Test compiled successfully, but it's marked compile_fail"), so it fails for the right reason.
  • cargo clippy --workspace --all-features --all-targets -- -D warnings, and the guest's clippy (native and wasm32-wasip1): pass.
  • mise x --env test -- cargo nextest run --workspace --all-features: 1401 of 1402 pass. The one failure is stack-encrypt::ui derive_diagnostics (trybuild), which fails on this machine for every snapshot because of the local toolchain setup. CI is the check for it.
  • mise run test:doc: pass. mise run wasm:guest:test: 80 of 80 pass. All four Go guests rebuilt, then go test -count=1 ./...: pass.

Related

Refs #1561. Review finding on the key vendor backend stack.

ADR-0009 allows ZeroKMS and at most one key vendor backend in a cipher.
The decision log said the KeyRouter type held exactly one vendor. It did
not: the ZeroKMS side took any DataKeySource, and a KeyRouter is one. So
KeyRouter<KeyRouter<ZeroKMS, Aws>, Gcp> compiled. RecordError::SecondVendor
catches two vendors only inside one VendorKeySource.

Add the marker trait stack_kms::ZeroKmsKeySource. StackKms, the two test
sources of stack-kms and the guest's MaybeZeroKms implement it. A router
does not. KeyRouter::new and KeyRouter::zerokms_only now ask for it, so a
nested router does not compile. A compile_fail doc test shows this, and it
compiles when the bound is removed.

The decision log now says what the type holds and that the first claim
was wrong.
@changeset-bot

changeset-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5f12aa4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 19 packages
Name Type
@cipherstash/auth Patch
stash Patch
@cipherstash/stack Patch
@cipherstash/wizard Patch
@cipherstash/ffi-integration-tests Patch
@cipherstash/basic-example Patch
@cipherstash/e2e Patch
@cipherstash/bench Patch
@cipherstash/stack-drizzle Patch
@cipherstash/stack-prisma Patch
@cipherstash/stack-supabase Patch
@cipherstash/test-kit Patch
@cipherstash/prisma-example Patch
@cipherstash/auth-darwin-arm64 Patch
@cipherstash/auth-darwin-x64 Patch
@cipherstash/auth-linux-arm64-gnu Patch
@cipherstash/auth-linux-x64-gnu Patch
@cipherstash/auth-linux-x64-musl Patch
@cipherstash/auth-win32-x64-msvc Patch

Not sure what this means? Click here to learn what changesets are.

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

@freshtonic
freshtonic added this pull request to stack #1523 November 6, 2026 11:33
@coderabbitai

coderabbitai Bot commented Nov 6, 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

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