Skip to content

Commit 8cb9a16

Browse files
committed
fix(deps): bump cipherstash-client from 0.33.2 to 0.34.0-alpha.2
Migrate ZeroKMS initialization from config-builder chain (ConsoleConfig/CtsConfig/ZeroKMSConfig/EnvSource) to the new ZeroKMSBuilder + AutoStrategy API. - Replace AutoRefresh<ServiceCredentials> with AutoStrategy - Use ClientKey::from_hex_v1 for client key construction - Update error variant: zerokms::Error::Credentials -> Error::Auth - Add ZeroKMSBuilderError variant to Error enum - Remove build_zerokms_config (replaced by init_zerokms_client) - Update cts-common to 0.34.0-alpha.3 - Pin vitaminc to 0.1.0-pre4.1 (pre4.2 broke backward compat)
1 parent 7cab49e commit 8cb9a16

File tree

8 files changed

+663
-333
lines changed

8 files changed

+663
-333
lines changed

Cargo.lock

Lines changed: 605 additions & 218 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ debug = true
4343

4444
[workspace.dependencies]
4545
sqltk = { version = "0.10.0" }
46-
cipherstash-client = { version = "0.33.2" }
47-
cts-common = { version = "0.4.1" }
46+
cipherstash-client = { version = "0.34.0-alpha.2" }
47+
cts-common = { version = "0.34.0-alpha.3" }
4848

4949
thiserror = "2.0.9"
5050
tokio = { version = "1.44.2", features = ["full"] }

