Skip to content

Commit

Permalink
Merge pull request #16953 from mberhault/marc/fail_root_password
Browse files Browse the repository at this point in the history
cli: return an error if using root without valid certificates
  • Loading branch information
mberhault authored Jul 10, 2017
2 parents f2e0676 + 22cbef6 commit 7a17925
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions pkg/cli/interactive_tests/test_secure.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ send "\\q\r"
eexpect $prompt
end_test

start_test "Check that root cannot use password."
# Run as root but with a non-existent certs directory.
send "$argv sql --certs-dir=non-existent-dir\r"
eexpect "Error: connections with user root must use a client certificate"
eexpect "Failed running \"sql\""
end_test

start_test "Check that CREATE USER WITH PASSWORD can be used from transactions."
# Create a user from a transaction.
send "$argv sql --certs-dir=$certs_dir\r"
Expand Down
13 changes: 8 additions & 5 deletions pkg/cli/sql_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,20 +374,23 @@ func makeSQLConn(url string) *sqlConn {
}

// getPasswordAndMakeSQLClient prompts for a password if running in secure mode
// and no certificates have been supplied. security.RootUser won't be prompted
// for a password as the only authentication method available for this user is
// certificate authentication.
// and no certificates have been supplied.
// Attempting to use security.RootUser without valid certificates will return an error.
func getPasswordAndMakeSQLClient() (*sqlConn, error) {
if len(sqlConnURL) != 0 {
return makeSQLConn(sqlConnURL), nil
}
var user *url.Userinfo
if !baseCfg.Insecure && sqlConnUser != security.RootUser &&
!baseCfg.ClientHasValidCerts(sqlConnUser) {
if !baseCfg.Insecure && !baseCfg.ClientHasValidCerts(sqlConnUser) {
if sqlConnUser == security.RootUser {
return nil, errors.Errorf("connections with user %s must use a client certificate", security.RootUser)
}

pwd, err := security.PromptForPassword()
if err != nil {
return nil, err
}

user = url.UserPassword(sqlConnUser, pwd)
} else {
user = url.User(sqlConnUser)
Expand Down

0 comments on commit 7a17925

Please sign in to comment.