Repository navigation
Description
Background
Stack Encrypt (packages/stack-encrypt) is the Rust crate that encrypts and decrypts values. It asks ZeroKMS, the CipherStash key service, for data keys. Every request to ZeroKMS needs two credentials, and they are independent of each other:
- a service token, which an auth strategy from Stack Auth (
packages/stack-auth) gets; - a client key, which a key provider from Stack KMS (
packages/stack-kms) loads.
#1701 lets a caller name both: StackCipher::builder().auth_strategy(strategy).key_provider(provider).init(). After auth_strategy, the builder reads a client key only from the provider the caller names.
Problem
The shortest way to build a cipher still reads the environment without the caller asking.
StackCipher::builder().init() and StackCipher::new() choose both credentials themselves:
- The auth strategy is
stack_auth::AutoStrategy. It readsCS_CLIENT_ACCESS_KEYandCS_WORKSPACE_CRN. If they are not set, it reads the login thatstash auth loginsaved in the profile directory (~/.cipherstash, orCS_CONFIG_PATH). - The key provider reads
CS_CLIENT_IDandCS_CLIENT_KEY. If they are not set, it readssecretkey.jsonfrom the profile directory (client_key_providerinpackages/stack-encrypt/src/cipher.rs, on the feat(stack-encrypt): name the auth strategy and the key provider on StackCipherBuilder #1701 branch).
Nothing in StackCipher::builder().init() says that it reads six environment variables and a directory. A reader of the code cannot tell where the credentials come from.
This matters because the environment is not always the program's to choose:
- A developer who has these variables exported for another project gets that project's credentials.
- A test that inherits them from CI talks to a real workspace.
- A server whose deployment sets the variables for another component uses them too.
In each case the cipher works, with credentials nobody chose for it. Nothing reports it.
Proposal
The design is left to the implementer. Whatever the shape, it should do the following:
- No way of building a
StackCipherreads environment variables or the profile directory unless the caller's code names that choice. - A short way to get today's behaviour stays: the environment, then the CLI's profile. Developer machines and CI need it. Its name must say what it reads.
- This is a breaking change to a published crate, made before the stable release. Mark the commit with
!and add an entry under[Unreleased]inpackages/stack-encrypt/CHANGELOG.md. Update the crate docs, the README, the examples, and the doc tests that callinit()on the bare builder.
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: addedauth_strategyandkey_provider. This issue builds on feat(stack-encrypt): name the auth strategy and the key provider on StackCipherBuilder #1701 and should branch from it until it merges.stack-encryptcannot run as end users without a lazily built cipher and a task-local — defer the default keyset load and take the JWT per operation #1708: wheninitloads the default keyset. A change toinithere should not makestack-encryptcannot run as end users without a lazily built cipher and a task-local — defer the default keyset load and take the JWT per operation #1708 harder.
Activity