Skip to content

Mark AllowNativePassword in DSN param string be true by default. #644

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

Merged
merged 2 commits into from
Aug 18, 2017
Merged

Conversation

elemount
Copy link
Contributor

@elemount elemount commented Aug 2, 2017

Description

This is the change about issue #642 (Is it possible to set the default value of "allowNativePasswords" to "true"?)
I see this AllowNativePassword param is introduced by @twocode in #494 , hi @twocode why you create this parameter and set the default value is true? Any security reason or others?
I think set the we should not have the allowNativePasswords param, so could we set it true?

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

@methane methane changed the title Mark AllowNativePassword in DNS param string be true by default. Mark AllowNativePassword in DSN param string be true by default. Aug 2, 2017
@twocode
Copy link
Contributor

twocode commented Aug 3, 2017

Hey @elemount , setting allowNativePasswords to false by default was basically following similar syntax as allowOldPasswords and allowClearTextPasswords. However, native authentication is the default auth method and safer than old password or clear text; it should be set to true by default. Besides your code changes made in this PR, I think we should by default allow authentication switch with native password authentication in this code:

mysql/driver.go

Line 165 in 5926162

} else if mc.cfg.AllowNativePasswords && err == ErrNativePassword {

@julienschmidt , Hi Julien, what do you think?

Thanks,
Xiangyu

@bingosummer
Copy link

bingosummer commented Aug 8, 2017

@julienschmidt @methane Could you please have a review?

Copy link
Member

@julienschmidt julienschmidt left a comment

Choose a reason for hiding this comment

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

Generally, this change makes sense to me.
If no one else of the team has any objections, I think it can and should be allowed by default.

README.md Outdated
```
`allowNativePasswords=true` allows the usage of the mysql native password method.
`allowNativePasswords=true` allows the usage of the mysql native password method, and to be `false` to disallow the usage of mysql native password method during auth switch process.
Copy link
Member

Choose a reason for hiding this comment

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

Only the effect of allowNativePasswords=false has to be documented, as true is the default value and setting it manually wouldn't make sense as it doesn't change anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

@julienschmidt julienschmidt added this to the v1.4 milestone Aug 17, 2017
Copy link
Member

@methane methane left a comment

Choose a reason for hiding this comment

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

LGTM

README.md Outdated
```
`allowNativePasswords=true` allows the usage of the mysql native password method.
`allowNativePasswords=false` disallows the usage of mysql native password method during auth switch process.
Copy link
Member

Choose a reason for hiding this comment

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

Might be nit-picking, but "during auth switch process" is an internal detail. The average driver user has no idea what is meant by this. Just remove it.
And if you push a change, please also change "mysql" to "MySQL" to keep it consistent within the README

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @julienschmidt , I've updated it.

@julienschmidt julienschmidt merged commit 37b91d8 into go-sql-driver:master Aug 18, 2017
@julienschmidt
Copy link
Member

Thanks for your first contribution!

@wayneashleyberry
Copy link

wayneashleyberry commented Jun 4, 2018

I just updated to 1.4 and started getting native password errors:

[mysql] 2018/06/04 08:50:00 driver.go:120: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.
panic: could not ping database: this user requires mysql native password authentication.

When I checked the DSN I noticed that allowNativePasswords was being set to false

root:root@tcp(127.0.0.1:3306)/my_db?allowNativePasswords=false&parseTime=true&maxAllowedPacket=0&charset=utf8mb4

I had to add AllowNativePasswords: true, to my mysql.Config struct, but that seems like the opposite of what this PR added, or am I missing something?

@julienschmidt
Copy link
Member

@wayneashleyberry are you creating a new mysql.Config without using NewConfig() (which sets defaults such as AllowNativePasswords: true)?

@wayneashleyberry
Copy link

Ah, that's exactly what I'm doing @julienschmidt. Didn't know about NewConfig, will check it out — thanks!

@julienschmidt
Copy link
Member

When the DSN is formatted there is no difference between the zero value for AllowNativePasswords (false) and explicitly setting it to false.

What is new in v1.4.0 is that these settings are checked correctly. Before there were situations where mysql_native_password could be used even though AllowNativePasswords was set to false.

@wayneashleyberry
Copy link

Yeah, makes sense @julienschmidt — just didn't expect the change in behaviour.

I have learnt something new though, using NewConfig everywhere new :) Thanks for taking the time to explain the change 🙇

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.

6 participants