Repository navigation
fix(proxy): redact plaintext in logs unless built with log-plaintext #534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tobyhede
merged 8 commits into
main
from
tobyhede/proxy-release-builds-must-never-log-plaintext-whatever-the-log-level
Dec 3, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ea4f395
fix(proxy): redact plaintext in logs unless built with log-plaintext
tobyhede c08ddbc
test(proxy): drop the CS_ prefix from the log redaction container var…
tobyhede f7c0ea9
test(proxy): fail the log redaction test in CI when it would skip
tobyhede 816bab4
fix(proxy): redact the param plan and handler error warnings
tobyhede 4864637
fix(proxy): never log credentials or migrated record keys
tobyhede 841876e
test(proxy): force every log target to trace for the redaction test
tobyhede 33bd619
docs(changelog): order Unreleased sections and add review fixes
tobyhede 8c13347
fix(proxy): enforce redaction in release builds
tobyhede File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
packages/cipherstash-proxy-integration/src/log_redaction.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| //! A release build of Proxy must never log plaintext, whatever the log level. | ||
| //! | ||
| //! This test sends a distinctive value through Proxy and then reads the Proxy container's logs. | ||
| //! It needs a Proxy built without the `log-plaintext` feature, running in a container named by `PROXY_LOG_CONTAINER`, with structured logging and every log target at `trace`. | ||
| //! `mise run test:integration` sets that up for the main integration run, by setting `PROXY_LOG_FORCE_LEVEL=trace` for `tests/docker-compose.yml`. | ||
| //! The test checks that the startup warning lists every log target, which proves each one is at `debug` or `trace`. | ||
| //! Without `PROXY_LOG_CONTAINER` the test is skipped locally, because a Proxy started with `mise run proxy` includes `log-plaintext`. | ||
| //! In CI, where `CI` is set, a missing `PROXY_LOG_CONTAINER` fails the test instead, so the check cannot stop running unnoticed. | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::common::{connect_with_tls, random_id, PROXY}; | ||
| use std::process::Command; | ||
| use std::time::Duration; | ||
|
|
||
| const CONTAINER_ENV: &str = "PROXY_LOG_CONTAINER"; | ||
|
|
||
| fn container_logs(container: &str) -> String { | ||
| let output = Command::new("docker") | ||
| .args(["logs", container]) | ||
| .output() | ||
| .unwrap(); | ||
| assert!( | ||
| output.status.success(), | ||
| "docker logs {container} failed: {}", | ||
| String::from_utf8_lossy(&output.stderr) | ||
| ); | ||
|
|
||
| // Proxy logs to stdout, and docker keeps stderr separately | ||
| let mut logs = String::from_utf8_lossy(&output.stdout).into_owned(); | ||
| logs.push_str(&String::from_utf8_lossy(&output.stderr)); | ||
| logs | ||
| } | ||
|
|
||
| fn redacted_startup_targets(logs: &str) -> Option<Vec<String>> { | ||
| logs.lines().find_map(|line| { | ||
| let event: serde_json::Value = serde_json::from_str(line).ok()?; | ||
| let fields = &event["fields"]; | ||
| if event["target"] == "CONFIG" | ||
| && event["level"] == "WARN" | ||
| && fields["msg"] | ||
| .as_str()? | ||
| .starts_with("Debug or trace logging is enabled") | ||
| && fields["plaintext_logging"] == false | ||
| { | ||
| // tracing serializes a Debug field as a string in structured output. | ||
| serde_json::from_str(fields["targets"].as_str()?).ok() | ||
| } else { | ||
| None | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| #[test] | ||
| fn reads_verbose_targets_only_from_the_startup_warning() { | ||
| let logs = r#"{"target":"CONFIG","level":"WARN","fields":{"msg":"Debug or trace logging is enabled.","plaintext_logging":false,"targets":"[\"default\", \"MAPPER\"]"}} | ||
| {"target":"MIGRATE","level":"INFO","fields":{"msg":"Select"}}"#; | ||
|
|
||
| assert_eq!( | ||
| redacted_startup_targets(logs).unwrap(), | ||
| ["default", "MAPPER"] | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn release_build_logs_no_plaintext_at_trace() { | ||
| let Ok(container) = std::env::var(CONTAINER_ENV) else { | ||
| // A skip reports as a pass, so CI must never skip: the check would | ||
| // stop running without anyone noticing. | ||
| assert!( | ||
| std::env::var_os("CI").is_none(), | ||
| "{CONTAINER_ENV} must be set in CI; `mise run test:integration` sets it" | ||
| ); | ||
| println!("Skipping: set {CONTAINER_ENV} to the name of a Proxy container built without log-plaintext"); | ||
| return; | ||
| }; | ||
|
|
||
| // Other tests clear the table concurrently, so this test checks the logs, | ||
| // not the rows each query returns. | ||
| let client = connect_with_tls(*PROXY).await; | ||
|
|
||
| let canary = format!("log-canary-{}", uuid::Uuid::new_v4().simple()); | ||
|
|
||
| // Extended protocol, with bound parameters | ||
| let extended_id = random_id(); | ||
| client | ||
| .query( | ||
| "INSERT INTO encrypted (id, encrypted_text) VALUES ($1, $2)", | ||
| &[&extended_id, &canary], | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
| client | ||
| .query( | ||
| "SELECT encrypted_text FROM encrypted WHERE id = $1", | ||
| &[&extended_id], | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
| client | ||
| .query( | ||
| "SELECT id FROM encrypted WHERE encrypted_text = $1", | ||
| &[&canary], | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| // Simple protocol, with literals | ||
| let simple_id = random_id(); | ||
| client | ||
| .simple_query(&format!( | ||
| "INSERT INTO encrypted (id, encrypted_text) VALUES ({simple_id}, '{canary}')" | ||
| )) | ||
| .await | ||
| .unwrap(); | ||
| client | ||
| .simple_query(&format!( | ||
| "SELECT encrypted_text FROM encrypted WHERE id = {simple_id}" | ||
| )) | ||
| .await | ||
| .unwrap(); | ||
| client | ||
| .simple_query(&format!( | ||
| "SELECT encrypted_text FROM encrypted WHERE encrypted_text = '{canary}'" | ||
| )) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| // Give the container a moment to flush its log output | ||
| tokio::time::sleep(Duration::from_secs(2)).await; | ||
| let logs = container_logs(&container); | ||
|
|
||
| let targets = redacted_startup_targets(&logs) | ||
| .expect("expected a structured CONFIG startup warning with plaintext logging disabled"); | ||
| for target in cipherstash_proxy::log::targets::log_targets() { | ||
| assert!( | ||
| targets.iter().any(|name| name == target), | ||
| "missing verbose target {target}" | ||
| ); | ||
| } | ||
| assert!( | ||
| logs.contains("Rewrite Bind") && logs.contains("Rewrite Query"), | ||
| "expected the mapper debug events in the {container} logs" | ||
| ); | ||
| assert!( | ||
| !logs.contains(&canary), | ||
| "{container} logged a plaintext value" | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.