Repository navigation
Backlog
Labels
Milestone
Description
Background
A Stack Encrypt cipher in Rust needs two things, named by two traits:
AuthStrategy(instack-auth) produces the bearer token for each ZeroKMS request.KeyProvider(instack-kms) produces the client key.
The token and the key must be for the same workspace, or ZeroKMS refuses the request.
stash auth login saves a profile: the ~/.cipherstash directory, or CS_CONFIG_PATH. There are two files in it for each workspace the developer logged in to. auth.json is the login's access token and refresh token. secretkey.json is the client key. A marker records which workspace the CLI is on.
Problem
A developer who wants to "use my profile" for both halves has to build two unrelated objects, and nothing makes them read the same workspace:
StackCipher::builder()
.auth_strategy(DeviceSessionStrategy::with_profile(store).build()?) // or AutoStrategy::detect()?
.key_provider(ProfileKeyProvider::for_detected_workspace())- Two names for one source. The token side is
DeviceSessionStrategy, inpackages/stack-auth/src/device_session_strategy.rs. The key side isProfileKeyProvider, inpackages/stack-kms/src/key_provider.rs. A developer has to learn that a "device session" is the profile's token. - The workspace is chosen twice, in different ways.
ProfileKeyProvidernames a workspace withfor_workspace(&crn)orfor_detected_workspace().DeviceSessionStrategytakes no CRN; it takes aProfileStorethe caller opened, for the profile root (with_profile) or for one workspace (with_workspace_store). - Nothing checks that the two halves agree. A strategy for one workspace and a key for another compile, and fail only when ZeroKMS refuses the request.
Proposal
The profile itself is the credential source. One handle, scoped to one workspace, implements both traits.
- A
Profilehandle with two constructors:Profile::detected()uses the workspaceCS_WORKSPACE_CRNnames, else the CLI's current workspace. This is howAutoStrategyandProfileKeyProvider::for_detected_workspace()choose it now.Profile::for_workspace(&crn)uses the workspace you name.
- It is the profile's
AuthStrategy, with the profile'sauth.jsontoken, refreshed under the cross-process lock the CLI uses, with the background refresh of feat: refresh tokens in the background before they expire, with backoff after a failure #1989. It also implementsKeyProvider, with the profile'ssecretkey.json. The handle carries the token cache and the refresh schedule. So it is a workspace handle, not the plainstack_profile::ProfileStorefile store. That store has other uses. - One builder call for both halves.
.profile(&profile)sets the auth strategy and the key provider from the same handle, so the two are for one workspace by construction..auth_strategyand.key_providerstay for mixed setups, such as OIDC federation with a key from the environment. - Type state for the separate calls.
Profile::detected()andProfile::for_workspace(&crn)return different types. The builder records where the strategy's workspace comes from: detected, named, or not a profile workspace (an access key or OIDC federation).key_provideraccepts only a provider whose workspace source can match. A detected strategy with a named-workspace key does not compile. What the types cannot prove is that two CRN values are equal. Two separately named workspaces are still checked when the cipher is built, with an error that names both. AutoStrategybecomes the access key fromCS_CLIENT_ACCESS_KEY, else the detected profile.StackCipher::with_detected_credentials()builds the same thing.DeviceSessionStrategyand its builder leave the public API. Two of its forms stay internal:with_token, the in-memory form. The device-code login flow and tests use it.with_workspace_store, the WASI guests' path. A guest uses it after it takes theauth.jsonlock.
- Docs and examples:
stack-auth's andstack-encrypt's rustdoc,packages/stack-auth/examples/auto_strategy.rs, andpackages/stack-encrypt/examples/zerokms_auth.rs. CHANGELOG entries under Breaking forstack-authandstack-kms.stack-auth0.43.0 on crates.io hasDeviceSessionStrategy.
Open decisions:
- Where the type lives:
stack-profile, where the profile's files are read and written.stack-profiledepends on no other stack crate.stack-authdepends on it,stack-kmsdepends onstack-auth, andstack-encryptdepends on both. Sostack-profilecannot implement the traits itself without a dependency cycle. Each trait's own crate implements it forProfileinstead. The orphan rule allows that:stack-authimplementsAuthStrategy, andstack-kmsimplementsKeyProvider. - Where the refresh state lives. The auth strategy needs a token cache and a refresh schedule (feat: refresh tokens in the background before they expire, with backoff after a failure #1989), and those types are defined in
stack-auth. So aProfiledefined instack-profilecannot contain them. There are two ways to keep the state:- the builder wraps the profile in a
stack-authrefresh engine, and the cipher owns that engine.Profilestays plain data, and the crates stay apart. stack-authkeeps the state in an opaque field ofProfile.
- the builder wraps the profile in a
- What
ProfileKeyProviderbecomes. Either it is removed, sinceProfileis the key provider, or it stays as a key-only provider. The second suits a developer who wants the profile's key with another strategy. - The names, including
.profile(&profile)on the builder.
Relationship to other work
- Go SDK: choose the auth strategy and the client key provider separately, as in Rust #2024: the Go SDK mirrors the Rust credential API. It follows this design for its profile source.
- The TypeScript packages follow this design too; see the comment on this issue.
- feat: refresh tokens in the background before they expire, with backoff after a failure #1989: the background refresh the profile's strategy runs.
Activity
coderdan commentedon Nov 29, 2026
Decided: the TypeScript interface changes to match.
These places expose the device session today:
@cipherstash/authpublishesDeviceSessionStrategy.fromProfile()(languages/typescript/packages/auth/index.d.ts, line 103), and its deprecated aliasOAuthStrategy.@cipherstash/stackre-exportsDeviceSessionStrategy(languages/typescript/packages/stack/src/index.ts, lines 30 to 32).envcommand usesDeviceSessionStrategy.fromProfile()(languages/typescript/packages/cli/src/commands/env/index.ts, line 343).skills/stash-auth/SKILL.md(line 165) listsDeviceSessionStrategyamong the auth strategies. That skill ships to customers.What changes:
Profilein@cipherstash/auth, withProfile.detected()andProfile.forWorkspace(crn). It is accepted where an auth strategy is (config.authStrategy), and it supplies the client key from the same workspace.DeviceSessionStrategyandOAuthStrategyare deprecated first, then removed. Both packages are published, so a release has to pass between the two steps, with changesets for@cipherstash/authand@cipherstash/stack.envcommand moves toProfile.skills/stash-authdescribesProfilein place ofDeviceSessionStrategy, with astashpatch changeset, as AGENTS.md requires for a change toskills/.