8000 loki.secretfilter: Change the way the secret is hashed by romain-gaillard · Pull Request #2529 · grafana/alloy · GitHub
[go: up one dir, main page]

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

loki.secretfilter: Change the way the secret is hashed #2529

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

romain-gaillard
Copy link
Contributor
@romain-gaillard romain-gaillard commented Jan 24, 2025

PR Description

This PR changes the way the secret is hashed in the experimental component loki.secretfilter.

In this context, the hash of the secret is used to be able to identify the redacted secret more easily, without revealing too much information about it in the logs. It's the reason why an algorithm with a shorter output was used (SHA1): it doesn't need to be collision resistant as it is used as an identifier for the redacted secret, not as a signature.

But I thought of a different approach to keep the hash relatively short: hash it with SHA256 and output only the first half of the hash. This approach should help keep the information about the secret minimal, while relying on a more recent hashing algorithm that is more likely to be available to someone investigating a leaked secret in their logs. I believe the first half of a SHA256 hash is unique enough to help identify the secret that leaked without ambiguity, and short enough not to add too much information about the underlying secret in the logs.

@kelnage happy to have your opinion on this!

Which issue(s) this PR fixes

Notes to the Reviewer

PR Checklist

  • CHANGELOG.md updated
  • Documentation added
  • Tests updated
  • Config converters updated

Copy link
Contributor

@romain-gaillard
Copy link
Contributor Author

Note that the failing tests aren't linked to this component.

@romain-gaillard romain-gaillard marked this pull request as ready for review January 24, 2025 14:41
hashBytes := hasher.Sum(nil)

// Only use the first half of the hash
firstHalf := hashBytes[:len(hashBytes)/2]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This sort of feels odd, could we use a native 128bit hash? This feels harder to use.

@kelnage
Copy link
kelnage commented Jan 27, 2025

I think this does make some sense - but I would much prefer it if the hash could be configurable, rather than our choice. I.e., if a user wants a particular hash function, they can pick it and we truncate it to the specific length.

Honestly, good secret encryption should use hash functions that we do not want to use in our component (e.g., compute/memory intensive ones), so the likelihood of us selecting a hash function that can be directly compared to a user's secret hash should be low - it's more relevant for identifying secrets which are being kept in plain text.

@clayton-cornell clayton-cornell added the type/docs Docs Squad label across all Grafana Labs repos label Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/docs Docs Squad label across all Grafana Labs repos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0