Skip to content
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

feature: hide client ip/name in querylog #575

Closed

Conversation

axelrindle
Copy link

@axelrindle axelrindle commented Jun 28, 2022

I'd like to hide the Client IP and Name in the querylog for privacy reasons.

  • Extend config
  • Fix tests
  • Implement for CSV etc. as well
  • Move logic to QueryLoggingResolver.writeLogResolve or LogEntry

@axelrindle axelrindle marked this pull request as ready for review June 28, 2022 13:42
@codecov
Copy link

codecov bot commented Jun 29, 2022

Codecov Report

Merging #575 (61175b7) into development (3009eec) will increase coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head 61175b7 differs from pull request most recent head 6751c15. Consider uploading reports for the commit 6751c15 to get more accurate results

@@               Coverage Diff               @@
##           development     #575       /-   ##
===============================================
  Coverage        92.74%   92.76%    0.02%     
===============================================
  Files               37       37              
  Lines             3251     3260        9     
===============================================
  Hits              3015     3024        9     
  Misses             170      170              
  Partials            66       66              
Impacted Files Coverage Δ
config/config.go 94.87% <ø> (ø)
querylog/database_writer.go 97.05% <100.00%> ( 0.23%) ⬆️
resolver/query_logging_resolver.go 100.00% <100.00%> (ø)
resolver/upstream_resolver.go 91.15% <0.00%> ( 0.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3009eec...6751c15. Read the comment docs.

@0xERR0R
Copy link
Owner

0xERR0R commented Jun 29, 2022

Thanks for your work! If I understand it right, "hideClient" is only used in databaseWriter (mysql and postgres), but not for CSV and console. I think, it would also make sense to hide client for all logging types, what do you think?

Maybe we can hide or obfuscate client/IP in QueryLoggingResolver.Resolve or LogEntry?

@0xERR0R 0xERR0R added the 🔨 enhancement New feature or request label Jun 29, 2022
@0xERR0R 0xERR0R added this to the 0.20 milestone Jun 29, 2022
@axelrindle
Copy link
Author

Sounds good. I will try to implement this for CSV etc. as well.

Also moving the logic to a more central place is surely a good approach.

for logEntry := range r.logChan {
start := time.Now()

if r.hideClient {
logEntry.Request.ClientIP = emptyClientIP
logEntry.Request.ClientNames = emptyClientName
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid the variables and parsing the IP on each log, you can do:

logEntry.Request.ClientIP = net.IPv4zero
logEntry.Request.ClientNames = nil

@@ -517,6 517,7 @@ type QueryLogConfig struct {
LogRetentionDays uint64 `yaml:"logRetentionDays"`
CreationAttempts int `yaml:"creationAttempts" default:"3"`
CreationCooldown Duration `yaml:"creationCooldown" default:"2s"`
HideClient bool `yaml:"hideClient" default:"false"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an existing option called logPrivacy, maybe we should extend that instead of creating a new option?

And if a new option is created think naming this something that starts with "log" would be nicer to make it clear it impacts the logs, and would follow the existing convention (logLevel, logPrivacy, etc.).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree to follow the existing naming convention. But what exactly do you mean by extending that option? I am thinking of two possibilities here:

  • Use that option instead of HideClient in the check in resolver/query_logging_resolver.go
  • Introduce different "levels" of privacy similar to Pi-hole (e.g. "hide client", "hide targets", "hide all")

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logPrivacy is only for logging purposes. If true, all sensitive data (requested domain, response data) will be obfuscated. Purpose: admin should not see, which domains were resolved.

I think it makes sense to introduce new configuration parameter for query logging. Currently we log client IP, client names, response reason, question (typically domain name), response code, answer and duration.

To make it more configurable, we can introduce a list of "columns" to log, something like:

queryLog:
  columns:
    - clientIP
    - clientNames
    - duration

column can be an enum. If not specified, we log all possible columns. If only a subset is set, all other columns are empty.

What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it more configurable, we can introduce a list of "columns" to log, something like:

I think that is awesome.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduce different "levels" of privacy similar to Pi-hole (e.g. "hide client", "hide targets", "hide all")

I was thinking of something like this, but what @0xERR0R suggested is great!

@0xERR0R 0xERR0R modified the milestones: 0.20, 0.21 Nov 7, 2022
@0xERR0R 0xERR0R linked an issue Nov 24, 2022 that may be closed by this pull request
@0xERR0R
Copy link
Owner

0xERR0R commented Nov 24, 2022

replaced with #766

@0xERR0R 0xERR0R closed this Nov 24, 2022
@0xERR0R 0xERR0R removed this from the 0.21 milestone Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

querylog: define which information should be logged
3 participants