-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
Codecov Report
@@ 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
|
```yaml | ||
- template: | ||
source: output | ||
template: '{{ Sha256 .Value "salt" }}' | ||
``` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this 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.
pkg/logentry/stages/template.go
Outdated
@@ -32,6 +34,11 @@ var ( | |||
"TrimPrefix": strings.TrimPrefix, | |||
"TrimSuffix": strings.TrimSuffix, | |||
"TrimSpace": strings.TrimSpace, | |||
"Sha256": func(salt string, s string) string { | |||
hasher := sha256.New() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
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
Special notes for your reviewer:
Checklist