-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat: add optional token hashing #25982
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
Conversation
davidby-influx
left a comment
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.
A variety of smaller issues. I will need to review this again to fully understand the larger changes.
davidby-influx
left a comment
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.
My usual add more context to error and log messages and a few more substantive questions and suggestions
davidby-influx
left a comment
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.
All changes pertain to comments, but important one is whether to delete or include a commented out code section
15f8e92 to
6aa2d1a
Compare
devanbenz
left a comment
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.
Just a few comments mostly about extra safety checks and some error messaging. I've been able to get about half way through the PR. Going to step away for a minute to take a little brain break and then finish up the rest of the PR for my first pass.
devanbenz
left a comment
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.
Adding a few more comments to storage_authorization.go I noticed that a bunch of my comments for the require.NoError(..) is similar to what david commented so my apologies for that :P
devanbenz
left a comment
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.
Adding in a few more comments
devanbenz
left a comment
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.
Going to pick back up my review next week for a second pass. Consider this first pass finished up.
devanbenz
left a comment
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.
Finished reading through this code, everything looks fine to me after that pass. Please let me know when you merge in main and require a second look over.
a3c28e7 to
fc74353
Compare
|
Claude's analysis of potential information leakage in error messages: |
devanbenz
left a comment
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.
Leaving two comments, still finishing up the review.
davidby-influx
left a comment
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.
A few remaining suggestions. What a huge amount of work!
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.
Just a general question: do we have context for all the startup errors?
- Opening the KV store
- NewAuthorizationHasher
- authorization.NewStore
- etc.
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 took a while, but I think there's good context for everything in authorization/authorization.goand authorization/storage_authorization.go
|
I tested everything locally and it all seems fine. I did notice, as outlined by your comment here: https://github.com/influxdata/influxdb/pull/25982/files#diff-05dfd885ddd66163be3e6ac7416f3b6326f186d236cba26153bd790bc93c880dR51, that starting up influxd without |
During normal operation, there is no way to "downgrade" a hashed token, so there is no need to log about unhashing a token. On startup, the hashed token can not be unhashed because hashes are one-way. When a token is used, there is no attempt to store it as unhashed, even though this could be added. The only way to update a token is by sending a PATCH request to I think logging on startup that hashed tokens exist but hashed tokens are disabled is a good idea, though. |
|
I'd be ok with using a helper for all the
not essential, but the code makes assumptions about what the empty string means -- there's a comment about it so it is essentially a special type of token: an "unset one". |
philjb
left a comment
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.
initial comments
| Additionally, raw tokens are automatically migrated to hashed tokens if `--use-hashed-tokens` is configured. | ||
| Due to the schema changes, to use a version of InfluxDB without hashed token support, a manual downgrade using | ||
| `influxd downgrade` must be run. Any tokens stored as hashed tokens will be unusable by the old version of InfluxDB | ||
| and must be reset or recreated. |
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.
worth while to mention "or restored from an independent backup" ? or something like that?
That's a good idea. I'll go ahead and implement it. |
cmd/influxd/launcher/cmd.go
Outdated
| DestP: &o.UseHashedTokens, | ||
| Flag: "use-hashed-tokens", | ||
| Default: o.UseHashedTokens, | ||
| Desc: "enable token hashing", |
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.
so terse it borders on inaccurate for everything this flag controls.
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.
How about enable storing hashed API tokens on disk (improves security, but prevents downgrades to < 2.8)?
Add optional token hashing with `--use-hashed-tokens` command line option.
Create duplicate tokens from being created. This is a bug introduced earlier in this PR. Also improve tests so they detect the bug and use testify throughout.
Fix a bug that only allowed hashed tokens to be looked up if they used the currently active hashing algorithm. Also added tests for configuration migration scenarios (enabling and disabling hashing, changing hashing scheme).
Address PR issues on comments, error handling, and add final token matching check in `Store.GetAuthorizationByToken`.
Changes in addition to minor cleanups: - `authentication.Store` can now log info and warnings - Improved logic in `UpdateAuthorization` when both Token and HashedToken are set. Added supporting test cases.
Add tests for misuses of NewAuthorizationHasher and improve an error message.
Update outdated comment regarding PHC format attack.
- In Store.autogenerateHasher, avoid modifying foundVariants. - Improve comment for Hasher.HashWithSalt
Also add some clarifying comments.
- Removed `authResponse.HashedToken` field - Improved error messages, log messages, and comments - Improved error propagation - Improve description of `--use-hashed-tokens` command line parameter - Removed dead code - Implemented test to make sure hashed version of tokens can not be presented for authentication
f35ac5b to
d1b3e1b
Compare
philjb
left a comment
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
Add optional token hashing with --use-hashed-tokens command line option.