-
Notifications
You must be signed in to change notification settings - Fork 482
sasl/scram #33468
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
sasl/scram #33468
Conversation
jasonhernandez
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.
I did a preliminary review and wanted to give some guidance on timing attacks and input validation. I assume some of these are already on your mental to-do list even if not called out.
a5bf100 to
fde3947
Compare
|
Sorry I just saw this! Looking over it now |
48ee1a6 to
ae20c1f
Compare
SangJunBak
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.
Overall the code looks great, just recommendations on documentation and testing. Nits are optional but I think we should do the comments related to testing. Lemme know if you want me to clarify anything in this review
| ) { | ||
| let role = self.catalog().try_get_role_by_name(role_name.as_str()); | ||
| let role_auth = role | ||
| .as_ref() |
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.
nit: I think the as_refs here, line 292, and line 297 are redundant
| let real_hash = role_auth | ||
| .as_ref() | ||
| .and_then(|auth| auth.password_hash.as_ref()); | ||
| let hash_ref: &str = real_hash.map(|s| s.as_str()).unwrap_or(&mock_hash); |
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.
nit: I think the explicit type annotation is redundant
src/auth/src/hash.rs
Outdated
| let signing_key = openssl::pkey::PKey::hmac(&server_key) | ||
| .map_err(|e| VerifyError::Hash(HashError::Openssl(e)))?; | ||
| let mut signer = | ||
| openssl::sign::Signer::new(openssl::hash::MessageDigest::sha256(), &signing_key) | ||
| .map_err(|e| VerifyError::Hash(HashError::Openssl(e)))?; | ||
| signer | ||
| .update(auth_message.as_bytes()) | ||
| .map_err(|e| VerifyError::Hash(HashError::Openssl(e)))?; | ||
| let server_signature = signer | ||
| .sign_to_vec() | ||
| .map_err(|e| VerifyError::Hash(HashError::Openssl(e)))?; |
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.
nit: Can probably de-duplicate this code w/ the client signature code by making it a helper function or anonymous function
src/pgwire/src/message.rs
Outdated
| pub enum SASLServerFinalMessageKinds { | ||
| Verifier(String), | ||
| // The spec specifies an Error kind here but PG just uses | ||
| // it's own error handling |
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.
nit: its*
| Err(_) => { | ||
| send_mock_challenge( | ||
| role_name, | ||
| self.catalog().state().mock_authentication_nonce(), |
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's not obvious the purpose of mock_authentication_nonce. We should probably document this above the definition of send_mock_challenge and here as well
| let opts1 = mock_sasl_challenge(username, mock); | ||
| let opts2 = mock_sasl_challenge(username, mock); | ||
| assert_eq!(opts1, opts2); | ||
| } |
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'd actually like to see more unit tests for sasl_verify! Especially since it's a pure function. Maybe something like:
- Positive case
- Client proof doesn't match
| &user, | ||
| &response.proof, | ||
| &auth_message, | ||
| &mock_hash, |
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'm guessing mock_hash is the hash generated from the mock_nonce and mock_sasl_challenge? Not immediately obvious the purpose of it and where it comes from, especially since the control flow goes jumps back and forth between coord messages. Should probably document where it comes from and the purpose it serves!
|
I think the next step is rigging up the orchestratord changes. Not sure if you'd like to do that or delegate that to Alex. Regardless should prolly keep the self managed peeps updated! |
cb26950 to
3fcdb9f
Compare
3fcdb9f to
dcd060d
Compare
jasonhernandez
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.
Thanks for addressing my comments / review. I think this looks ok from a security standpoint. More comments / test cases in line with @SangJunBak's recommendations are nice to add but not blocking re: security.
The (SASL/SCRAM)[MaterializeInc#33468] PR introduces the need for some stable, cluster wide, cryptographically random key material. We use this material to be able to present deterministic challenges for even users that don't exist to guard against enumeration attacks. Old versions of the catalog won't have this so we have to add it.
The (SASL/SCRAM)[MaterializeInc#33468] PR introduces the need for some stable, cluster wide, cryptographically random key material. We use this material to be able to present deterministic challenges for even users that don't exist to guard against enumeration attacks. However that PR made a bad assumption that the initialize step of catalog opening would always add this new key. But old versions that have already been initialized wouldn't have it! This PR add code to generate it for old versions
The (SASL/SCRAM)[MaterializeInc#33468] PR introduces the need for some stable, cluster wide, cryptographically random key material. We use this material to be able to present deterministic challenges for even users that don't exist to guard against enumeration attacks. However that PR made a bad assumption that the initialize step of catalog opening would always add this new key. But old versions that have already been initialized wouldn't have it! This PR add code to generate it for old versions
The [SASL/SCRAM](MaterializeInc#33468) PR introduces the need for some stable, cluster wide, cryptographically random key material. We use this material to be able to present deterministic challenges for even users that don't exist to guard against enumeration attacks. However that PR made a bad assumption that the initialize step of catalog opening would always add this new key. But old versions that have already been initialized wouldn't have it! This PR add code to generate it for old versions
This reverts commit 2c17d81.
This reverts commit 2c17d81.
The [SASL/SCRAM](MaterializeInc#33468) PR introduces the need for some stable, cluster wide, cryptographically random key material. We use this material to be able to present deterministic challenges for even users that don't exist to guard against enumeration attacks. However that PR made a bad assumption that the initialize step of catalog opening would always add this new key. But old versions that have already been initialized wouldn't have it! This PR add code to generate it for old versions
The [SASL/SCRAM](MaterializeInc#33468) PR introduces the need for some stable, cluster wide, cryptographically random key material. We use this material to be able to present deterministic challenges for even users that don't exist to guard against enumeration attacks. However that PR made a bad assumption that the initialize step of catalog opening would always add this new key. But old versions that have already been initialized wouldn't have it! This PR add code to generate it for old versions
The [SASL/SCRAM](#33468) PR introduces the need for some stable, cluster wide, cryptographically random key material. We use this material to be able to present deterministic challenges for even users that don't exist to guard against enumeration attacks. However that PR made a bad assumption that the initialize step of catalog opening would always add this new key. But old versions that have already been initialized wouldn't have it! This PR add code to generate it for old versions <!-- Describe the contents of the PR briefly but completely. If you write detailed commit messages, it is acceptable to copy/paste them here, or write "see commit messages for details." If there is only one commit in the PR, GitHub will have already added its commit message above. --> ### Motivation Fixes MaterializeInc/database-issues#9724 <!-- Which of the following best describes the motivation behind this PR? * This PR fixes a recognized bug. [Ensure issue is linked somewhere.] * This PR adds a known-desirable feature. [Ensure issue is linked somewhere.] * This PR fixes a previously unreported bug. [Describe the bug in detail, as if you were filing a bug report.] * This PR adds a feature that has not yet been specified. [Write a brief specification for the feature, including justification for its inclusion in Materialize, as if you were writing the original feature specification.] * This PR refactors existing code. [Describe what was wrong with the existing code, if it is not obvious.] --> ### Tips for reviewer <!-- Leave some tips for your reviewer, like: * The diff is much smaller if viewed with whitespace hidden. * [Some function/module/file] deserves extra attention. * [Some function/module/file] is pure code movement and only needs a skim. Delete this section if no tips. --> ### Checklist - [x] This PR has adequate test coverage / QA involvement has been duly considered. ([trigger-ci for additional test/nightly runs](https://trigger-ci.dev.materialize.com/)) - [ ] This PR has an associated up-to-date [design doc](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/README.md), is a design doc ([template](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/design/00000000_template.md)), or is sufficiently small to not require a design. <!-- Reference the design in the description. --> - [ ] If this PR evolves [an existing `$T ⇔ Proto$T` mapping](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/command-and-response-binary-encoding.md) (possibly in a backwards-incompatible way), then it is tagged with a `T-proto` label. - [ ] If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label ([example](MaterializeInc/cloud#5021)). <!-- Ask in #team-cloud on Slack if you need help preparing the cloud PR. --> - [ ] If this PR includes major [user-facing behavior changes](https://github.com/MaterializeInc/materialize/blob/main/doc/developer/guide-changes.md#what-changes-require-a-release-note), I have pinged the relevant PM to schedule a changelog post.
This implements the SASL/SCRAM protocol as implemented by postgres. The goal is to be compatible with postgres clients that support/expect SASL/SCRAM.
Motivation
Tips for reviewer
Checklist
$T ⇔ Proto$Tmapping (possibly in a backwards-incompatible way), then it is tagged with aT-protolabel.