Skip to content
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to Guepard CLI will be documented in this file.

## Unreleased

### Features
- **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
- **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`), 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)

### Features
Expand Down
90 changes: 90 additions & 0 deletions docs/documentation/tenet.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,94 @@ 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 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):

- **`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. 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
table. The proxy logs this as a warning at startup.

#### 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. 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:
users:
- name: dev
password: "SCRAM-SHA-256$4096:..." # a verifier, as PostgreSQL stores it
upstream:
user: guepard # a database user of this deployment
password_env: TENET_UPSTREAM_PASSWORD
```

```bash
guepard deploy ... -u guepard -w '<password>' --masked --proxy-config ./proxy.yaml
guepard tenet proxy set <job_id> --proxy-config ./proxy.yaml # an existing masked deployment
```

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

`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 <id>` shows
`Masked status: ready` once both Tenet and the database behind it are running.

---

## Connecting with `psql`
Expand All @@ -134,6 +222,8 @@ psql "host=<client-host> port=<tenet-proxy-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` 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. |

---

Expand Down
104 changes: 104 additions & 0 deletions src/application/commands/tenet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ async fn resolve_postgres_host_for_hints(upstream_host: &str) -> Option<String>
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,
Expand Down Expand Up @@ -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?;
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -265,14 +281,19 @@ 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 pending = is_pending(resp.status.as_deref());

if output_format == OutputFormat::Json {
print_json(&serde_json::json!({
"job_id": s.job_id,
"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 {
Expand All @@ -285,6 +306,84 @@ async fn proxy_set(
#[cfg(test)]
mod tests {
use super::*;

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::Deploy(d) => d,
other => panic!("not tenet deploy: {:?}", other),
},
other => panic!("not tenet: {:?}", other),
}
}

#[test]
fn standalone_tenet_deploy_takes_upstream_password_from_flag_or_env() {
let base = [
"guepard",
"tenet",
"deploy",
"--tenant-id",
"t1",
"--upstream-host",
"10.0.0.5",
"--upstream-port",
"5432",
"--masking-salt",
"s",
"--config-yaml",
"rules: []",
];
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_tenet_deploy(&base);
std::env::remove_var("GUEPARD_TENET_UPSTREAM_PASSWORD");
assert_eq!(from_env.upstream_password.as_deref(), Some("env-pw"));
}

#[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]
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;

Expand All @@ -298,6 +397,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);
Expand All @@ -316,6 +416,7 @@ mod tests {
host: None,
proxy_port: Some(6544),
api_port: None,
status: None,
};
assert!(tenet_deploy_hint_lines(&resp, None).is_empty());
}
Expand All @@ -330,6 +431,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);
Expand All @@ -347,6 +449,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);
Expand Down Expand Up @@ -386,6 +489,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!(
Expand Down
Loading
Loading