Skip to content

Basic AuthPlugin support - #28

Open
sundy-li wants to merge 21 commits into
jonhoo:mainfrom
datafuse-extras:auth
Open

Basic AuthPlugin support#28
sundy-li wants to merge 21 commits into
jonhoo:mainfrom
datafuse-extras:auth

Conversation

@sundy-li

@sundy-li sundy-li commented Sep 14, 2021

Copy link
Copy Markdown
Contributor

Changes:

  1. Support AuthPlugin, defaults to use mysql_native_password
  2. Bump some crate (continue Bump deps #22)
  3. Some minor bug/Lint fixes (EOF -> Eof, etc)

PsiACE and others added 20 commits July 19, 2021 10:29
Signed-off-by: Chojan Shang <psiace@outlook.com>
Signed-off-by: Chojan Shang <psiace@outlook.com>
Signed-off-by: Chojan Shang <psiace@outlook.com>
Signed-off-by: Chojan Shang <psiace@outlook.com>
Signed-off-by: Chojan Shang <psiace@outlook.com>
Signed-off-by: Chojan Shang <psiace@outlook.com>
Signed-off-by: Chojan Shang <psiace@outlook.com>
@jonhoo

jonhoo commented Sep 17, 2021

Copy link
Copy Markdown
Owner

It's pretty difficult to review this given that it also includes #22, so I'd like to hold off on this until we can land #22. I'm definitely in favor of landing something along these lines though! I'll leave a few inline comments.

Comment thread src/commands.rs Outdated
Comment thread examples/serve_one.rs Outdated
Comment thread src/commands.rs Outdated
Comment thread src/lib.rs
//! ```
#![deny(missing_docs)]
#![deny(rust_2018_idioms)]
#![allow(clippy::from_over_into)]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why this?

Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
@sundy-li

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review.

Seems there are lots of styles/documents to improve. I'll try to apply the review suggestions.

@codecov

codecov Bot commented Sep 20, 2021

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.06897% with 81 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.63%. Comparing base (e77fd27) to head (2387bc8).
⚠️ Report is 186 commits behind head on main.

Files with missing lines Patch % Lines
src/lib.rs 57.42% 43 Missing ⚠️
src/value/utils.rs 81.42% 26 Missing ⚠️
src/commands.rs 68.75% 10 Missing ⚠️
src/value/encode.rs 66.66% 1 Missing ⚠️
tests/async.rs 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
- Coverage   81.19%   80.63%   -0.56%     
==========================================
  Files          10       11       +1     
  Lines        2159     2391     +232     
==========================================
+ Hits         1753     1928     +175     
- Misses        406      463      +57     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jonhoo jonhoo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks! I left some more comments inline.

Comment thread src/commands.rs
if capabilities.contains(CapabilityFlags::CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA) {
let (i, size) = read_length_encoded_number(i)?;
let mut i = i;
let size = i.read_lenenc_int().unwrap_or(0);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

If read_lenenc_int fails, should we return an error here instead? Assuming it is 0 doesn't seem right.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, but I don't know how to initialize which kind of nom Error can be raised.

BTW I will continue to finish the pr #22 , after that is merged, then you can review this pr.

Comment thread src/lib.rs

/// Connection id
fn connect_id(&self) -> u32 {
/// Default connection id

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'd still like to see some more documentation here about this value is. Ideally with a link to some MySQL/MariaDB documentation about what the connection ID is used for. Otherwise, as an implementor, I don't really know what I'm supposed to return here.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

We should also document what the default value is.

Comment thread src/lib.rs
Comment on lines +167 to +168
/// default plugin for authentication
/// Plugin methods: https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase_authentication_methods.html

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Here too I'd like to actually spell out what this is, what it's used for, when you might want to override it, and what the default value is (and why). I would copy-paste some of the documentation from that linked page, and include links to relevant subsections.

Comment thread src/lib.rs
Comment on lines +173 to +174
/// Called when reading the handshake response by client's auth_plugin
/// See: https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase.html#sect_protocol_connection_phase_auth_method_mismatch

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Same thing here — let's give consumers of this API a bit more to go on. At the very least this should say something like

Allows you to determine the authentication plugin to use for a particular user, independently of what the server default is (see [MysqlShim::default_auth_plugin]).

Comment thread src/lib.rs

/// Default salt(scramble) for auth plugin
fn salt(&self) -> [u8; SCRAMBLE_SIZE] {
/// Called when initializing the handshake

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This doesn't actually tell someone looking to implement this trait what this is used for, or what kind of value they should return. Again, copying from the MySQL documentation may be the way to go here.

Comment thread src/lib.rs
)
})?;
self.writer.set_seq(seq + 1);
auth_response = auth_response_data.to_vec();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I believe you can avoid this .to_vec() and the .to_vec() on auth_response before drop(handshake) if you restructure the code above a little bit to:

let auth_ok = if user_custom_auth {
    drop(handshake);
    // the rest of the contents of the `if` until this line, then:
    self.shim.authenticate(user_auth_plugin, &username, &salt, &auth_response)
} else {
    self.shim.authenticate(&handshake.auth_plugin, &handshake.username, &salt, &handshake.auth_response)
};

Comment thread src/lib.rs
drop(handshake);

let user_auth_plugin = self.shim.auth_plugin_for_user(&username);
// Start SwitchAuthRequest

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Let's move this comment into the if, since that's what it applies to.

Comment thread src/lib.rs
.authenticate(user_auth_plugin, &username, &salt, &auth_response)
{
let err_msg = format!(
"Access denied for user '{}'@'{}' (using password: YES)",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is "using password: YES" here conditional on something?

Comment thread src/lib.rs
self.socket_addr.ip()
);
writers::write_err(
ErrorKind::ER_ACCESS_DENIED_ERROR,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Should we perhaps allow MysqlShim::authenticate to return Result<(), ErrorKind> so that the implementor can indicate the error type? Or perhaps even Result<(), (String, ErrorKind)> so they can also dictate the message?

Comment thread src/lib.rs
| CapabilityFlags::CLIENT_SECURE_CONNECTION // this is required for `Secure Password Authentication`
| CapabilityFlags::CLIENT_PLUGIN_AUTH
| CapabilityFlags::CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA
| CapabilityFlags::CLIENT_CONNECT_WITH_DB)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Do we actually support CLIENT_CONNECT_WITH_DB?

ovr pushed a commit to ovr/msql-srv that referenced this pull request Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants