Skip to content

Commit ec0dffc

Browse files
authored
Merge pull request #205 from cipherstash/cs-client-env-vars
feat(config) add zerokms and cts hosts
2 parents e9f1a11 + 5b8c2b4 commit ec0dffc

File tree

3 files changed

+89
-11
lines changed

3 files changed

+89
-11
lines changed

DEVELOPMENT.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,26 @@ The possible values are:
238238
- `warn`
239239
- `error`
240240

241-
A Proxy-wide default level is configured by setting the environment variable `RUST_LOG`.
242-
If this variable is not set, the default value set in the Proxy code will be used.
241+
The Proxy-wide default level can be configured by `CS_LOG__LEVEL`.
242+
Default level is `Info`.
243+
244+
Proxy has multiple "log targets" corresponding to the internal domains.
245+
246+
Set log levels for a specific log target to turn on or turn of more verbose logging:
247+
248+
```
249+
Target | ENV
250+
--------------- | -------------------------------------
251+
DEVELOPMENT | CS_LOG__DEVELOPMENT_LEVEL
252+
AUTHENTICATION | CS_LOG__AUTHENTICATION_LEVEL
253+
CONTEXT | CS_LOG__CONTEXT_LEVEL
254+
ENCRYPT | CS_LOG__ENCRYPT_LEVEL
255+
KEYSET | CS_LOG__KEYSET_LEVEL
256+
PROTOCOL | CS_LOG__PROTOCOL_LEVEL
257+
MAPPER | CS_LOG__MAPPER_LEVEL
258+
SCHEMA | CS_LOG__SCHEMA_LEVEL
259+
```
243260

244-
There are different "log targets" in Proxy.
245-
They correspond to modules or functionalities.
246-
Set log levels for a specific log target to turn on or turn of more verbose logging.
247261

248262
> [!IMPORTANT]
249263
> The application code must use the 'target' parameter for the per-target log level to work.
@@ -395,6 +409,8 @@ The integration tests have several runtime dependencies:
395409
- Credentials for CipherStash ZeroKMS (which can be found in the [quickstart](#developing) section)
396410

397411

412+
413+
398414
### Working with Encrypt Query Language (EQL)
399415

400416
The [Encrypt Query Language (EQL)](https://github.com/cipherstash/encrypt-query-language/) is a set of abstractions for transmitting, storing, and interacting with encrypted data and indexes in PostgreSQL.
@@ -481,6 +497,36 @@ If you ever get confused about where your configuration is coming from, run `mis
481497
Certificates are generated by `mkcert`, and live in `tests/tls/`.
482498

483499

500+
#### Configuration: development endpoints
501+
502+
503+
ZeroKMS and CTS host endpoints can be configured for local development.
504+
505+
Env variables are `CS_DEVELOPMENT__ZEROKMS_HOST` and `CS_DEVELOPMENT__CTS_HOST`.
506+
507+
508+
```toml
509+
510+
[development]
511+
# ZeroKMS host
512+
# Optional
513+
# Defaults to CipherStash Production ZeroKMS host
514+
# Env: CS_DEVELOPMENT__ZEROKMS_HOST
515+
zerokms_host = "1.1.1.1"
516+
517+
518+
# CTS host
519+
# Optional
520+
# Defaults to CipherStash Production CTS host
521+
# Env: CS_DEVELOPMENT__CTS_HOST
522+
cts_host = "1.1.1.1"
523+
524+
```
525+
526+
527+
528+
529+
484530
## Logging
485531

486532
- Use structured logging

packages/cipherstash-proxy/src/config/tandem.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ pub struct DevelopmentConfig {
6565

6666
#[serde(default)]
6767
pub enable_mapping_errors: bool,
68+
69+
#[serde(default)]
70+
pub zerokms_host: Option<String>,
71+
72+
#[serde(default)]
73+
pub cts_host: Option<String>,
6874
}
6975

7076
/// Config defaults to a file called `tandem` in the current directory.
@@ -198,6 +204,18 @@ impl TandemConfig {
198204
}
199205
}
200206

207+
pub fn zerokms_host(&self) -> Option<String> {
208+
self.development
209+
.as_ref()
210+
.and_then(|dev| dev.zerokms_host.clone())
211+
}
212+
213+
pub fn cts_host(&self) -> Option<String> {
214+
self.development
215+
.as_ref()
216+
.and_then(|dev| dev.cts_host.clone())
217+
}
218+
201219
pub fn use_structured_logging(&self) -> bool {
202220
matches!(self.log.format, LogFormat::Structured)
203221
}

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
Identifier,
1111
};
1212
use cipherstash_client::{
13+
config::EnvSource,
1314
credentials::{auto_refresh::AutoRefresh, ServiceCredentials},
1415
encryption::{
1516
self, Encrypted, EncryptionError, IndexTerm, Plaintext, PlaintextTarget,
@@ -190,19 +191,32 @@ impl Encrypt {
190191

191192
async fn init_cipher(config: &TandemConfig) -> Result<ScopedCipher, Error> {
192193
let console_config = ConsoleConfig::builder().with_env().build()?;
193-
let cts_config = CtsConfig::builder().with_env().build()?;
194194

195-
// Not using with_env because the proxy config should take precedence
196-
let builder = ZeroKMSConfig::builder(); //.with_env();
195+
let builder = CtsConfig::builder().with_env();
196+
let builder = if let Some(cts_host) = config.cts_host() {
197+
builder.base_url(&cts_host)
198+
} else {
199+
builder
200+
};
201+
let cts_config = builder.build()?;
197202

198-
let zerokms_config = builder
203+
// Not using with_env because the proxy config should take precedence
204+
let builder = ZeroKMSConfig::builder()
205+
.add_source(EnvSource::default())
199206
.workspace_id(&config.auth.workspace_id)
200207
.access_key(&config.auth.client_access_key)
201208
.try_with_client_id(&config.encrypt.client_id)?
202209
.try_with_client_key(&config.encrypt.client_key)?
203210
.console_config(&console_config)
204-
.cts_config(&cts_config)
205-
.build_with_client_key()?;
211+
.cts_config(&cts_config);
212+
213+
let builder = if let Some(zerokms_host) = config.zerokms_host() {
214+
builder.base_url(zerokms_host)
215+
} else {
216+
builder
217+
};
218+
219+
let zerokms_config = builder.build_with_client_key()?;
206220

207221
let zerokms_client = zerokms_config
208222
.create_client_with_credentials(AutoRefresh::new(zerokms_config.credentials()));

0 commit comments

Comments
 (0)