Repository navigation
Backlog
Backlog
Copy link
Milestone
Description
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:
- OIDC federation fails in production by default.
OIDCFederation(crn, provider)reads its client key only from the profile. A production server has no profile, soNewClientreturnsErrNoCredentialsand says to runstash auth login. The developer must addWithClientKey(ClientKeyFromEnv()). OIDC federation is mostly used in production. - There is no environment-only key for an access-key client.
AutoCredentialsfalls 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. OnlyAccessKeyCredentials, filled by the program's own config loader, rules the profile out. - Go and Rust pick different workspaces. With
CS_WORKSPACE_CRNset and no access key, Rust'sAutoStrategyuses that workspace's device session and key. Go'sProfileStore.Autouses the CLI's current workspace for both (languages/golang/auth/strategy.go,Auto). TheAutoCredentialsdoc says it resolves "in the order the Rust client resolves them in". - A caller's own strategy brings two more lifetimes.
NewCredentialstakes a strategy the caller made from aProfileStorethey 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. - 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.
- 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.NewClientstarts the credential guest, creates the strategy in it, and closes it inClient.Close. The guest mounts the profile only when the strategy or the key provider reads it, as it does now (usesProfile). - Key providers.
encrypt.EnvKeyProvider(),encrypt.ProfileKeyProvider(crn),encrypt.ProfileKeyProviderForDetectedWorkspace(),encrypt.StaticKeyProvider(clientID, key), andencrypt.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. - Two options.
encrypt.WithAuthStrategy(s)andencrypt.WithKeyProvider(k). - The default is Rust's. With neither option,
NewClient(ctx)usesAutoStrategy()andFallbackKeyProvider(EnvKeyProvider(), ProfileKeyProviderForDetectedWorkspace()). That is whatwith_detected_credentials()builds. - Detection matches Rust's. With
CS_WORKSPACE_CRNset, the auto strategy and the detected key provider use that workspace, not the CLI's current one. The token is checked against it. - 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, andWithClientKey: removed, or kept as shortcuts for a strategy and a provider. The module is atv0.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
NewClientand wiped. Rust'sStaticKeyProviderkeeps 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
authpackage keeps strategies made from an openProfileStorefor programs that need them, outsideencrypt.
Relationship to other work
- feat(golang): let OIDCFederation take its client key from a source the caller chooses #1727: adds the OIDC client key sources this replaces. It is reworked onto this design, or closed in favour of it.
- Go SDK: encrypt one value into one ciphertext, as Rust and TypeScript do #2010: the Go SDK's whole-value encrypt and decrypt use the same client.
Activity