Skip to content

Go SDK: choose the auth strategy and the client key provider separately, as in Rust #2024

Backlog

Description

@coderdan

Background

A Client in the Go SDK (languages/golang/encrypt) needs two things from its credentials:

  • A token, from an auth strategy. The strategy is an access key, a device session saved by stash auth login, or OIDC federation. OIDC federation exchanges a token from the application's identity provider (Clerk, Auth0, Okta) with CTS.
  • A client key: the ZeroKMS client id and key. It must be for the same workspace as the token, or ZeroKMS refuses the request.

The Rust engine treats these as two independent choices. A caller picks an auth strategy and a key provider, and with_detected_credentials() is a shortcut for the usual pair:

StackCipher::builder()
    .auth_strategy(AutoStrategy::detect()?) // AccessKeyStrategy, DeviceSessionStrategy, OidcFederationStrategy
    .key_provider(FallbackKeyProvider::new( // EnvKeyProvider, ProfileKeyProvider, StaticKeyProvider
        EnvKeyProvider,
        ProfileKeyProvider::for_detected_workspace(),
    ))

Problem

The Go SDK bundles a strategy and a key rule together, and each bundle has its own key rule. So a developer cannot choose the two separately, and the rules differ from Rust's.

Rust Go now
AutoStrategy, AccessKeyStrategy, DeviceSessionStrategy, OidcFederationStrategy methods on an open auth.ProfileStore: Auto, AccessKey, DeviceSession, OIDC
EnvKeyProvider, ProfileKeyProvider, StaticKeyProvider ClientKeyFromEnv, ClientKeyFromProfile(crn), ClientKeyFromValues (#1727), accepted only by OIDC's WithClientKey
FallbackKeyProvider none; the fallback is built into AutoCredentials
ProfileKeyProvider::for_detected_workspace() none as a source; built into AutoCredentials
.auth_strategy(s).key_provider(k) NewCredentials(clientID, key, strategy), which takes a key value, not a provider
with_detected_credentials() AutoCredentials(), the default

What a developer meets as a result, on #1727's branch:

  1. OIDC federation fails in production by default. OIDCFederation(crn, provider) reads its client key only from the profile. A production server has no profile, so NewClient returns ErrNoCredentials and says to run stash auth login. The developer must add WithClientKey(ClientKeyFromEnv()). OIDC federation is mostly used in production.
  2. There is no environment-only key for an access-key client. AutoCredentials falls back to the profile for the token and for the key separately. One missing or misspelt variable quietly uses the developer's login. That login may be for another workspace. Only AccessKeyCredentials, filled by the program's own config loader, rules the profile out.
  3. Go and Rust pick different workspaces. With CS_WORKSPACE_CRN set and no access key, Rust's AutoStrategy uses that workspace's device session and key. Go's ProfileStore.Auto uses the CLI's current workspace for both (languages/golang/auth/strategy.go, Auto). The AutoCredentials doc says it resolves "in the order the Rust client resolves them in".
  4. A caller's own strategy brings two more lifetimes. NewCredentials takes a strategy the caller made from a ProfileStore they opened. The client never closes either, so the caller closes the client, then the strategy, then the store. In Rust the cipher owns its strategy.
  5. The README is hard to follow. "Credentials" lists AutoCredentials, AccessKeyCredentials, NewCredentials, and the OIDC forms in a row, with different key rules, and does not say which to use when.

Proposal

Make the Go credential API mirror Rust's. A developer chooses an auth strategy and a key provider separately. The names, the rules, and the default are Rust's.

  1. Strategies, as values the client owns. encrypt.AutoStrategy(), encrypt.AccessKeyStrategy(crn, key), encrypt.DeviceSessionStrategy(), encrypt.OIDCFederationStrategy(crn, provider), and the detected-workspace forms. Each constructor only records the choice. NewClient starts the credential guest, creates the strategy in it, and closes it in Client.Close. The guest mounts the profile only when the strategy or the key provider reads it, as it does now (usesProfile).
  2. Key providers. encrypt.EnvKeyProvider(), encrypt.ProfileKeyProvider(crn), encrypt.ProfileKeyProviderForDetectedWorkspace(), encrypt.StaticKeyProvider(clientID, key), and encrypt.FallbackKeyProvider(a, b), usable with every strategy. They are the feat(golang): let OIDCFederation take its client key from a source the caller chooses #1727 sources, renamed and opened to every strategy.
  3. Two options. encrypt.WithAuthStrategy(s) and encrypt.WithKeyProvider(k).
  4. The default is Rust's. With neither option, NewClient(ctx) uses AutoStrategy() and FallbackKeyProvider(EnvKeyProvider(), ProfileKeyProviderForDetectedWorkspace()). That is what with_detected_credentials() builds.
  5. Detection matches Rust's. With CS_WORKSPACE_CRN set, the auto strategy and the detected key provider use that workspace, not the CLI's current one. The token is checked against it.
  6. The README is rewritten by scenario: local development after stash auth login; environment only; an access key in production; OIDC federation in production. Each scenario gives the code and says what is read.

Open decisions:

  • The bundles. What happens to AutoCredentials, AccessKeyCredentials, NewCredentials, OIDCFederation, and WithClientKey: removed, or kept as shortcuts for a strategy and a provider. The module is at v0.1.0-rc.7, so removing them before 0.1.0 is possible.
  • A key value is wiped once used. Today a key given as a value is consumed by the first NewClient and wiped. Rust's StaticKeyProvider keeps its key. Keep Go's rule, and say so in the docs, or match Rust.
  • The OIDC default. Whether OIDC federation with no key provider uses the same default as every strategy (environment, then the detected workspace's profile), or the environment alone.
  • Callers who manage the guest themselves. Whether the auth package keeps strategies made from an open ProfileStore for programs that need them, outside encrypt.

Relationship to other work

Activity

  1. added
    Golang
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GolangSDK

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions