From 689f13f1b330d98ccbbe3240373b4d5b18e4b162 Mon Sep 17 00:00:00 2001 From: Mohamed Aziz Ktata Date: Thu, 5 Nov 2026 11:38:05 +0100 Subject: [PATCH 1/7] docs(tenet): document the next Tenet release's changed defaults The next Tenet (guepard-tenet feature/performance-tuning) refuses writes on a masked connection by default and derives masked values with siphash instead of xxhash64, so every masked value changes for the same salt. Both were run against a local Postgres with the branch build and with main's: every sample proxy.yaml under scripts/ loads and masks reads on both, the UPDATE main allows is refused, and seed_derivation: xxhash64 reproduces main's hash. The CLI passes proxy.yaml through unchanged, so no code changes are needed. --- CHANGELOG.md | 5 +++++ docs/documentation/tenet.md | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0c29ba..10c5a50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to Guepard CLI will be documented in this file. +## Unreleased + +### Documentation +- **Tenet guide**: [behaviour changes in the next Tenet release](docs/documentation/tenet.md#behaviour-changes-in-the-next-tenet-release). Writes through a masked port are refused by default (`block_writes`), and masked values change for the same salt (`seed_derivation: siphash`); the guide shows how to keep the old behaviour. Every sample `proxy.yaml` under `scripts/` was checked against that release and loads unchanged. + ## v0.29.10 (2026-06-08) ### Features diff --git a/docs/documentation/tenet.md b/docs/documentation/tenet.md index 1a5b08a..270ad7c 100644 --- a/docs/documentation/tenet.md +++ b/docs/documentation/tenet.md @@ -108,6 +108,30 @@ This repo ships small samples under **`scripts/`**: | `scripts/sql/tenet_masking_seed.sql` | Seed table + row for demos | | `scripts/tenet-e2e-from-deploy.sh` | Scripted flow: deploy → compute → seed → tenet (`cargo run` by default; set `USE_INSTALLED_GUEPARD=1` for `guepard` on `PATH`) | +### Behaviour changes in the next Tenet release + +The next Tenet (guepard-tenet branch `feature/performance-tuning`, not yet on its `main`) reads +every `proxy.yaml` shipped under `scripts/` unchanged, but two defaults change what clients of a +masked port see. Both can be set back in `proxy.yaml`, then pushed with `guepard tenet proxy set`. + +| Change | What a client notices | Keep the old behaviour | +|--------|-----------------------|------------------------| +| **Writes are refused** on a masked connection (`block_writes`, on by default) | `INSERT` / `UPDATE` / `DELETE` through the Tenet port fail with `UPDATE is not permitted on a masked connection while block_writes is on…`. Reads are unchanged. Writing directly to Postgres still works. | `block_writes: false`. With it off, Tenet refuses a write that would store a masked value in a column masked by another rule. | +| **Masked values change** for the same salt (`seed_derivation` now defaults to `siphash`, was `xxhash64`) | Every deterministic masked value (for example a `hash` column) differs from what the previous release returned. | `seed_derivation: xxhash64`, while anything that stored old masked values is migrated. | + +Other additions, all opt-in (see the guepard-tenet docs on that branch): + +- **`tuning`**: developers can create and drop indexes and refresh statistics on the real database through Tenet, without seeing values. +- **`auth`**: Tenet authenticates clients itself and connects upstream with its own account. +- **`strict_masking`**: refuses any statement that would move a masked value out of its column. +- **`column_groups`**: masks related columns from one draw, so a row stays consistent. +- **Column patterns and `table: "*"`**: one rule can cover several columns. + +The `custom-wasm` transformer is removed. Columns that used it fall back to the generic masking and log a warning. + +`table:` is not enforced: a rule masks its column in every result set, not only in the named +table. The proxy logs this as a warning at startup. + --- ## Connecting with `psql` @@ -134,6 +158,8 @@ psql "host= port= user=guepard dbname=postgres ss | **`tenet start` 404** | Scheduler idempotency / job already running — verify Nomad alloc. | | **Hang on `psql` to EIP:tenet-port** | Security group / NACL / no DNAT to host where Tenet listens. Open same path as for Postgres host port. | | **Plaintext through Tenet** | Rules don’t match **table/column** names; wrong DB in connection string; or `masking_enabled: false`. | +| **`… is not permitted on a masked connection while block_writes is on`** | Next Tenet release: writes through the masked port are refused by default. Write directly to Postgres, or set `block_writes: false` ([behaviour changes](#behaviour-changes-in-the-next-tenet-release)). | +| **Masked values differ after a Tenet upgrade** | Next Tenet release: `seed_derivation` defaults to `siphash`. Pin `seed_derivation: xxhash64` to keep the old values. | --- From 4a52a223a31f779e6324390f4631c9c01853ebc0 Mon Sep 17 00:00:00 2001 From: Mohamed Aziz Ktata Date: Thu, 5 Nov 2026 12:00:05 +0100 Subject: [PATCH 2/7] docs(tenet): pair block_writes: false with strict_masking: true The previous commit told readers to set block_writes: false to keep writes working. Run on Nomad with the branch image, that alone lets a client copy a masked column into an unmasked one ('reach me: ' || email) and read the real value back; strict_masking: true refuses the copy. Also note that an email inside free text in a column without a rule is not masked by the content scanner. --- CHANGELOG.md | 2 +- docs/documentation/tenet.md | 30 +++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10c5a50..b8e1c6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to Guepard CLI will be documented in this file. ## Unreleased ### Documentation -- **Tenet guide**: [behaviour changes in the next Tenet release](docs/documentation/tenet.md#behaviour-changes-in-the-next-tenet-release). Writes through a masked port are refused by default (`block_writes`), and masked values change for the same salt (`seed_derivation: siphash`); the guide shows how to keep the old behaviour. Every sample `proxy.yaml` under `scripts/` was checked against that release and loads unchanged. +- **Tenet guide**: [behaviour changes in the next Tenet release](docs/documentation/tenet.md#behaviour-changes-in-the-next-tenet-release). Writes through a masked port are refused by default (`block_writes`), and masked values change for the same salt (`seed_derivation: siphash`); the guide shows how to keep the old behaviour, and why allowing writes needs `strict_masking: true`. Every sample `proxy.yaml` under `scripts/` was checked against that release and loads unchanged. ## v0.29.10 (2026-06-08) diff --git a/docs/documentation/tenet.md b/docs/documentation/tenet.md index 270ad7c..5266401 100644 --- a/docs/documentation/tenet.md +++ b/docs/documentation/tenet.md @@ -116,17 +116,41 @@ masked port see. Both can be set back in `proxy.yaml`, then pushed with `guepard | Change | What a client notices | Keep the old behaviour | |--------|-----------------------|------------------------| -| **Writes are refused** on a masked connection (`block_writes`, on by default) | `INSERT` / `UPDATE` / `DELETE` through the Tenet port fail with `UPDATE is not permitted on a masked connection while block_writes is on…`. Reads are unchanged. Writing directly to Postgres still works. | `block_writes: false`. With it off, Tenet refuses a write that would store a masked value in a column masked by another rule. | +| **Writes are refused** on a masked connection (`block_writes`, on by default) | `INSERT` / `UPDATE` / `DELETE` through the Tenet port fail with `UPDATE is not permitted on a masked connection while block_writes is on…`. Reads are unchanged. Writing directly to Postgres still works. | `block_writes: false` **together with `strict_masking: true`** ([see below](#allowing-writes-safely)). | | **Masked values change** for the same salt (`seed_derivation` now defaults to `siphash`, was `xxhash64`) | Every deterministic masked value (for example a `hash` column) differs from what the previous release returned. | `seed_derivation: xxhash64`, while anything that stored old masked values is migrated. | Other additions, all opt-in (see the guepard-tenet docs on that branch): - **`tuning`**: developers can create and drop indexes and refresh statistics on the real database through Tenet, without seeing values. - **`auth`**: Tenet authenticates clients itself and connects upstream with its own account. -- **`strict_masking`**: refuses any statement that would move a masked value out of its column. +- **`strict_masking`**: refuses any statement that would move a masked value out of its column. On by default only with `tuning` or `auth`. - **`column_groups`**: masks related columns from one draw, so a row stays consistent. - **Column patterns and `table: "*"`**: one rule can cover several columns. +#### Allowing writes safely + +Never set `block_writes: false` without `strict_masking: true`. With strict masking off, a +client can copy a masked column into a column no rule covers and read the real value back: + +```sql +UPDATE customers SET notes = 'reach me: ' || email WHERE id = 4; -- accepted +SELECT notes FROM customers WHERE id = 4; -- the real email, unmasked +``` + +With `strict_masking: true` the copy is refused (`the operator || over a masked column is not +permitted`; a plain `SET notes = email` gets `'notes' would receive the value of a masked +column`). Strict masking also refuses functions and casts over masked columns +in reads (`SELECT upper(email)`), so check the application's queries before turning it on. + +```yaml +block_writes: false +strict_masking: true +``` + +The content scanner does not mask an email that sits inside free text in a column without a +rule (`call back at user1@example.com` comes through as is). Give free-text columns a rule of +their own, for example `column: notes` with `transformer: redacted`. + The `custom-wasm` transformer is removed. Columns that used it fall back to the generic masking and log a warning. `table:` is not enforced: a rule masks its column in every result set, not only in the named @@ -158,7 +182,7 @@ psql "host= port= user=guepard dbname=postgres ss | **`tenet start` 404** | Scheduler idempotency / job already running — verify Nomad alloc. | | **Hang on `psql` to EIP:tenet-port** | Security group / NACL / no DNAT to host where Tenet listens. Open same path as for Postgres host port. | | **Plaintext through Tenet** | Rules don’t match **table/column** names; wrong DB in connection string; or `masking_enabled: false`. | -| **`… is not permitted on a masked connection while block_writes is on`** | Next Tenet release: writes through the masked port are refused by default. Write directly to Postgres, or set `block_writes: false` ([behaviour changes](#behaviour-changes-in-the-next-tenet-release)). | +| **`… is not permitted on a masked connection while block_writes is on`** | Next Tenet release: writes through the masked port are refused by default. Write directly to Postgres, or set `block_writes: false` with `strict_masking: true` ([allowing writes safely](#allowing-writes-safely)). | | **Masked values differ after a Tenet upgrade** | Next Tenet release: `seed_derivation` defaults to `siphash`. Pin `seed_derivation: xxhash64` to keep the old values. | --- From d1b1abdcfb4d00bb8276289c1aca66ffec5d4103 Mon Sep 17 00:00:00 2001 From: Mohamed Aziz Ktata Date: Thu, 5 Nov 2026 13:45:31 +0100 Subject: [PATCH 3/7] fix(deploy): wait for masked_status ready, not just a Tenet port deploy --masked returned as soon as GET /deploy/{id} carried a tenet_proxy_port. The API sends that port while the Tenet job runs and the database behind it is still starting or failing, so the CLI could report success before the database accepted a connection (against a local stack it returned after 7s). Only masked_status ready now ends the wait; the port alone counts only for an API that sends no masked_status. --- src/application/services/deploy.rs | 55 ++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/src/application/services/deploy.rs b/src/application/services/deploy.rs index 6cef9cd..e81e796 100644 --- a/src/application/services/deploy.rs +++ b/src/application/services/deploy.rs @@ -74,6 +74,25 @@ pub async fn create_deployment( create_deployment_with_deps(request, config, &auth_provider).await } +#[derive(Debug, PartialEq, Eq)] +enum MaskedProgress { + Ready, + Failed, + Pending, +} + +/// The API returns the Tenet port as soon as the proxy job runs, before the database behind it +/// is up, so only `masked_status: ready` means ready. The port alone counts only for an API that +/// sends no `masked_status` at all. +fn masked_progress(masked_status: Option<&str>, tenet_proxy_port: Option) -> MaskedProgress { + match masked_status { + Some("ready") => MaskedProgress::Ready, + Some("failed") => MaskedProgress::Failed, + None if tenet_proxy_port.is_some() => MaskedProgress::Ready, + _ => MaskedProgress::Pending, + } +} + /// Poll GET /deploy/{id} until masked Tenet is ready or failed. pub async fn poll_masked_deployment_ready( deployment_id: &str, @@ -85,12 +104,15 @@ pub async fn poll_masked_deployment_ready( loop { let dep = get_deployment(deployment_id, config).await?; - if dep.masked_status.as_deref() == Some("ready") || dep.tenet_proxy_port.is_some() { - return Ok(dep); - } - if dep.masked_status.as_deref() == Some("failed") { - let detail = dep.message.unwrap_or_else(|| "Tenet provisioning failed".to_string()); - return Err(DeployError::ApiError(detail)); + match masked_progress(dep.masked_status.as_deref(), dep.tenet_proxy_port) { + MaskedProgress::Ready => return Ok(dep), + MaskedProgress::Failed => { + let detail = dep + .message + .unwrap_or_else(|| "Tenet provisioning failed".to_string()); + return Err(DeployError::ApiError(detail)); + } + MaskedProgress::Pending => {} } if started.elapsed() > MAX_WAIT { return Err(DeployError::ApiError( @@ -314,6 +336,27 @@ pub async fn list_pending_deployments( mod tests { use super::*; + #[test] + fn masked_deployment_with_a_port_but_not_ready_keeps_waiting() { + // What GET returns while Tenet runs and the database behind it is still starting. + let progress = masked_progress(Some("provisioning"), Some(30665)); + assert_eq!(progress, MaskedProgress::Pending); + } + + #[test] + fn masked_deployment_is_ready_only_on_ready() { + let port = Some(30665); + assert_eq!(masked_progress(Some("ready"), port), MaskedProgress::Ready); + assert_eq!(masked_progress(Some("failed"), port), MaskedProgress::Failed); + assert_eq!(masked_progress(Some("starting"), None), MaskedProgress::Pending); + } + + #[test] + fn an_api_without_masked_status_falls_back_to_the_port() { + assert_eq!(masked_progress(None, Some(30665)), MaskedProgress::Ready); + assert_eq!(masked_progress(None, None), MaskedProgress::Pending); + } + #[tokio::test] async fn test_list_deployments_session_error() { let config = Config { From 7348f956e93bcb11f12c48c4595f78cbe39832a6 Mon Sep 17 00:00:00 2001 From: Mohamed Aziz Ktata Date: Thu, 5 Nov 2026 14:23:05 +0100 Subject: [PATCH 4/7] feat(tenet): send Tenet's upstream password; report pending restarts deploy --masked, tenet deploy and tenet proxy set take --upstream-password (env GUEPARD_TENET_UPSTREAM_PASSWORD) for Tenet's auth mode; the API refuses it inline in proxy.yaml and keeps it in the proxy's Nomad Variable. deploy sends it only with --masked, so the env var does not leak into other deploys. The API now answers tenet deploy/start/proxy set with 202 and status pending when the proxy is not running within ~20 s. Those calls used to accept only 200, so a 202 would have been reported as an error; they now succeed and say the proxy is still starting. --- CHANGELOG.md | 7 +++ docs/documentation/tenet.md | 34 +++++++++++++ src/application/commands/deploy.rs | 7 +++ src/application/commands/tenet.rs | 79 +++++++++++++++++++++++++++++- src/application/dto/deploy.rs | 2 + src/application/dto/tenet.rs | 39 +++++++++++++++ src/application/services/deploy.rs | 1 + src/application/services/tenet.rs | 30 ++++++++++-- src/structure.rs | 12 +++++ 9 files changed, 205 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8e1c6d..e5b433a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All notable changes to Guepard CLI will be documented in this file. ## Unreleased +### Features +- **Tenet `auth`**: `--upstream-password` (or `GUEPARD_TENET_UPSTREAM_PASSWORD`) on `deploy --masked`, `tenet deploy` and `tenet proxy set` sends Tenet's own database password separately from `proxy.yaml` + +### Fixes +- **Masked deploy**: waits for `masked_status: ready` instead of returning as soon as a Tenet port exists +- **Tenet commands**: a proxy that is still starting (API answer 202, `status: pending`) is reported as such instead of as an error + ### Documentation - **Tenet guide**: [behaviour changes in the next Tenet release](docs/documentation/tenet.md#behaviour-changes-in-the-next-tenet-release). Writes through a masked port are refused by default (`block_writes`), and masked values change for the same salt (`seed_derivation: siphash`); the guide shows how to keep the old behaviour, and why allowing writes needs `strict_masking: true`. Every sample `proxy.yaml` under `scripts/` was checked against that release and loads unchanged. diff --git a/docs/documentation/tenet.md b/docs/documentation/tenet.md index 5266401..f6cacbc 100644 --- a/docs/documentation/tenet.md +++ b/docs/documentation/tenet.md @@ -156,6 +156,40 @@ The `custom-wasm` transformer is removed. Columns that used it fall back to the `table:` is not enforced: a rule masks its column in every result set, not only in the named table. The proxy logs this as a warning at startup. +#### Tenet's own login (`auth`) and `--upstream-password` + +With `auth:`, clients sign in to Tenet with Tenet's own users, and Tenet signs in to the +database with one account of its own. Its password never goes in `proxy.yaml` (the API refuses +an inline `auth.upstream.password` with 400): point Tenet at an environment variable and send the +password separately. + +```yaml +auth: + users: + - name: dev + password: "SCRAM-SHA-256$4096:..." # a verifier, as PostgreSQL stores it + upstream: + user: app_owner + password_env: TENET_UPSTREAM_PASSWORD +``` + +```bash +export GUEPARD_TENET_UPSTREAM_PASSWORD='' # or --upstream-password +guepard deploy ... --masked --proxy-config ./proxy.yaml # new masked deployment +guepard tenet proxy set --proxy-config ./proxy.yaml # existing proxy +``` + +The API keeps the password in the proxy's Nomad Variable and hands it to Tenet as +`TENET_UPSTREAM_PASSWORD`; it is not in the job definition, its history, or `tenet proxy get`. +Set it once: later `proxy set` calls without it keep the stored one. + +#### When a change takes a while to apply + +`tenet deploy`, `tenet start` and `tenet proxy set` wait up to about 20 seconds for the proxy to +run. If it is still starting, they say so (`⏳ The proxy is still starting...`) instead of +failing; the change is saved and applies on its own. `guepard deploy -x ` shows +`Masked status: ready` once both Tenet and the database behind it are running. + --- ## Connecting with `psql` diff --git a/src/application/commands/deploy.rs b/src/application/commands/deploy.rs index 9e07322..8eedea2 100644 --- a/src/application/commands/deploy.rs +++ b/src/application/commands/deploy.rs @@ -450,6 +450,12 @@ async fn create_deployment( masked: if args.masked { Some(true) } else { None }, proxy_yaml, masking_salt: args.masking_salt.clone(), + // Only for a masked deploy: the env var may be set for other commands. + upstream_password: if args.masked { + args.upstream_password.clone() + } else { + None + }, }; let mut deployment = deploy::create_deployment(request, config).await?; @@ -1544,6 +1550,7 @@ async fn interactive_deploy(config: &Config) -> Result<()> { masked: None, proxy_yaml: None, masking_salt: None, + upstream_password: None, }; let deployment = deploy::create_deployment(request, config).await?; diff --git a/src/application/commands/tenet.rs b/src/application/commands/tenet.rs index 53b4797..b337fbf 100644 --- a/src/application/commands/tenet.rs +++ b/src/application/commands/tenet.rs @@ -112,6 +112,14 @@ async fn resolve_postgres_host_for_hints(upstream_host: &str) -> Option Some(picked.ip().to_string()) } +const PENDING_NOTE: &str = + "⏳ The proxy is still starting with this config; it is not accepting connections yet. Check again in a few seconds."; + +/// The API answers 202 with status "pending" when the proxy was not running yet when it stopped waiting. +fn is_pending(status: Option<&str>) -> bool { + status == Some("pending") +} + async fn deploy( d: &TenetDeployCliArgs, config: &Config, @@ -146,6 +154,7 @@ async fn deploy( config_yaml, proxy_port: d.proxy_port, api_port: d.api_port, + upstream_password: d.upstream_password.clone(), }; let resp = tenet::deploy_tenet(&body, config).await?; @@ -176,6 +185,9 @@ async fn deploy( if output_format == OutputFormat::Table { println!("{} Tenet deploy submitted", "✅".green()); + if is_pending(resp.status.as_deref()) { + println!("{}", PENDING_NOTE.yellow()); + } print_row_or_json(row, output_format); for line in tenet_deploy_hint_lines(&resp, connect_host_str) { println!("{}", line); @@ -199,6 +211,7 @@ async fn lifecycle( _ => unreachable!(), }; + let pending = is_pending(resp.status.as_deref()); let message = resp .message .unwrap_or_else(|| format!("Tenet {} completed", action)); @@ -210,6 +223,9 @@ async fn lifecycle( if output_format == OutputFormat::Table { println!("{} Tenet {}", "✅".green(), action); + if pending { + println!("{}", PENDING_NOTE.yellow()); + } print_row_or_json(row, output_format); } else { print_json(&row); @@ -264,7 +280,15 @@ async fn proxy_set( )) })?; let apply = s.apply.unwrap_or(true); - let resp = tenet::set_proxy_yaml(&s.job_id, &yaml, apply, config).await?; + let resp = tenet::set_proxy_yaml( + &s.job_id, + &yaml, + apply, + s.upstream_password.as_deref(), + config, + ) + .await?; + let pending = is_pending(resp.status.as_deref()); if output_format == OutputFormat::Json { print_json(&serde_json::json!({ @@ -272,7 +296,11 @@ async fn proxy_set( "apply": apply, "message": resp.message, "status": "updated", + "proxy_status": resp.status, })); + } else if pending { + println!("{} Proxy config saved (apply={})", "✅".green(), apply); + println!("{}", PENDING_NOTE.yellow()); } else { println!("{} Proxy config updated (apply={})", "✅".green(), apply); if let Some(m) = resp.message { @@ -285,6 +313,50 @@ async fn proxy_set( #[cfg(test)] mod tests { use super::*; + + fn parse_proxy_set(args: &[&str]) -> crate::structure::TenetProxySetArgs { + use clap::Parser; + let cli = crate::structure::CLI::try_parse_from(args).expect("parses"); + match cli.sub_commands { + crate::structure::SubCommand::Tenet(t) => match t.command { + crate::structure::TenetCommand::Proxy(p) => match p.action { + crate::structure::TenetProxyAction::Set(s) => s, + other => panic!("not proxy set: {:?}", other), + }, + other => panic!("not tenet proxy: {:?}", other), + }, + other => panic!("not tenet: {:?}", other), + } + } + + #[test] + fn proxy_set_takes_upstream_password_from_flag_or_env() { + let base = [ + "guepard", + "tenet", + "proxy", + "set", + "job-1", + "--proxy-config", + "p.yaml", + ]; + let from_flag = parse_proxy_set(&[&base[..], &["--upstream-password", "flag-pw"]].concat()); + assert_eq!(from_flag.upstream_password.as_deref(), Some("flag-pw")); + + std::env::set_var("GUEPARD_TENET_UPSTREAM_PASSWORD", "env-pw"); + let from_env = parse_proxy_set(&base); + std::env::remove_var("GUEPARD_TENET_UPSTREAM_PASSWORD"); + assert_eq!(from_env.upstream_password.as_deref(), Some("env-pw")); + + assert_eq!(parse_proxy_set(&base).upstream_password, None); + } + + #[test] + fn only_a_pending_status_is_pending() { + assert!(is_pending(Some("pending"))); + assert!(!is_pending(Some("running"))); + assert!(!is_pending(None)); + } use crate::application::dto::tenet::TenetDeployRequest; use std::fs; @@ -298,6 +370,7 @@ mod tests { host: Some("10.0.0.2".into()), proxy_port: Some(6544), api_port: Some(3010), + status: None, }; let lines = tenet_deploy_hint_lines(&resp, Some("10.0.0.2")); assert_eq!(lines.len(), 2); @@ -316,6 +389,7 @@ mod tests { host: None, proxy_port: Some(6544), api_port: None, + status: None, }; assert!(tenet_deploy_hint_lines(&resp, None).is_empty()); } @@ -330,6 +404,7 @@ mod tests { host: None, proxy_port: Some(6544), api_port: Some(3010), + status: None, }; let lines = tenet_deploy_hint_lines(&resp, Some("44.239.18.139")); assert_eq!(lines.len(), 2); @@ -347,6 +422,7 @@ mod tests { host: None, proxy_port: Some(6544), api_port: None, + status: None, }; let lines = tenet_deploy_hint_lines(&resp, Some("10.0.4.20")); assert_eq!(lines.len(), 1); @@ -386,6 +462,7 @@ mod tests { config_yaml: yaml, proxy_port: None, api_port: None, + upstream_password: None, }; let j = serde_json::to_value(&body).unwrap(); assert_eq!( diff --git a/src/application/dto/deploy.rs b/src/application/dto/deploy.rs index 72b0d9f..8b5d286 100644 --- a/src/application/dto/deploy.rs +++ b/src/application/dto/deploy.rs @@ -20,6 +20,8 @@ pub struct CreateDeploymentRequest { pub proxy_yaml: Option, #[serde(skip_serializing_if = "Option::is_none")] pub masking_salt: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub upstream_password: Option, } #[derive(Serialize, Deserialize, Debug)] diff --git a/src/application/dto/tenet.rs b/src/application/dto/tenet.rs index ad8023f..5ab396f 100644 --- a/src/application/dto/tenet.rs +++ b/src/application/dto/tenet.rs @@ -15,6 +15,8 @@ pub struct TenetDeployRequest { pub proxy_port: Option, #[serde(skip_serializing_if = "Option::is_none")] pub api_port: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub upstream_password: Option, } #[derive(Debug, Clone, Deserialize, Serialize)] @@ -29,6 +31,9 @@ pub struct TenetDeployResponse { pub proxy_port: Option, #[serde(default)] pub api_port: Option, + /// "pending" when the API answered before the proxy was running. + #[serde(default)] + pub status: Option, } #[cfg(test)] @@ -47,6 +52,7 @@ mod tests { config_yaml: "x: 1".to_string(), proxy_port: None, api_port: None, + upstream_password: None, }; let v = serde_json::to_value(&r).unwrap(); assert!(v.get("proxy_port").is_none()); @@ -54,6 +60,33 @@ mod tests { assert_eq!(v.get("tenant_id").unwrap(), "t1"); } + #[test] + fn upstream_password_is_sent_only_when_set() { + let unset = TenetProxyYamlSetRequest { + config_yaml: "x: 1".to_string(), + upstream_password: None, + }; + assert!(serde_json::to_value(&unset) + .unwrap() + .get("upstream_password") + .is_none()); + let set = TenetProxyYamlSetRequest { + config_yaml: "x: 1".to_string(), + upstream_password: Some("pw".to_string()), + }; + assert_eq!( + serde_json::to_value(&set).unwrap()["upstream_password"], + "pw" + ); + } + + #[test] + fn deploy_response_reads_a_pending_status() { + let j = r#"{"job_id":"j","eval_id":"e","alloc_id":"","node_id":"","proxy_port":31000,"status":"pending"}"#; + let r: TenetDeployResponse = serde_json::from_str(j).unwrap(); + assert_eq!(r.status.as_deref(), Some("pending")); + } + #[test] fn deploy_request_json_includes_ports_when_set() { let r = TenetDeployRequest { @@ -66,6 +99,7 @@ mod tests { config_yaml: "rules: []".to_string(), proxy_port: Some(6544), api_port: Some(3010), + upstream_password: None, }; let v = serde_json::to_value(&r).unwrap(); assert_eq!(v.get("proxy_port").and_then(|x| x.as_u64()), Some(6544)); @@ -94,10 +128,15 @@ mod tests { #[derive(Debug, Clone, Serialize)] pub struct TenetProxyYamlSetRequest { pub config_yaml: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub upstream_password: Option, } #[derive(Debug, Clone, Deserialize, Serialize, Default)] pub struct TenetLifecycleResponse { #[serde(default)] pub message: Option, + /// "pending" when the API answered before the proxy was running again. + #[serde(default)] + pub status: Option, } diff --git a/src/application/services/deploy.rs b/src/application/services/deploy.rs index e81e796..292961b 100644 --- a/src/application/services/deploy.rs +++ b/src/application/services/deploy.rs @@ -429,6 +429,7 @@ mod tests { masked: None, proxy_yaml: None, masking_salt: None, + upstream_password: None, }; let r1 = create_deployment_with_deps(create_req, &config, &auth).await; assert!(r1.is_err()); diff --git a/src/application/services/tenet.rs b/src/application/services/tenet.rs index 7b1185e..97e8116 100644 --- a/src/application/services/tenet.rs +++ b/src/application/services/tenet.rs @@ -20,6 +20,11 @@ impl TenetAuthProvider for DefaultTenetAuthProvider { } } +/// 202: the API registered the change but answered before the proxy was running again. +fn is_accepted(status: StatusCode) -> bool { + status == StatusCode::OK || status == StatusCode::ACCEPTED +} + async fn read_error_body(response: reqwest::Response) -> String { response .text() @@ -46,7 +51,7 @@ pub async fn deploy_tenet_with_deps( .map_err(TenetError::RequestFailed)?; match response.status() { - StatusCode::OK => response + status if is_accepted(status) => response .json::() .await .map_err(|e| TenetError::ParseError(e.to_string())), @@ -135,7 +140,7 @@ async fn lifecycle_post( .map_err(TenetError::RequestFailed)?; match response.status() { - StatusCode::OK => { + status if is_accepted(status) => { let text = response .text() .await @@ -147,6 +152,7 @@ async fn lifecycle_post( Ok(v) => Ok(v), Err(_) => Ok(TenetLifecycleResponse { message: Some(text), + status: None, }), } } @@ -200,6 +206,7 @@ pub async fn set_proxy_yaml_with_deps( job_id: &str, yaml: &str, apply: bool, + upstream_password: Option<&str>, config: &Config, auth_provider: &A, ) -> Result { @@ -213,6 +220,7 @@ pub async fn set_proxy_yaml_with_deps( ); let body = TenetProxyYamlSetRequest { config_yaml: yaml.to_string(), + upstream_password: upstream_password.map(str::to_string), }; let response = client .put(url) @@ -224,7 +232,7 @@ pub async fn set_proxy_yaml_with_deps( .map_err(TenetError::RequestFailed)?; match response.status() { - StatusCode::OK => { + status if is_accepted(status) => { let text = response .text() .await @@ -236,6 +244,7 @@ pub async fn set_proxy_yaml_with_deps( Ok(v) => Ok(v), Err(_) => Ok(TenetLifecycleResponse { message: Some(text), + status: None, }), } } @@ -253,16 +262,25 @@ pub async fn set_proxy_yaml( job_id: &str, yaml: &str, apply: bool, + upstream_password: Option<&str>, config: &Config, ) -> Result { let auth = DefaultTenetAuthProvider; - set_proxy_yaml_with_deps(job_id, yaml, apply, config, &auth).await + set_proxy_yaml_with_deps(job_id, yaml, apply, upstream_password, config, &auth).await } #[cfg(test)] mod tests { use super::*; + #[test] + fn a_pending_202_counts_as_success() { + assert!(is_accepted(StatusCode::OK)); + assert!(is_accepted(StatusCode::ACCEPTED)); + assert!(!is_accepted(StatusCode::BAD_GATEWAY)); + assert!(!is_accepted(StatusCode::NO_CONTENT)); + } + #[tokio::test] async fn deploy_session_error() { let config = Config { @@ -288,6 +306,7 @@ mod tests { config_yaml: "x: 1".to_string(), proxy_port: None, api_port: None, + upstream_password: None, }; let r = deploy_tenet_with_deps(&body, &config, &auth).await; assert!(matches!(r.unwrap_err(), TenetError::SessionError(_))); @@ -314,6 +333,7 @@ mod tests { config_yaml: "x".to_string(), proxy_port: None, api_port: None, + upstream_password: None, }; assert!(deploy_tenet_with_deps(&body, &config, &auth).await.is_err()); assert!(start_tenet_with_deps("job", &config, &auth).await.is_err()); @@ -323,7 +343,7 @@ mod tests { .await .is_err()); assert!( - set_proxy_yaml_with_deps("job", "a: 1", true, &config, &auth) + set_proxy_yaml_with_deps("job", "a: 1", true, None, &config, &auth) .await .is_err() ); diff --git a/src/structure.rs b/src/structure.rs index 73e6c8e..794c4dc 100644 --- a/src/structure.rs +++ b/src/structure.rs @@ -557,6 +557,10 @@ pub struct DeployArgs { /// Tenet masking salt (auto-generated by API if omitted) #[arg(long, requires = "masked")] pub masking_salt: Option, + /// Tenet's own database password when proxy.yaml uses auth (password_env: TENET_UPSTREAM_PASSWORD). + /// Stored in the proxy's Nomad Variable, never in proxy.yaml. + #[arg(long, env = "GUEPARD_TENET_UPSTREAM_PASSWORD", hide_env_values = true)] + pub upstream_password: Option, } #[derive(Args, Debug)] @@ -891,6 +895,10 @@ pub struct TenetDeployCliArgs { /// Address shown in hints / where clients connect to Tenet (VPC or node IP, e.g. 10.0.4.20), not necessarily the upstream DB host. #[arg(long)] pub client_host: Option, + /// Tenet's own database password when proxy.yaml uses auth (password_env: TENET_UPSTREAM_PASSWORD). + /// Stored in the proxy's Nomad Variable, never in proxy.yaml. + #[arg(long, env = "GUEPARD_TENET_UPSTREAM_PASSWORD", hide_env_values = true)] + pub upstream_password: Option, } #[derive(Args, Debug)] @@ -919,6 +927,10 @@ pub struct TenetProxySetArgs { value_parser = clap::builder::BoolishValueParser::new(), )] pub apply: Option, + /// Tenet's own database password when proxy.yaml uses auth (password_env: TENET_UPSTREAM_PASSWORD). + /// Stored in the proxy's Nomad Variable, never in proxy.yaml. + #[arg(long, env = "GUEPARD_TENET_UPSTREAM_PASSWORD", hide_env_values = true)] + pub upstream_password: Option, } // Additional structs for original API compatibility From dc4da46a1dc2c48fd4adf95b2317e7cf243339c4 Mon Sep 17 00:00:00 2001 From: Mohamed Aziz Ktata Date: Thu, 5 Nov 2026 14:43:59 +0100 Subject: [PATCH 5/7] refactor(tenet): drop --upstream-password from masked deploy and proxy set The API now supplies Tenet's upstream password itself when auth.upstream.user is one of the deployment's database users, which it created and whose passwords it holds. The flag stays only on a standalone `tenet deploy`, whose upstream is not a Guepard deployment. --- CHANGELOG.md | 2 +- docs/documentation/tenet.md | 26 ++++++----- src/application/commands/deploy.rs | 7 --- src/application/commands/tenet.rs | 73 ++++++++++++++++++++---------- src/application/dto/deploy.rs | 2 - src/application/dto/tenet.rs | 16 +++++-- src/application/services/deploy.rs | 1 - src/application/services/tenet.rs | 7 +-- src/structure.rs | 9 +--- 9 files changed, 80 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5b433a..85e8be9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to Guepard CLI will be documented in this file. ## Unreleased ### Features -- **Tenet `auth`**: `--upstream-password` (or `GUEPARD_TENET_UPSTREAM_PASSWORD`) on `deploy --masked`, `tenet deploy` and `tenet proxy set` sends Tenet's own database password separately from `proxy.yaml` +- **Tenet `auth`**: name one of the deployment's database users as `auth.upstream.user` and the API supplies its password, for `deploy --masked` and `tenet proxy set` alike; a standalone `tenet deploy` takes it with `--upstream-password` (or `GUEPARD_TENET_UPSTREAM_PASSWORD`) ### Fixes - **Masked deploy**: waits for `masked_status: ready` instead of returning as soon as a Tenet port exists diff --git a/docs/documentation/tenet.md b/docs/documentation/tenet.md index f6cacbc..c6eaba4 100644 --- a/docs/documentation/tenet.md +++ b/docs/documentation/tenet.md @@ -156,12 +156,13 @@ The `custom-wasm` transformer is removed. Columns that used it fall back to the `table:` is not enforced: a rule masks its column in every result set, not only in the named table. The proxy logs this as a warning at startup. -#### Tenet's own login (`auth`) and `--upstream-password` +#### Tenet's own login (`auth`) With `auth:`, clients sign in to Tenet with Tenet's own users, and Tenet signs in to the -database with one account of its own. Its password never goes in `proxy.yaml` (the API refuses -an inline `auth.upstream.password` with 400): point Tenet at an environment variable and send the -password separately. +database with one account of its own. Name one of the deployment's database users as that +account: the user you deployed with (`-u`, default `guepard`) or the admin (`guepard-admin`). +The API created both and already holds their passwords, so it gives Tenet the right one; you send +no password. ```yaml auth: @@ -169,19 +170,22 @@ auth: - name: dev password: "SCRAM-SHA-256$4096:..." # a verifier, as PostgreSQL stores it upstream: - user: app_owner + user: guepard # a database user of this deployment password_env: TENET_UPSTREAM_PASSWORD ``` ```bash -export GUEPARD_TENET_UPSTREAM_PASSWORD='' # or --upstream-password -guepard deploy ... --masked --proxy-config ./proxy.yaml # new masked deployment -guepard tenet proxy set --proxy-config ./proxy.yaml # existing proxy +guepard deploy ... -u guepard -w '' --masked --proxy-config ./proxy.yaml +guepard tenet proxy set --proxy-config ./proxy.yaml # an existing masked deployment ``` -The API keeps the password in the proxy's Nomad Variable and hands it to Tenet as -`TENET_UPSTREAM_PASSWORD`; it is not in the job definition, its history, or `tenet proxy get`. -Set it once: later `proxy set` calls without it keep the stored one. +The password never goes in `proxy.yaml`: the API refuses an inline `auth.upstream.password`, and an +`upstream.user` that is not one of the deployment's users, with 400. It keeps the password in the +proxy's Nomad Variable and hands it to Tenet as `TENET_UPSTREAM_PASSWORD`; it is not in the job +definition, its history, or `tenet proxy get`. + +Only a standalone `guepard tenet deploy`, pointed at an upstream that is not a Guepard deployment, +needs the password from you: `--upstream-password`, or `GUEPARD_TENET_UPSTREAM_PASSWORD`. #### When a change takes a while to apply diff --git a/src/application/commands/deploy.rs b/src/application/commands/deploy.rs index 8eedea2..9e07322 100644 --- a/src/application/commands/deploy.rs +++ b/src/application/commands/deploy.rs @@ -450,12 +450,6 @@ async fn create_deployment( masked: if args.masked { Some(true) } else { None }, proxy_yaml, masking_salt: args.masking_salt.clone(), - // Only for a masked deploy: the env var may be set for other commands. - upstream_password: if args.masked { - args.upstream_password.clone() - } else { - None - }, }; let mut deployment = deploy::create_deployment(request, config).await?; @@ -1550,7 +1544,6 @@ async fn interactive_deploy(config: &Config) -> Result<()> { masked: None, proxy_yaml: None, masking_salt: None, - upstream_password: None, }; let deployment = deploy::create_deployment(request, config).await?; diff --git a/src/application/commands/tenet.rs b/src/application/commands/tenet.rs index b337fbf..0ee6710 100644 --- a/src/application/commands/tenet.rs +++ b/src/application/commands/tenet.rs @@ -280,14 +280,7 @@ async fn proxy_set( )) })?; let apply = s.apply.unwrap_or(true); - let resp = tenet::set_proxy_yaml( - &s.job_id, - &yaml, - apply, - s.upstream_password.as_deref(), - config, - ) - .await?; + let resp = tenet::set_proxy_yaml(&s.job_id, &yaml, apply, config).await?; let pending = is_pending(resp.status.as_deref()); if output_format == OutputFormat::Json { @@ -314,41 +307,75 @@ async fn proxy_set( mod tests { use super::*; - fn parse_proxy_set(args: &[&str]) -> crate::structure::TenetProxySetArgs { + fn parse_tenet_deploy(args: &[&str]) -> crate::structure::TenetDeployCliArgs { use clap::Parser; let cli = crate::structure::CLI::try_parse_from(args).expect("parses"); match cli.sub_commands { crate::structure::SubCommand::Tenet(t) => match t.command { - crate::structure::TenetCommand::Proxy(p) => match p.action { - crate::structure::TenetProxyAction::Set(s) => s, - other => panic!("not proxy set: {:?}", other), - }, - other => panic!("not tenet proxy: {:?}", other), + crate::structure::TenetCommand::Deploy(d) => d, + other => panic!("not tenet deploy: {:?}", other), }, other => panic!("not tenet: {:?}", other), } } #[test] - fn proxy_set_takes_upstream_password_from_flag_or_env() { + fn standalone_tenet_deploy_takes_upstream_password_from_flag_or_env() { let base = [ "guepard", "tenet", - "proxy", - "set", - "job-1", - "--proxy-config", - "p.yaml", + "deploy", + "--tenant-id", + "t1", + "--upstream-host", + "10.0.0.5", + "--upstream-port", + "5432", + "--masking-salt", + "s", + "--config-yaml", + "rules: []", ]; - let from_flag = parse_proxy_set(&[&base[..], &["--upstream-password", "flag-pw"]].concat()); + let from_flag = + parse_tenet_deploy(&[&base[..], &["--upstream-password", "flag-pw"]].concat()); assert_eq!(from_flag.upstream_password.as_deref(), Some("flag-pw")); std::env::set_var("GUEPARD_TENET_UPSTREAM_PASSWORD", "env-pw"); - let from_env = parse_proxy_set(&base); + let from_env = parse_tenet_deploy(&base); std::env::remove_var("GUEPARD_TENET_UPSTREAM_PASSWORD"); assert_eq!(from_env.upstream_password.as_deref(), Some("env-pw")); + } - assert_eq!(parse_proxy_set(&base).upstream_password, None); + #[test] + fn proxy_set_and_masked_deploy_take_no_upstream_password() { + use clap::Parser; + // The API supplies the deployment user's password for these two. + for args in [ + &[ + "guepard", + "tenet", + "proxy", + "set", + "job-1", + "--proxy-config", + "p.yaml", + "--upstream-password", + "x", + ][..], + &[ + "guepard", + "deploy", + "--masked", + "--proxy-config", + "p.yaml", + "--upstream-password", + "x", + ][..], + ] { + let without_flag = &args[..args.len() - 2]; + assert!(crate::structure::CLI::try_parse_from(without_flag).is_ok()); + assert!(crate::structure::CLI::try_parse_from(args).is_err()); + } } #[test] diff --git a/src/application/dto/deploy.rs b/src/application/dto/deploy.rs index 8b5d286..72b0d9f 100644 --- a/src/application/dto/deploy.rs +++ b/src/application/dto/deploy.rs @@ -20,8 +20,6 @@ pub struct CreateDeploymentRequest { pub proxy_yaml: Option, #[serde(skip_serializing_if = "Option::is_none")] pub masking_salt: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub upstream_password: Option, } #[derive(Serialize, Deserialize, Debug)] diff --git a/src/application/dto/tenet.rs b/src/application/dto/tenet.rs index 5ab396f..19b7e08 100644 --- a/src/application/dto/tenet.rs +++ b/src/application/dto/tenet.rs @@ -62,17 +62,25 @@ mod tests { #[test] fn upstream_password_is_sent_only_when_set() { - let unset = TenetProxyYamlSetRequest { + let unset = TenetDeployRequest { + tenant_id: "t1".to_string(), + compute_job_id: None, + upstream_host: "h".to_string(), + upstream_port: 5432, + masking_salt: "s".to_string(), + config_dir: None, config_yaml: "x: 1".to_string(), + proxy_port: None, + api_port: None, upstream_password: None, }; assert!(serde_json::to_value(&unset) .unwrap() .get("upstream_password") .is_none()); - let set = TenetProxyYamlSetRequest { - config_yaml: "x: 1".to_string(), + let set = TenetDeployRequest { upstream_password: Some("pw".to_string()), + ..unset }; assert_eq!( serde_json::to_value(&set).unwrap()["upstream_password"], @@ -128,8 +136,6 @@ mod tests { #[derive(Debug, Clone, Serialize)] pub struct TenetProxyYamlSetRequest { pub config_yaml: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub upstream_password: Option, } #[derive(Debug, Clone, Deserialize, Serialize, Default)] diff --git a/src/application/services/deploy.rs b/src/application/services/deploy.rs index 292961b..e81e796 100644 --- a/src/application/services/deploy.rs +++ b/src/application/services/deploy.rs @@ -429,7 +429,6 @@ mod tests { masked: None, proxy_yaml: None, masking_salt: None, - upstream_password: None, }; let r1 = create_deployment_with_deps(create_req, &config, &auth).await; assert!(r1.is_err()); diff --git a/src/application/services/tenet.rs b/src/application/services/tenet.rs index 97e8116..498f741 100644 --- a/src/application/services/tenet.rs +++ b/src/application/services/tenet.rs @@ -206,7 +206,6 @@ pub async fn set_proxy_yaml_with_deps( job_id: &str, yaml: &str, apply: bool, - upstream_password: Option<&str>, config: &Config, auth_provider: &A, ) -> Result { @@ -220,7 +219,6 @@ pub async fn set_proxy_yaml_with_deps( ); let body = TenetProxyYamlSetRequest { config_yaml: yaml.to_string(), - upstream_password: upstream_password.map(str::to_string), }; let response = client .put(url) @@ -262,11 +260,10 @@ pub async fn set_proxy_yaml( job_id: &str, yaml: &str, apply: bool, - upstream_password: Option<&str>, config: &Config, ) -> Result { let auth = DefaultTenetAuthProvider; - set_proxy_yaml_with_deps(job_id, yaml, apply, upstream_password, config, &auth).await + set_proxy_yaml_with_deps(job_id, yaml, apply, config, &auth).await } #[cfg(test)] @@ -343,7 +340,7 @@ mod tests { .await .is_err()); assert!( - set_proxy_yaml_with_deps("job", "a: 1", true, None, &config, &auth) + set_proxy_yaml_with_deps("job", "a: 1", true, &config, &auth) .await .is_err() ); diff --git a/src/structure.rs b/src/structure.rs index 794c4dc..caf96d1 100644 --- a/src/structure.rs +++ b/src/structure.rs @@ -557,10 +557,6 @@ pub struct DeployArgs { /// Tenet masking salt (auto-generated by API if omitted) #[arg(long, requires = "masked")] pub masking_salt: Option, - /// Tenet's own database password when proxy.yaml uses auth (password_env: TENET_UPSTREAM_PASSWORD). - /// Stored in the proxy's Nomad Variable, never in proxy.yaml. - #[arg(long, env = "GUEPARD_TENET_UPSTREAM_PASSWORD", hide_env_values = true)] - pub upstream_password: Option, } #[derive(Args, Debug)] @@ -896,6 +892,7 @@ pub struct TenetDeployCliArgs { #[arg(long)] pub client_host: Option, /// Tenet's own database password when proxy.yaml uses auth (password_env: TENET_UPSTREAM_PASSWORD). + /// Needed here because this upstream is not a Guepard deployment whose users the API knows. /// Stored in the proxy's Nomad Variable, never in proxy.yaml. #[arg(long, env = "GUEPARD_TENET_UPSTREAM_PASSWORD", hide_env_values = true)] pub upstream_password: Option, @@ -927,10 +924,6 @@ pub struct TenetProxySetArgs { value_parser = clap::builder::BoolishValueParser::new(), )] pub apply: Option, - /// Tenet's own database password when proxy.yaml uses auth (password_env: TENET_UPSTREAM_PASSWORD). - /// Stored in the proxy's Nomad Variable, never in proxy.yaml. - #[arg(long, env = "GUEPARD_TENET_UPSTREAM_PASSWORD", hide_env_values = true)] - pub upstream_password: Option, } // Additional structs for original API compatibility From f3a72ccef26f8f59c903c0ab711d515d3dbb4faa Mon Sep 17 00:00:00 2001 From: Mohamed Aziz Ktata Date: Thu, 5 Nov 2026 16:01:47 +0100 Subject: [PATCH 6/7] fix(tenet): print the API's reason on a Tenet error, not raw JSON Tenet commands printed the whole error body, e.g. Status 400: {"message":"Nomad error","status":400,"body":"..."}. They now print the API's message, and for a Nomad failure the reason it carries, as deploy errors already do. --- src/application/services/tenet.rs | 42 ++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/application/services/tenet.rs b/src/application/services/tenet.rs index 498f741..f51f0c6 100644 --- a/src/application/services/tenet.rs +++ b/src/application/services/tenet.rs @@ -25,6 +25,22 @@ fn is_accepted(status: StatusCode) -> bool { status == StatusCode::OK || status == StatusCode::ACCEPTED } +/// The API's own reason from an error body (`{"message": ...}`), else the body as it came. +/// A Nomad failure carries the reason in `body` under `message: "Nomad error"`. +fn error_detail(body: &str) -> String { + let Ok(json) = serde_json::from_str::(body) else { + return body.to_string(); + }; + match json.get("message").and_then(|m| m.as_str()) { + Some("Nomad error") => match json.get("body").and_then(|b| b.as_str()) { + Some(reason) => format!("Nomad: {}", reason), + None => body.to_string(), + }, + Some(message) => message.to_string(), + None => body.to_string(), + } +} + async fn read_error_body(response: reqwest::Response) -> String { response .text() @@ -59,7 +75,8 @@ pub async fn deploy_tenet_with_deps( let text = read_error_body(response).await; Err(TenetError::Unexpected(format!( "Status {}: {}", - status, text + status, + error_detail(&text) ))) } } @@ -160,7 +177,8 @@ async fn lifecycle_post( let text = read_error_body(response).await; Err(TenetError::Unexpected(format!( "Status {}: {}", - status, text + status, + error_detail(&text) ))) } } @@ -191,7 +209,8 @@ pub async fn get_proxy_yaml_with_deps( let text = read_error_body(response).await; Err(TenetError::Unexpected(format!( "Status {}: {}", - status, text + status, + error_detail(&text) ))) } } @@ -250,7 +269,8 @@ pub async fn set_proxy_yaml_with_deps( let text = read_error_body(response).await; Err(TenetError::Unexpected(format!( "Status {}: {}", - status, text + status, + error_detail(&text) ))) } } @@ -270,6 +290,20 @@ pub async fn set_proxy_yaml( mod tests { use super::*; + #[test] + fn errors_print_the_api_reason() { + assert_eq!( + error_detail(r#"{"message":"auth.upstream.user \"stranger\" has no password"}"#), + r#"auth.upstream.user "stranger" has no password"# + ); + assert_eq!( + error_detail(r#"{"message":"Nomad error","status":502,"body":"no leader"}"#), + "Nomad: no leader" + ); + assert_eq!(error_detail("plain text"), "plain text"); + assert_eq!(error_detail(r#"{"other":1}"#), r#"{"other":1}"#); + } + #[test] fn a_pending_202_counts_as_success() { assert!(is_accepted(StatusCode::OK)); From 89476a6ef9d163823833c651fbacdc8a3d3956c1 Mon Sep 17 00:00:00 2001 From: Mohamed Aziz Ktata Date: Thu, 5 Nov 2026 17:42:26 +0100 Subject: [PATCH 7/7] docs(tenet): pattern rules and LIKE refusal in behaviour changes Two changes customers will notice were missing from the list. The published Tenet matches rule columns literally, so a rule such as column: "*phone*" left that column in clear; the next release applies it. Measured on the published image: the real phone number came back under "*phone*" and was masked under column: phone. LIKE, regex, SIMILAR TO, BETWEEN and range filters on masked columns are now refused; the wording follows refuse_unsupported_predicates in guepard-tenet's config.rs. --- CHANGELOG.md | 2 +- docs/documentation/tenet.md | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85e8be9..4642ed6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ All notable changes to Guepard CLI will be documented in this file. - **Tenet commands**: a proxy that is still starting (API answer 202, `status: pending`) is reported as such instead of as an error ### Documentation -- **Tenet guide**: [behaviour changes in the next Tenet release](docs/documentation/tenet.md#behaviour-changes-in-the-next-tenet-release). Writes through a masked port are refused by default (`block_writes`), and masked values change for the same salt (`seed_derivation: siphash`); the guide shows how to keep the old behaviour, and why allowing writes needs `strict_masking: true`. Every sample `proxy.yaml` under `scripts/` was checked against that release and loads unchanged. +- **Tenet guide**: [behaviour changes in the next Tenet release](docs/documentation/tenet.md#behaviour-changes-in-the-next-tenet-release). Writes through a masked port are refused by default (`block_writes`), masked values change for the same salt (`seed_derivation: siphash`), rules with a column pattern (`"*phone*"`) now apply where the previous release ignored them, and `LIKE`/range filters on masked columns are refused; the guide shows how to keep the old behaviour, and why allowing writes needs `strict_masking: true`. Every sample `proxy.yaml` under `scripts/` was checked against that release and loads unchanged. ## v0.29.10 (2026-06-08) diff --git a/docs/documentation/tenet.md b/docs/documentation/tenet.md index c6eaba4..52b7524 100644 --- a/docs/documentation/tenet.md +++ b/docs/documentation/tenet.md @@ -111,13 +111,15 @@ This repo ships small samples under **`scripts/`**: ### Behaviour changes in the next Tenet release The next Tenet (guepard-tenet branch `feature/performance-tuning`, not yet on its `main`) reads -every `proxy.yaml` shipped under `scripts/` unchanged, but two defaults change what clients of a -masked port see. Both can be set back in `proxy.yaml`, then pushed with `guepard tenet proxy set`. +every `proxy.yaml` shipped under `scripts/` unchanged, but these changes affect what clients of a +masked port see. Settings go in `proxy.yaml`, pushed with `guepard tenet proxy set`. | Change | What a client notices | Keep the old behaviour | |--------|-----------------------|------------------------| | **Writes are refused** on a masked connection (`block_writes`, on by default) | `INSERT` / `UPDATE` / `DELETE` through the Tenet port fail with `UPDATE is not permitted on a masked connection while block_writes is on…`. Reads are unchanged. Writing directly to Postgres still works. | `block_writes: false` **together with `strict_masking: true`** ([see below](#allowing-writes-safely)). | | **Masked values change** for the same salt (`seed_derivation` now defaults to `siphash`, was `xxhash64`) | Every deterministic masked value (for example a `hash` column) differs from what the previous release returned. | `seed_derivation: xxhash64`, while anything that stored old masked values is migrated. | +| **Rules with a column pattern now apply** (for example `column: "*phone*"`) | The previous release matched rule columns literally, so a pattern rule did not apply: a `phone` column under `column: "*phone*"` came back in clear. It is masked now. | None needed; this is the rule doing what it says. Check your `proxy.yaml` for patterns to see which columns start being masked. | +| **`LIKE` and range filters on a masked column are refused** (`LIKE`, regex, `SIMILAR TO`, `BETWEEN`, `<`, `>`; `refuse_unsupported_predicates`, on by default) | The query fails with `LIKE on a masked column is not permitted…`. The previous release ran these filters on the real values, so a client could learn them one guess at a time. Filter with `=`, `<>` or `IN` on a value the proxy showed instead. | `refuse_unsupported_predicates: false` answers them again, on real values, with a `NOTICE`: it reopens that leak. | Other additions, all opt-in (see the guepard-tenet docs on that branch):