TheArd
TheArd

Reputation: 21

Masking IP addresses, names, and emails in Grafana before downloading logs

I am fetching multiple logs from Loki in Grafana, and I want to mask sensitive data (like IP addresses, email addresses, and names) before downloading the logs using the Grafana UI.

The requirement is as follows:

Logs should remain in their original form when viewed in Grafana. When downloaded, the logs must have sensitive data (e.g., IPs, emails, names) masked. What I’ve tried: I attempted to use the following LogQL query with a replace function to mask IP addresses:

{filename="PATH"}
| regexp "(?P<ip>[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})"
| line_format "{{ replace .line .ip \"***\" }}" 

However, this approach does not work. I’m unsure if it’s an issue with how replace is used in the query or if there’s another solution I should try.

Is there a way to achieve this masking behavior in Grafana/Loki while still maintaining the original logs for display? Any ideas or alternative approaches are welcome.

Upvotes: 1

Views: 70

Answers (0)

Related Questions