packages/cipherstash-proxy-integration/src/generate.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#[cfg(test)]
22
mod tests {
33
use crate::common::trace;
4-
use cipherstash_client::config::EnvSource;
5-
use cipherstash_client::credentials::auto_refresh::AutoRefresh;
64
use cipherstash_client::encryption::{
75
Encrypted, EncryptedSteVecTerm, JsonIndexer, JsonIndexerOptions, OreTerm, Plaintext,
86
PlaintextTarget, ReferencedPendingPipeline,
97
};
8+
use cipherstash_client::zerokms::{ClientKey, ZeroKMSBuilder};
109
use cipherstash_client::{encryption::ScopedCipher, zerokms::EncryptedRecord};
11-
use cipherstash_client::{ConsoleConfig, CtsConfig, ZeroKMSConfig};
1210
use cipherstash_config::column::{ArrayIndexMode, Index, IndexType};
1311
use cipherstash_config::{ColumnConfig, ColumnType};
1412
use cipherstash_proxy::Identifier;
@@ -129,16 +127,19 @@ mod tests {
129127
// clear().await;
130128
// let client = connect_with_tls(PROXY).await;
131129

132-
let console_config = ConsoleConfig::builder().with_env().build().unwrap();
133-
let cts_config = CtsConfig::builder().with_env().build().unwrap();
134-
let zerokms_config = ZeroKMSConfig::builder()
135-
.add_source(EnvSource::default())
136-
.console_config(&console_config)
137-
.cts_config(&cts_config)
138-
.build_with_client_key()
130+
let client_id: uuid::Uuid = std::env::var("CS_CLIENT_ID")
131+
.expect("CS_CLIENT_ID must be set")
132+
.parse()
133+
.expect("CS_CLIENT_ID must be a valid UUID");
134+
let client_key_hex =
135+
std::env::var("CS_CLIENT_KEY").expect("CS_CLIENT_KEY must be set");
136+
let client_key = ClientKey::from_hex_v1(client_id, &client_key_hex)
137+
.expect("CS_CLIENT_KEY must be valid hex");
138+
let zerokms_client = ZeroKMSBuilder::auto()
139+
.unwrap()
140+
.with_client_key(client_key)
141+
.build()
139142
.unwrap();
140-
let zerokms_client = zerokms_config
141-
.create_client_with_credentials(AutoRefresh::new(zerokms_config.credentials()));
142143

143144
let dataset_id = Uuid::parse_str("295504329cb045c398dc464c52a287a1").unwrap();
144145

packages/cipherstash-proxy/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,15 @@ tokio-rustls = "0.26.0"
5454
tokio-util = { version = "0.7.13", features = ["rt"] }
5555
tracing = { workspace = true }
5656
tracing-subscriber = { workspace = true }
57+
url = "2"
58+
# Pin vitaminc to 0.1.0-pre4.1 — pre4.2 removed root-level re-exports breaking cts-common
59+
vitaminc = { version = "= 0.1.0-pre4.1", features = ["random", "protected", "encrypt"] }
60+
vitaminc-random = { version = "= 0.1.0-pre4.1" }
61+
vitaminc-protected = { version = "= 0.1.0-pre4.1" }
62+
vitaminc-encrypt = { version = "= 0.1.0-pre4.1" }
63+
vitaminc-traits = { version = "= 0.1.0-pre4.1" }
5764
uuid = { version = "1.11.0", features = ["serde", "v4"] }
5865
x509-parser = "0.17.0"
59-
vitaminc-protected = "0.1.0-pre2"
6066

6167

6268
[dev-dependencies]

packages/cipherstash-proxy/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ pub enum Error {
5454
#[error(transparent)]
5555
ZeroKMS(#[from] ZeroKMSError),
5656

57+
#[error(transparent)]
58+
ZeroKMSBuilder(#[from] cipherstash_client::zerokms::ZeroKMSBuilderError),
59+
5760
#[error("Unknown error")]
5861
Unknown,
5962

packages/cipherstash-proxy/src/proxy/mod.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -166,57 +166,3 @@ pub trait EncryptionService: Send + Sync {
166166
) -> Result<Vec<Option<Plaintext>>, Error>;
167167
}
168168

169-
#[cfg(test)]
170-
mod tests {
171-
use super::*;
172-
use crate::config::TandemConfig;
173-
use crate::test_helpers::with_no_cs_vars;
174-
use cts_common::WorkspaceId;
175-
176-
fn build_tandem_config(env: Vec<(&str, Option<&str>)>) -> TandemConfig {
177-
with_no_cs_vars(|| {
178-
temp_env::with_vars(env, || {
179-
TandemConfig::build_path("tests/config/unknown.toml").unwrap()
180-
})
181-
})
182-
}
183-
184-
fn default_env_vars() -> Vec<(&'static str, Option<&'static str>)> {
185-
vec![
186-
("CS_DATABASE__USERNAME", Some("postgres")),
187-
("CS_DATABASE__PASSWORD", Some("password")),
188-
("CS_DATABASE__NAME", Some("db")),
189-
("CS_DATABASE__HOST", Some("localhost")),
190-
("CS_DATABASE__PORT", Some("5432")),
191-
("CS_ENCRYPT__KEYSET_ID", Some("c50d8463-60e9-41a5-86cd-5782e03a503c")),
192-
("CS_ENCRYPT__CLIENT_ID", Some("e40f1692-6bb7-4bbd-a552-4c0f155be073")),
193-
("CS_ENCRYPT__CLIENT_KEY", Some("a4627031a16b7065726d75746174696f6e90090e0805000b0d0c0106040f0a0302076770325f66726f6da16b7065726d75746174696f6e9007060a0b02090d080c00040f0305010e6570325f746fa16b7065726d75746174696f6e900a0206090b04050c070f0e010d030800627033a16b7065726d75746174696f6e98210514181d0818200a18190b1112181809130f15181a0717181e000e0103181f0d181c1602040c181b1006")),
194-
]
195-
}
196-
197-
#[test]
198-
fn build_zerokms_config_with_crn() {
199-
with_no_cs_vars(|| {
200-
let mut env = default_env_vars();
201-
env.push(("CS_CLIENT_ACCESS_KEY", Some("client-access-key")));
202-
env.push((
203-
"CS_WORKSPACE_CRN",
204-
Some("crn:ap-southeast-2.aws:3KISDURL3ZCWYZ2O"),
205-
));
206-
207-
let tandem_config = build_tandem_config(env);
208-
209-
let zerokms_config = zerokms::build_zerokms_config(&tandem_config).unwrap();
210-
211-
assert_eq!(
212-
WorkspaceId::try_from("3KISDURL3ZCWYZ2O").unwrap(),
213-
zerokms_config.workspace_id()
214-
);
215-
216-
assert!(zerokms_config
217-
.base_url()
218-
.to_string()
219-
.contains("ap-southeast-2.aws"));
220-
});
221-
}
222-
}

packages/cipherstash-proxy/src/proxy/zerokms/mod.rs

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,43 @@ mod zerokms;
44
pub use zerokms::ZeroKms;
55

66
use crate::config::TandemConfig;
7-
use cipherstash_client::config::{ConfigError, ZeroKMSConfigWithClientKey};
87
use cipherstash_client::{
9-
config::EnvSource,
10-
credentials::{auto_refresh::AutoRefresh, ServiceCredentials},
11-
zerokms::ClientKey,
12-
ConsoleConfig, CtsConfig, ZeroKMS, ZeroKMSConfig,
8+
zerokms::{ClientKey, ZeroKMSBuilder, ZeroKMSBuilderError},
9+
AutoStrategy, ZeroKMS,
1310
};
1411

15-
pub type ScopedCipher =
16-
cipherstash_client::encryption::ScopedCipher<AutoRefresh<ServiceCredentials>>;
12+
pub type ScopedCipher = cipherstash_client::encryption::ScopedCipher<AutoStrategy>;
1713

18-
pub type ZerokmsClient = ZeroKMS<AutoRefresh<ServiceCredentials>, ClientKey>;
14+
pub type ZerokmsClient = ZeroKMS<AutoStrategy, ClientKey>;
1915

2016
pub(crate) fn init_zerokms_client(
2117
config: &TandemConfig,
22-
) -> Result<ZeroKMS<AutoRefresh<ServiceCredentials>, ClientKey>, ConfigError> {
23-
let zerokms_config = build_zerokms_config(config)?;
24-
25-
Ok(zerokms_config
26-
.create_client_with_credentials(AutoRefresh::new(zerokms_config.credentials())))
27-
}
28-
29-
pub fn build_zerokms_config(
30-
config: &TandemConfig,
31-
) -> Result<ZeroKMSConfigWithClientKey, ConfigError> {
32-
let console_config = ConsoleConfig::builder().with_env().build()?;
33-
34-
let builder = CtsConfig::builder().with_env();
35-
let builder = if let Some(cts_host) = config.cts_host() {
36-
builder.base_url(&cts_host)
37-
} else {
38-
builder
39-
};
40-
let cts_config = builder.build()?;
41-
42-
// Not using with_env because the proxy config should take precedence
43-
let builder = ZeroKMSConfig::builder()
44-
.add_source(EnvSource::default())
45-
.workspace_crn(config.auth.workspace_crn.clone())
46-
.access_key(&config.auth.client_access_key)
47-
.try_with_client_id(&config.encrypt.client_id)?
48-
.try_with_client_key(&config.encrypt.client_key)?
49-
.console_config(&console_config)
50-
.cts_config(&cts_config);
51-
52-
let builder = if let Some(zerokms_host) = config.zerokms_host() {
53-
builder.base_url(zerokms_host)
54-
} else {
55-
builder
56-
};
57-
58-
builder.build_with_client_key()
18+
) -> Result<ZerokmsClient, ZeroKMSBuilderError> {
19+
// 1. Build auth strategy from proxy config
20+
let strategy = AutoStrategy::builder()
21+
.with_access_key(&config.auth.client_access_key)
22+
.with_workspace_crn(config.auth.workspace_crn.clone())
23+
.detect()?;
24+
25+
// 2. Parse client key
26+
let client_id: uuid::Uuid = config
27+
.encrypt
28+
.client_id
29+
.parse()
30+
.expect("client_id must be a valid UUID");
31+
let client_key = ClientKey::from_hex_v1(client_id, &config.encrypt.client_key)
32+
.expect("client_key must be valid hex");
33+
34+
// 3. Build ZeroKMS client (with_base_url must be called before with_client_key)
35+
let mut builder = ZeroKMSBuilder::new(strategy);
36+
37+
// Optional: override ZeroKMS endpoint for development
38+
if let Some(zerokms_host) = config.zerokms_host() {
39+
let url: url::Url = zerokms_host
40+
.parse()
41+
.expect("zerokms_host must be a valid URL");
42+
builder = builder.with_base_url(url);
43+
}
44+
45+
builder.with_client_key(client_key).build()
5946
}

packages/cipherstash-proxy/src/proxy/zerokms/zerokms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl ZeroKms {
137137
}
138138
.into())
139139
}
140-
cipherstash_client::zerokms::Error::Credentials(_) => {
140+
cipherstash_client::zerokms::Error::Auth(_) => {
141141
Err(ZeroKMSError::AuthenticationFailed.into())
142142
}
143143
_ => Err(Error::ZeroKMS(err.into())),

0 commit comments

Comments
 (0)