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

Template: Added a sha256 template function for obfuscating / anonymize PII data in e.g. the replace stage #2422

Merged
merged 4 commits into from
Jul 28, 2020

Conversation

wardbekker
Copy link
Member

@wardbekker wardbekker commented Jul 26, 2020

What this PR does / why we need it:

The replace pipeline stage allows the replacement of PII values, but no obfuscating/anonymization like https://github.com/y-ken/fluent-plugin-anonymizer. By calculating the hash of a known value, you retain the possibility to query on the hashed value, so no data is lost.

See this example where typical PII data like email and SSN are replaced with a hashed value

image

Special notes for your reviewer:

Checklist

  • Documentation added
  • Tests updated

@codecov-commenter
Copy link

codecov-commenter commented Jul 26, 2020

Codecov Report

Merging #2422 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2422      +/-   ##
==========================================
- Coverage   61.64%   61.64%   -0.01%     
==========================================
  Files         160      160              
  Lines       13597    13601       +4     
==========================================
+ Hits         8382     8384       +2     
- Misses       4593     4594       +1     
- Partials      622      623       +1     
Impacted Files Coverage Δ
pkg/logentry/stages/template.go 82.75% <100.00%> (+1.27%) ⬆️
pkg/promtail/targets/file/tailer.go 76.13% <0.00%> (-2.28%) ⬇️

Comment on lines +186 to +190
```yaml
- template:
source: output
template: '{{ Sha256 .Value "salt" }}'
```
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to have an example of this in replace.md as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added!

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@pull-request-size pull-request-size bot added size/M and removed size/S labels Jul 27, 2020
Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

Lgtm

I’d prefer the static function over the hasher.

@@ -32,6 +34,11 @@ var (
"TrimPrefix": strings.TrimPrefix,
"TrimSuffix": strings.TrimSuffix,
"TrimSpace": strings.TrimSpace,
"Sha256": func(salt string, s string) string {
hasher := sha256.New()
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will be better https://golang.org/pkg/crypto/sha256/#Sum256 since you don’t reuse the hasher.

The reason is shorter code but also less heap allocation for high volume.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed. changed!

@@ -32,6 +34,10 @@ var (
"TrimPrefix": strings.TrimPrefix,
"TrimSuffix": strings.TrimSuffix,
"TrimSpace": strings.TrimSpace,
"Sha256": func(salt string, s string) string {
Copy link
Member

Choose a reason for hiding this comment

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

I like this, but it'd be cool if it was multi-arity. For instance, supporting | Sha256 and | Sha256 "salt".

I can followup this PR with this change myself.

@owen-d owen-d merged commit 0fa98d8 into master Jul 28, 2020
@owen-d owen-d deleted the sha_template_function branch July 28, 2020 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants