workload-replay: harden workload anonymization#36745
Closed
jasonhernandez wants to merge 1 commit into
Closed
Conversation
The anonymizer scrubs identifiers and string literals from workload captures so they can be shared. Several gaps let sensitive data leak through or silently corrupted the output: - Connection and sink create_sql only had identifiers replaced, never literals. Those statements carry hostnames, usernames, regions, broker lists, bucket/path URLs, and topic names as string literals, all of which were emitted verbatim. Also anonymize literals for types and indexes for consistency. - The string-literal regex used a nested quantifier (`'(?:[^']*(?:'')?)*'`), a catastrophic-backtracking shape. Rewrote it as the linear `'(?:[^']|'')*'`. - Child sources looked up `child["schema"]`/`["database"]` directly in the mapping, crashing with KeyError on any builtin/uncaptured name. Use `.get` so unmapped names pass through, matching the query path. - Output defaulted to overwriting the input capture, destroying the original. Now require an explicit `-o` (use `-` for stdout) or the new `--in-place` flag. Add a `--verify` pass (on by default) that re-scans the anonymized output for whole-word survivals of original identifiers and for string literals that were not reduced to a `literal_N` placeholder, and refuses to write if any are found. Cluster create_sql is exempt from the literal check because its literals (SIZE, replication factor, AZs) are non-sensitive config that replay must preserve. This converts silent leaks into a hard failure, which is the property that matters for a privacy tool. This does not address the deeper, parser-level issues (case folding, word boundaries in the identifier regex, the global mapping collapsing duplicate column/table names, dollar-quoted strings, comments, numeric literals); those require resolving SQL with the Mz parser rather than text substitution, per the existing TODOs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 27, 2026
Contributor
Author
|
Superseded by #36803, which squashes this stack into a single PR against main. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
bin/mz-workload-anonymizescrubs identifiers and string literals from workload captures so they can be shared. While looking at it I found several gaps where sensitive data leaks through or the output is silently corrupted. This PR fixes the cheap, high-value ones and adds a fail-loud verification backstop. It deliberately does not attempt the parser-level rewrite (see "Out of scope").What changed
Privacy leaks
create_sqlonly had identifiers replaced, never literals — so hostnames, usernames, regions, broker lists, bucket/path URLs, and topic names were emitted verbatim. Types and indexes also get literal anonymization now, for consistency.Correctness / robustness
'(?:[^']*(?:'')?)*'had a nested quantifier (catastrophic-backtracking shape). Rewrote as the linear'(?:[^']|'')*'.child["schema"]/["database"]directly in the mapping, crashing on any builtin/uncaptured name. Now uses.get, matching the query path.Footgun
-o(-for stdout) or the new--in-placeflag.Fail-loud verification (
--verify, on by default)literal_Nplaceholder, and refuses to write if any are found.--no-verifyoverrides.create_sqlis exempt from the literal check: its literals (SIZE, replication factor, AZs) are non-sensitive config that replay must preserve.Out of scope (parser-level, tracked by existing TODOs)
These require resolving SQL with the Mz parser instead of text substitution, and are left for follow-up:
mappingcollapsing duplicate column/table names across schemas (distinct objects can map to one name).The
--verifypass is meant as the safety net for this residual risk: anything it can detect becomes a hard error rather than a silent leak.Testing
bin/fmtclean;ruff checkclean;py_compileclean.--in-place,--no-verifybypass, and that--verifycatches an intentionally-leaked literal.🤖 Generated with Claude Code