Skip to content

refactor(stack-kms-vendor): share one credential cache across vendors - #1557

Draft
freshtonic wants to merge 1 commit into
james/kms-vendor-test-harnessfrom
james/kms-vendor-cached-token
Draft

freshtonic wants to merge 1 commit into
james/kms-vendor-test-harnessfrom
james/kms-vendor-cached-token

Conversation

@freshtonic

Copy link
Copy Markdown
Contributor

Summary

The AWS, Google Cloud, Azure and Vault crates each had a copy of the same credential cache. This cache keeps a short-lived credential (an access token, a Vault token or temporary AWS keys) and gets a new one before the old one expires. Google Cloud and Azure also had the same access-token and error types. A fix to one copy did not reach the others. This PR puts one generic cache in stack-kms-vendor and moves all four crates onto it.

Changes

  • stack-kms-vendor: new credential module with CachedToken<P, K>, the CredentialKind / FetchCredential traits, Expiring / Expiry, the shared AccessToken, and CredentialError<K>. The generic cache tests are here, once (15 tests).
  • Each vendor crate declares a marker type and keeps its public names as type aliases or re-exports (CachedToken, CachedCredentials, AuthError, CredentialsError, AccessToken).
  • Unused futures (all four) and web-time (Vault) dependencies removed. Both lockfiles updated.
  • Changeset: @cipherstash/auth patch (the binding compiles the vendor crates in).

Behaviour changes (small)

  • AWS credentials that live less than 15 minutes now refresh a third of their life before expiry, the same rule the others used.
  • GCP: AccessToken::from_env_lookup is gone. Use the new ACCESS_TOKEN_VARIABLE (Azure already had one). The one caller, in @cipherstash/auth, is updated. These crates are not yet published.

Verification

Run on the top branch of this stack (james/kms-vendor-dispatch), on macOS:

  • cargo fmt --all --check and cargo clippy --workspace --all-features --all-targets -- -D warnings: 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). It fails on every snapshot because of a local rustc wrapper that changes the paths in the compiler output. This stack does not touch stack-encrypt. CI is the check for it.
  • mise run wasm:guest:test: 80 of 80 pass.
  • All four Go guests rebuilt, then go vet ./... and go test -count=1 ./... in languages/golang: pass.
  • pnpm --filter @cipherstash/auth test: 92 pass. pnpm --filter stash test: 1667 pass.
  • Biome on the changed TypeScript and script files: no errors.
  • cargo check of the workspace and the guest (native and wasm32-wasip1) on each branch of the stack: pass.
  • mise run wasm:wasi-check and mise run test:doc: pass (run by the agent that wrote the change).

Related

Refs #1541. Code-smell follow-up to the key vendor backend stack.

The AWS, Google Cloud, Azure and Vault crates each had a copy of the same
credential cache. Google Cloud and Azure also had the same access token
and error types. A fix to one copy did not go to the others.

stack-kms-vendor now has one generic CachedToken<P, K>. Each vendor crate
declares a marker type that names its credential, its cache key and its
error label. The crates keep their public names as type aliases
(CachedToken, CachedCredentials, AuthError, CredentialsError) and
re-export the shared AccessToken.

The cache rules do not change: refresh at min(5 minutes, life / 3) before
expiry, one fetch at a time, and a credential that has not expired is
kept when a fetch fails. AWS credentials now also use the life / 3 rule.
The cache tests are now in stack-kms-vendor, once.
@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

@changeset-bot

changeset-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8f8929d

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:25
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Mutation testing (cargo-mutants, --in-diff, stack-auth + stack-encrypt)

No mutants were generated for the changed lines.

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