[FR] 支持对mongo请求的参数脱敏
Search before asking
- [x] I had searched in the issues and found no similar feature requirement.
Description
目前mongo请求还不支持脱敏,查询条件里如果带了敏感信息,会被存到 clickhouse 中,存在数据泄露风险。
Use case
No response
Related issues
No response
Are you willing to submit a PR?
- [ ] Yes I am willing to submit a PR!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Hi! I'd like to work on this issue.
Reading the code, the query condition already reaches us parsed: agent/src/flow_generator/protocol_logs/sql/mongo.rs decodes the payload into a bson::Document and then calls .to_string() on it to fill request_resource. So an obfuscator can walk that document and replace values while keeping field names — no re-parsing and no regex over the serialized string. The obfuscate_enabled_protocols bitmap already accepts "MongoDB" as a config value, so this can follow the same opt-in model as the SQL and HTTP paths, defaulting to off.
Three things I'd like your call on before writing code:
- Placeholder for replaced values —
?, as the SQL obfuscator uses, or something else? - Nesting — walk nested documents and arrays recursively, replacing leaf values only?
- Query operators (
$gt,$in, ...) — leave them as-is, or treat them as ordinary field names?
If the direction is right, I'd add a mongo_obfuscate module alongside sql_obfuscate with unit tests covering the document walker, and wire it at the four places in mongo.rs that serialize a document. Happy to adjust the split if you'd prefer it elsewhere.
Hi! I'd like to work on this issue.
Reading the code, the query condition already reaches us parsed:
agent/src/flow_generator/protocol_logs/sql/mongo.rsdecodes the payload into abson::Documentand then calls.to_string()on it to fillrequest_resource. So an obfuscator can walk that document and replace values while keeping field names — no re-parsing and no regex over the serialized string. Theobfuscate_enabled_protocolsbitmap already accepts"MongoDB"as a config value, so this can follow the same opt-in model as the SQL and HTTP paths, defaulting to off.Three things I'd like your call on before writing code:
- Placeholder for replaced values —
?, as the SQL obfuscator uses, or something else?- Nesting — walk nested documents and arrays recursively, replacing leaf values only?
- Query operators (
$gt,$in, ...) — leave them as-is, or treat them as ordinary field names?If the direction is right, I'd add a
mongo_obfuscatemodule alongsidesql_obfuscatewith unit tests covering the document walker, and wire it at the four places inmongo.rsthat serialize a document. Happy to adjust the split if you'd prefer it elsewhere.
- It is best to maintain consistency with SQL to keep the logic simpler.
- The implementation should incur minimal performance overhead, avoiding recursive traversal whenever possible. The data in the trace records should primarily indicate when an operation was performed on a specific piece of data within a document, what that operation was, and the outcome (success or failure, along with the time taken). Other information can be retrieved from logs or similar sources.
- Operators can remain as they are.