Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cargo/mutants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ exclude_re = [
'stack-encrypt/src/op(/mod)?\.rs:\d+:\d+: replace <impl Clone for Matches<C>>::clone -> Self with Default::default\(\)$',
'stack-encrypt/src/op(/mod)?\.rs:\d+:\d+: replace Matches::case_sensitive -> Matches<CaseSensitive> with Default::default\(\)$',
'stack-encrypt/src/target/index\.rs:\d+:\d+: replace <impl Clone for Match<O>>::clone -> Self with Default::default\(\)$',
'stack-encrypt/src/cipher\.rs:\d+:\d+: replace StackCipher<FromEnv>::builder -> StackCipherBuilder with Default::default\(\)$',
'stack-encrypt/src/cipher\.rs:\d+:\d+: replace StackCipher<NoKms>::builder -> StackCipherBuilder with Default::default\(\)$',
'stack-encrypt/src/sem/mod\.rs:\d+:\d+: replace <impl MatchConfig for DefaultMatch>::options -> MatchOptions with Default::default\(\)$',
# `Orderable`'s default `check_query` refuses nothing: its body is
# `Ok(())`, so the replacement is the body. Text overrides it with
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/tests-golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,9 @@ jobs:
# Round trips through real ZeroKMS. The Go live tests skip without their
# STACK_ENCRYPT_TEST_* variables, so the secrets pre-flight runs first and
# turns a missing credential into a failure rather than a silent skip. The
# stack-encrypt examples read CS_* through `StackCipher::new()`; tests-crates
# builds them, and this job runs them.
# stack-encrypt examples read CS_* through
# `StackCipher::with_detected_credentials()`; tests-crates builds them, and
# this job runs them.
live:
name: Go live tests and stack-encrypt examples
needs: wasi-check
Expand Down
4 changes: 2 additions & 2 deletions languages/golang/encrypt/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ var envZeroKMSHost = []string{"CS_ZEROKMS_HOST", "CS_VITUR_HOST"}

// AutoCredentials is [Credentials] from the environment first, then the
// developer profile `stash auth login` writes — the order the Rust client
// (stack-encrypt's StackCipher::builder().init()) resolves them in, so one
// set of variables configures a service in either language:
// (stack-encrypt's StackCipher::with_detected_credentials()) resolves them
// in, so one set of variables configures a service in either language:
//
// - The token, by stack-auth's AutoStrategy order: CS_CLIENT_ACCESS_KEY
// (with CS_WORKSPACE_CRN, which is then required) exchanged for a token;
Expand Down
25 changes: 24 additions & 1 deletion packages/stack-encrypt/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`StackCipher::builder().auth_strategy(strategy).key_provider(provider).init()`
builds the ZeroKMS client from an auth strategy and a client key provider
that you choose. Before, a caller who wanted another auth strategy had to
build the `StackKms` by hand. `init()` and `kms(..)` are unchanged.
build the `StackKms` by hand. `kms(..)` is unchanged.
- `auth_strategy` takes any strategy `StackKmsBuilder::new` takes: an
`OidcFederationStrategy`, an `AccessKeyStrategy`, or an `AuthStrategyFn`.
- `key_provider` is required after `auth_strategy`. The builder then reads
Expand Down Expand Up @@ -438,6 +438,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking

- **A cipher no longer reads credentials you did not name** (#1722).
`StackCipher::new()` and `init()` on the bare builder read
`CS_CLIENT_ID`, `CS_CLIENT_KEY`, `CS_CLIENT_ACCESS_KEY`,
`CS_WORKSPACE_CRN` and the CLI's profile directory, and nothing in the
call said so. Both are removed.
- `StackCipher::with_detected_credentials()` replaces `new()`. It reads
the same places in the same order, and its name says so. To upgrade,
rename the call.
- `StackCipher::builder()` has no `init()` until you name a data-key
source, with `kms(..)` or with `auth_strategy(..)` and then
`key_provider(..)`. For `StackCipher::builder().init()` with builder
options such as `keyset_cache_size`, write
`.auth_strategy(AutoStrategy::detect()?)` and
`.key_provider(FallbackKeyProvider::new(EnvKeyProvider, ProfileKeyProvider::for_detected_workspace()))`
Comment thread
coderdan marked this conversation as resolved.
Resolved
before `init()`. That builds the same cipher on a native target.
`ProfileKeyProvider` exists on native targets only, so on wasm32 write
`.key_provider(EnvKeyProvider)`.
- The builder state `FromEnv` is renamed `NoKms`, since the builder no
longer reads the environment in it.
- `Error::Config` reads "could not build a ZeroKMS client", without
"from the environment": a builder given an auth strategy and a key
provider reports its errors there too.

- **A key source of your own states its kind.** `kms::DataKeySource`,
`kms::IndexKeySource` and `kms::CredentialKeySource` each require
`kms::KeySourceKind`, so that a type cannot be both kinds of key source.
Expand Down
23 changes: 13 additions & 10 deletions packages/stack-encrypt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ license-file = "LICENSE"

[dependencies]
# `profile` (native only; stack-kms gates it off wasm32 itself) lets
# `StackCipher::new()` fall back to the client key `stash auth login` writes
# to the profile directory (`secretkey.json`) when CS_CLIENT_ID /
# CS_CLIENT_KEY are not set — the same place `AutoStrategy` finds the token.
# `StackCipher::with_detected_credentials()` fall back to the client key
# `stash auth login` writes to the profile directory (`secretkey.json`) when
# CS_CLIENT_ID / CS_CLIENT_KEY are not set — the same place `AutoStrategy`
# finds the token.
stack-kms = { path = "../stack-kms", version = "0.2.0", default-features = false, features = ["profile"] }
# `StackCipher::new()` builds a ZeroKMS client from the environment, so its
# return type names the auto-detected auth strategy. Only needed with `http`.
# `StackCipher::with_detected_credentials()` builds a ZeroKMS client from the
# environment, so its return type names the auto-detected auth strategy. Only
# needed with `http`.
stack-auth = { workspace = true, optional = true }
# `#[derive(EncryptTarget)]` / `#[derive(DecryptSource)]`, re-exported from `target`.
stack-encrypt-derive = { path = "../stack-encrypt-derive", version = "0.3.0" }
Expand Down Expand Up @@ -106,11 +108,12 @@ zeroize = { workspace = true }

[features]
default = ["http", "jiff", "rust_decimal"]
# `StackCipher::new()` / `StackCipher::builder().init()` from the environment:
# the default HTTP transport in stack-kms and the auto-detected auth strategy
# in stack-auth. Off, a cipher is built over an explicit `DataKeySource`
# (`StackCipher::builder().kms(..)`) and no HTTP client or TLS stack is in
# the dependency graph — the shape the WASI/wazero guest builds against.
# A cipher over ZeroKMS: `StackCipher::with_detected_credentials()`, or
# `StackCipher::builder().auth_strategy(..)`. It brings the default HTTP
# transport in stack-kms and the auth strategies in stack-auth. Off, a cipher
# is built over an explicit `DataKeySource` (`StackCipher::builder().kms(..)`)
# and no HTTP client or TLS stack is in the dependency graph — the shape the
# WASI/wazero guest builds against.
http = ["dep:stack-auth", "stack-auth/http", "stack-kms/http"]
# `stack_encrypt::dynamic`: encrypt and decrypt values whose types are known
# only at runtime, as an FFI binding's are. Off by default — it is only of
Expand Down
4 changes: 2 additions & 2 deletions packages/stack-encrypt/examples/encrypted_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// The cipher seals each value under its own ZeroKMS data key. `new` also
// loads the keyset's index key. The index key derives the terms. Data keys
// and terms always come from the same keyset.
let cipher = StackCipher::new().await?;
let cipher = StackCipher::with_detected_credentials().await?;
// The client's default keyset.
let keyset = cipher.default_keyset();

Expand Down Expand Up @@ -158,7 +158,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// A second client. Any process with the same ZeroKMS credentials and
// keyset can decrypt what this one wrote.
let decryptor = StackCipher::new().await?;
let decryptor = StackCipher::with_detected_credentials().await?;

// Decrypting the matching rows together makes one batched
// `retrieve_keys` call, however many rows match. Each field opens under
Expand Down
2 changes: 1 addition & 1 deletion packages/stack-encrypt/examples/mixed_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn describe(ciphertext: &StackCipherText, indent: usize) {

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cipher = StackCipher::new().await?;
let cipher = StackCipher::with_detected_credentials().await?;

let users = vec![
User {
Expand Down
2 changes: 1 addition & 1 deletion packages/stack-encrypt/examples/opaque_blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct ProfileV2 {

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cipher = StackCipher::new().await?;
let cipher = StackCipher::with_detected_credentials().await?;
let keyset = cipher.default_keyset();

let profile = Profile {
Expand Down
2 changes: 1 addition & 1 deletion packages/stack-encrypt/examples/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use stack_encrypt::{Ciphertext, DecryptFrom, EncryptInto, StackCipher};

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cipher = StackCipher::new().await?;
let cipher = StackCipher::with_detected_credentials().await?;
let keyset = cipher.default_keyset();

let encrypted = keyset.encrypt(42i32).await?;
Expand Down
7 changes: 4 additions & 3 deletions packages/stack-encrypt/examples/search_terms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ use stack_encrypt::{nonempty, EncryptInto, StackCipher, StackCipherText};

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// `StackCipher::new()` builds a ZeroKMS client from the environment and
// loads the keyset's index key once, during construction.
let cipher = StackCipher::new().await?;
// `StackCipher::with_detected_credentials()` builds a ZeroKMS client from
// the environment or the CLI's login, and loads the keyset's index key
// once, during construction.
let cipher = StackCipher::with_detected_credentials().await?;
// Terms bind to a keyset: this handle derives every term under the
// default keyset's index key.
let terms = cipher.default_keyset();
Expand Down
12 changes: 6 additions & 6 deletions packages/stack-encrypt/examples/zerokms_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ use stack_encrypt::StackCipher;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// --- The default: credentials from the environment ----------------------
// --- Detected credentials: from the environment or the CLI's login -------
//
// `StackCipher::new()` is `StackKmsBuilder::auto()` plus a client key,
// plus a keyset resolution. Both credentials are looked up the same way —
// environment first, then the current workspace in the CLI's profile
// directory (`~/.cipherstash`, written by `npx stash auth login`):
// `StackCipher::with_detected_credentials()` is the one constructor that
// looks for credentials itself. Both credentials are looked up the same
// way: the environment first, then the CLI's profile directory
// (`~/.cipherstash`, written by `npx stash auth login`):
//
// access token: CS_CLIENT_ACCESS_KEY + CS_WORKSPACE_CRN, else auth.json
// client key: CS_CLIENT_ID + CS_CLIENT_KEY, else secretkey.json
//
// So a logged-in developer machine needs nothing else; CI sets the four
// variables.
let cipher = match StackCipher::new().await {
let cipher = match StackCipher::with_detected_credentials().await {
Ok(cipher) => cipher,
// Nothing to connect to: say so and exit cleanly, so the example is
// safe to run anywhere.
Expand Down
Loading
Loading