-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: add CREATE USER stmt and pgwire password-based authentication #9794
Conversation
Haven't reviewed anything yet, but please avoid writing large PR descriptions; instead, include whatever information is necessary in the commit message. See "Good Commit Message" area of https://github.com/cockroachdb/cockroach/blob/master/CONTRIBUTING.md#code-review-workflow. |
Review status: 0 of 30 files reviewed at latest revision, 1 unresolved discussion. security/password.go, line 62 at r1 (raw file):
It's unfortunate that pgwire is forcing how we store hashed passwords. I don't keep up on these things, but I'm pretty sure md5 is frowned upon from a security perspective. Cc @bdarnell, @arjunravinarayan, @mberhault. Comments from Reviewable |
security/password.go, line 62 at r1 (raw file):
|
Reviewed 28 of 30 files at r1. cli/sql.go, line 503 at r1 (raw file):
use cli/user.go, line 136 at r1 (raw file):
while you're here, move this inside the cli/user.go, line 143 at r1 (raw file):
why remove support for this? cli/cliflags/flags.go, line 235 at r1 (raw file):
ditto: why remove this? security/password.go, line 54 at r1 (raw file):
s/the// security/password.go, line 55 at r1 (raw file):
remove the last sentence and just say "returns the md5 hash of the password concatenated with the username". sql/logic_test.go, line 472 at r1 (raw file):
can this be sql/pgwire_test.go, line 1225 at r1 (raw file):
i don't remember the implications of this, but i'd certainly feel better if you only have one of these outstanding at a time. sql/pgwire_test.go, line 1230 at r1 (raw file):
put this into the sql/pgwire_test.go, line 1232 at r1 (raw file):
no need for this case; sql/pgwire_test.go, line 1238 at r1 (raw file):
throughout: prefer sql/pgwire_test.go, line 1249 at r1 (raw file):
can this use a placeholder instead? sql/parser/stmt.go, line 120 at r1 (raw file):
is it a DDL? how'd you arrive at that? sql/pgwire/v3.go, line 102 at r1 (raw file):
authMD5Password sql/pgwire/v3.go, line 348 at r1 (raw file):
throughout: change these sql/pgwire/v3.go, line 362 at r1 (raw file):
use sql/pgwire/v3.go, line 364 at r1 (raw file):
sql/pgwire/v3.go, line 382 at r1 (raw file):
sql/pgwire/v3.go, line 393 at r1 (raw file):
instead of modifying
sql/pgwire/v3.go, line 404 at r1 (raw file):
include the user in this string sql/testdata/user, line 1 at r1 (raw file):
what's the error? sql/testdata/user, line 4 at r1 (raw file):
this error should include the user whose creation was attempted Comments from Reviewable |
Review status: 28 of 30 files reviewed at latest revision, 23 unresolved discussions. security/password.go, line 62 at r1 (raw file):
|
The non-SQL parts look good to me. Has anyone reviewed the changes to Review status: 28 of 30 files reviewed at latest revision, 26 unresolved discussions. cli/sql_util.go, line 191 at r1 (raw file):
There should also be a new command-line flag for specifying a password. This is useful for tests and command-line automation. Probably as a separate PR. security/password.go, line 77 at r1 (raw file):
can you skip the line above and just encode sql/pgwire_test.go, line 1263 at r1 (raw file):
could you also test with a Unicode user name? Comments from Reviewable |
Review status: 28 of 30 files reviewed at latest revision, 26 unresolved discussions. security/password.go, line 62 at r1 (raw file):
|
Review status: 28 of 30 files reviewed at latest revision, 29 unresolved discussions, some commit checks failed. cli/sql_test.go, line 40 at r1 (raw file):
Does it make sense to change security.RootUser to a url.User to avoid all these conversions? sql/create.go, line 280 at r1 (raw file):
no period at end of error message sql/parser/create.go, line 607 at r1 (raw file):
This is problematic because it will save the password to the user's sql cli history file. I'm not sure what the correct thing to do is, though. sql/parser/stmt.go, line 120 at r1 (raw file):
|
Review status: 28 of 30 files reviewed at latest revision, 29 unresolved discussions, some commit checks failed. sql/pgwire/v3.go, line 382 at r1 (raw file):
|
Review status: 28 of 30 files reviewed at latest revision, 29 unresolved discussions, some commit checks failed. security/password.go, line 62 at r1 (raw file):
|
Review status: 28 of 30 files reviewed at latest revision, 29 unresolved discussions, some commit checks failed. cli/sql_test.go, line 40 at r1 (raw file):
|
Review status: 28 of 30 files reviewed at latest revision, 29 unresolved discussions, some commit checks failed. cli/sql_test.go, line 40 at r1 (raw file):
|
Review status: 28 of 30 files reviewed at latest revision, 29 unresolved discussions, some commit checks failed. sql/parser/create.go, line 607 at r1 (raw file):
|
Review status: 28 of 30 files reviewed at latest revision, 29 unresolved discussions, some commit checks failed. cli/user.go, line 143 at r1 (raw file):
|
Review status: 28 of 30 files reviewed at latest revision, 29 unresolved discussions, some commit checks failed. sql/parser/create.go, line 607 at r1 (raw file):
|
Review status: 15 of 29 files reviewed at latest revision, 29 unresolved discussions. cli/sql_util.go, line 191 at r1 (raw file):
|
Review status: 15 of 29 files reviewed at latest revision, 29 unresolved discussions, some commit checks pending. cli/sql.go, line 503 at r1 (raw file):
|
Review status: 15 of 29 files reviewed at latest revision, 29 unresolved discussions, some commit checks pending. sql/logic_test.go, line 472 at r1 (raw file):
|
Review status: 15 of 29 files reviewed at latest revision, 29 unresolved discussions, some commit checks failed. sql/logic_test.go, line 472 at r1 (raw file):
|
Review status: 15 of 29 files reviewed at latest revision, 25 unresolved discussions, some commit checks failed. sql/logic_test.go, line 472 at r1 (raw file):
|
Reviewed 14 of 15 files at r2. security/password.go, line 54 at r1 (raw file):
|
Review status: 28 of 29 files reviewed at latest revision, 23 unresolved discussions, some commit checks failed. sql/parser/create.go, line 607 at r1 (raw file):
|
Review status: 28 of 29 files reviewed at latest revision, 23 unresolved discussions, some commit checks failed. sql/parser/stmt.go, line 120 at r1 (raw file):
|
Reviewed 14 of 61 files at r3, 12 of 19 files at r4, 9 of 9 files at r5. pkg/base/config.go, line 154 at r5 (raw file):
I'm not sure this is the right location for these checks. All our other flag consistency checks are in package pkg/base/config.go, line 158 at r5 (raw file):
We need a longer explanation, either here as a comment or in the commit message, of the rationale for accepting a missing certificate. I know you know but this is not written anywhere. Please explain in writing. pkg/cli/sql_util.go, line 191 at r5 (raw file):
What would be the proper way for a user to request mpassword authentication on top of certificate validation? (Like 2FA)? pkg/cli/user.go, line 154 at r5 (raw file):
I think we still want an error to protect against empty passwords, unless an explicit flag ( pkg/security/auth.go, line 131 at r3 (raw file):
|
I will add documentation to the commit message. Thanks for pointing this out. Review status: all files reviewed at latest revision, 25 unresolved discussions, all commit checks successful. pkg/base/config.go, line 154 at r5 (raw file):
|
Reviewed 12 of 19 files at r4, 9 of 9 files at r5. pkg/cli/sql_util.go, line 191 at r5 (raw file):
|
Review status: all files reviewed at latest revision, 24 unresolved discussions, all commit checks successful. pkg/base/config.go, line 154 at r5 (raw file):
|
Review status: all files reviewed at latest revision, 24 unresolved discussions, all commit checks successful. pkg/cli/user.go, line 154 at r5 (raw file):
|
Reviewed 9 of 9 files at r5. pkg/security/auth.go, line 131 at r3 (raw file):
|
Review status: all files reviewed at latest revision, 24 unresolved discussions, some commit checks failed. pkg/sql/testdata/user, line 5 at r5 (raw file):
|
Review status: all files reviewed at latest revision, 24 unresolved discussions, some commit checks failed. pkg/base/config.go, line 154 at r5 (raw file):
|
Reviewed 1 of 61 files at r3, 14 of 14 files at r6. pkg/sql/create.go, line 239 at r6 (raw file):
indentation is off? pkg/sql/pgwire/server.go, line 265 at r6 (raw file):
optional, not even a nit: opinions vary on this, but I like to put the closing paren on the next line (you'll need to add a comma). The symmetry is nicer, in my opinion, but you should make up your own mind since we don't have a consistent style on this. Comments from Reviewable |
Reviewed 1 of 19 files at r4. Comments from Reviewable |
Reviewed 1 of 14 files at r6. pkg/cli/user.go, line 154 at r5 (raw file):
|
Could you either extend this PR or follow-up with another soon after to test the command-line flags for authentication. I believe we don't have any test that does this so far. Suggested by @songhao in #10175. Review status: all files reviewed at latest revision, 22 unresolved discussions, some commit checks failed. Comments from Reviewable |
Sounds good, I'll add this test in a separate PR. I'm going to wait either for a second LGTM or the end of the day on Monday to merge. Review status: 24 of 35 files reviewed at latest revision, 23 unresolved discussions, some commit checks pending. pkg/sql/create.go, line 280 at r5 (raw file):
|
Reviewed 12 of 12 files at r7. pkg/sql/create.go, line 239 at r6 (raw file):
|
Reviewed 3 of 3 files at r8. Comments from Reviewable |
Review status: all files reviewed at latest revision, 23 unresolved discussions, some commit checks pending. pkg/sql/parser/name_part.go, line 84 at r7 (raw file):
|
Reviewed 1 of 14 files at r6, 1 of 12 files at r7. Comments from Reviewable |
Looking good! Just minor nits left. Reviewed 12 of 12 files at r9. pkg/sql/pgwire/server.go, line 282 at r9 (raw file):
ReNormalizeName is only there to renormalize a name previously stored unnormalized in the database. pkg/sql/pgwire/v3.go, line 218 at r9 (raw file):
use the Comments from Reviewable |
Password-based authentication is an option for users that want to have authentication but find it difficult to use cert authentication. This form of authentication is only used in secure clusters, thus there are now two ways to connect to a secure cluster: - Providing --ca-cert, --cert, and --key in which case cert authentication will be used. - Providing --ca-cert in which case the user will be prompted for a password in our cli implementation and password authentication will be used. Important notes: - The root user cannot authenticate using a password. - Only users that have been created (i.e. exist in the system.users table) are allowed to authenticate, be it cert or password authentication. - Users that are created with an empty ("") password get a "password invalid" error when using password authentication. - Usernames are case-insensitive (i.e. Foo and foo are the same user). - CREATE USER <username> [WITH [PASSWORD '<pwd>']]. Note with and password are optional independently, which is what postgres does.
Review status: 28 of 36 files reviewed at latest revision, 23 unresolved discussions. pkg/sql/pgwire/server.go, line 282 at r9 (raw file):
|
Reviewed 8 of 8 files at r10. Comments from Reviewable |
Reviewed 8 of 12 files at r9, 8 of 8 files at r10. pkg/sql/pgwire/v3.go, line 247 at r10 (raw file):
nit: this is no longer called "public" Comments from Reviewable |
Add mechanism to create users and then authenticate as them through a pgwire connection. This takes care of #6457.
@tamird @petermattis @cuongdo @mberhault
This change is