Skip to content

Go SDK: encrypt.OIDCFederation always takes the client key from the environment or the CLI's current workspace — let the caller choose where it comes from #1723

Open

Description

@coderdan

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):

  1. CS_CLIENT_ID and CS_CLIENT_KEY, if both are set (clientKeyFromEnv, credentials.go:529);
  2. otherwise secretkey.json in 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:

  1. A caller can pair any token source, OIDCFederation included, with a client key from a source they choose: the environment, the CLI profile for a named workspace, or values their program loaded.
  2. 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.
  3. The caller does not have to manage the lifetime of a ProfileStore or a strategy to do this.
  4. AutoCredentials keeps its behaviour. It is named for reading the environment and the profile.

Relationship to other work

Activity

  1. added
    enhancement
    on Nov 19, 2026
  2. self-assigned this
    on Nov 19, 2026
  3. coderdan commented on Nov 19, 2026

    @coderdan
    ContributorAuthor

    #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.

  4. coderdan commented on Nov 21, 2026

    @coderdan
    ContributorAuthor

    Related: #1741 proposes a parsed auth.CRN type in the Go SDK, backed by the guest's sa_auth_validate_crn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

SDKenhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions