Repository navigation
Description
Background
The Go SDK (languages/golang, module github.com/cipherstash/stack/languages/golang) encrypts and decrypts values through ZeroKMS, the CipherStash key service. Every request to ZeroKMS needs two credentials, and they are independent of each other:
- a service token, which an auth strategy gets (
auth.Strategy); - a client key and its client id, which identify the application to ZeroKMS.
encrypt.NewClient takes an encrypt.Credentials value that says where both come from. There are four: AutoCredentials(), AccessKeyCredentials{…}, NewCredentials(clientID, key, strategy) and OIDCFederation(crn, provider, …) (languages/golang/encrypt/credentials.go).
OIDCFederation is for a server that makes requests as its signed-in user. It exchanges the user's token from an identity provider (Clerk, Auth0, Okta) for a CipherStash token.
Problem
OIDCFederation chooses the client key itself, and the caller cannot change that.
It resolves the key as AutoCredentials does (resolveWithStrategy, credentials.go:456):
CS_CLIENT_IDandCS_CLIENT_KEY, if both are set (clientKeyFromEnv,credentials.go:529);- otherwise
secretkey.jsonin the CLI's current workspace (clientKeyFromProfile,credentials.go:552).
This causes two problems.
A server that loads its own configuration cannot pass its key. Many Go services load every setting into one struct, which is why AccessKeyCredentials exists (#1689). OIDCFederation has no field for a client key, so the key must be in the process environment or in a CLI profile.
The key can come from a different workspace than the token. OIDCFederation(crn, …) gets tokens for the workspace that crn names. If the variables are not set, the key comes from whatever workspace the CLI has selected. A developer whose CLI is on workspace B, running a server configured for workspace A, gets workspace A's tokens with workspace B's key. ZeroKMS refuses a request whose token and client key come from different workspaces. The error does not point at the key's source.
The only way around both today is NewCredentials. The caller then opens a ProfileStore with auth.Resolve, builds the strategy with ProfileStore.OIDC, and loads the key. They must also close the strategy and the store after Client.Close (credentials.go:101-124). That is the whole lifecycle, managed by hand, to change one setting.
The Rust crates already separate the two: in #1701, StackCipher::builder().auth_strategy(…).key_provider(…) takes any strategy with any key provider. A key provider can read the environment, read a named workspace's secretkey.json, or hold a fixed key.
Proposal
The design is left to the implementer. Whatever the shape, it should do the following:
- A caller can pair any token source,
OIDCFederationincluded, with a client key from a source they choose: the environment, the CLI profile for a named workspace, or values their program loaded. - When the key is read from the profile for a named workspace, it is that workspace's key. It is never the current workspace's key in its place.
- The caller does not have to manage the lifetime of a
ProfileStoreor a strategy to do this. AutoCredentialskeeps its behaviour. It is named for reading the environment and the profile.
Relationship to other work
StackCiphercannot take an auth strategy without re-implementing client key loading #1700 and feat(stack-encrypt): name the auth strategy and the key provider on StackCipherBuilder #1701: the same separation in the Rust crates.- Go SDK: no exported credentials struct with
envtags, so services using go-envconfig must write their own and build NewCredentials by hand #1689:AccessKeyCredentials, a struct a configuration loader can fill. It does not cover OIDC federation.
Activity
coderdan commentedon Nov 19, 2026
#1724 is the related issue on detecting the workspace for OIDC federation. A detected workspace should also decide which workspace's client key is read from the profile.
coderdan commentedon Nov 21, 2026
Related: #1741 proposes a parsed
auth.CRNtype in the Go SDK, backed by the guest'ssa_auth_validate_crn.