Skip to content

Commit

Permalink
Allow dolt sql command line access to always log in as the root sup…
Browse files Browse the repository at this point in the history
…eruser account, even if the root account was assigned a password
  • Loading branch information
fulghum committed Jan 14, 2025
1 parent 99c7cca commit 17c65a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 1 addition & 12 deletions go/cmd/dolt/commands/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,9 @@ func newLateBindingEngine(
}

} else {
// Ensure a root user exists, with superuser privs
dbUser = DefaultUser
ed := rawDb.Editor()
user := rawDb.GetUser(ed, dbUser, config.ServerHost, false)
ed.Close()
if user != nil {
// Want to ensure that the user has an empty password. If it has a password, we'll error
err := passwordValidate(rawDb, salt, dbUser, nil)
if err != nil {
return nil, nil, nil, err
}
}

// If the user doesn't exist, we'll create it with superuser privs.
ed = rawDb.Editor()
defer ed.Close()
rawDb.AddSuperUser(ed, dbUser, config.ServerHost, "")
}
Expand Down
13 changes: 13 additions & 0 deletions integration-tests/bats/sql-privs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ teardown() {
[ $status -ne 0 ]
}

# Asserts that `dolt sql` can always be used to access the database as a superuser. For example, if the root
# user is assigned a password, `dolt sql` should still be able to log in as a superuser, since the user
# already has access to the host and data directory.
@test "sql-privs: superuser access is always available from dolt sql" {
# Create a root@% user with a password set
dolt sql -q "CREATE USER root@'%' identified by 'pass1'; grant all on *.* to root@'%' with grant option;"

# Make sure dolt sql can still log in as root, even though root has a password set now
run dolt sql -q "select user();"
[ $status -eq 0 ]
[[ $output =~ "root@localhost" ]] || false
}

@test "sql-privs: starting server with empty config works" {
make_test_repo
touch server.yaml
Expand Down

0 comments on commit 17c65a7

Please sign in to comment.