Skip to content

StackCipher::builder().init() reads CS_CLIENT_ID and CS_CLIENT_KEY without being asked — make reading the environment an explicit choice #1722

Closed

Description

@coderdan

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:

  1. The auth strategy is stack_auth::AutoStrategy. It reads CS_CLIENT_ACCESS_KEY and CS_WORKSPACE_CRN. If they are not set, it reads the login that stash auth login saved in the profile directory (~/.cipherstash, or CS_CONFIG_PATH).
  2. The key provider reads CS_CLIENT_ID and CS_CLIENT_KEY. If they are not set, it reads secretkey.json from the profile directory (client_key_provider in packages/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:

  1. No way of building a StackCipher reads environment variables or the profile directory unless the caller's code names that choice.
  2. 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.
  3. This is a breaking change to a published crate, made before the stable release. Mark the commit with ! and add an entry under [Unreleased] in packages/stack-encrypt/CHANGELOG.md. Update the crate docs, the README, the examples, and the doc tests that call init() on the bare builder.

Relationship to other work

Activity

  1. self-assigned this
    on Nov 19, 2026
  2. added
    enhancement
    rust
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

SDKenhancementrust

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions