Skip to content
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

Initialize persisted root superuser on SQL server startup #8690

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

fulghum
Copy link
Contributor

@fulghum fulghum commented Dec 19, 2024

Previously, Dolt would only create a root superuser on sql-server startup when no other user accounts had been created. This resulted in a behavior where users would run dolt sql-server, create user accounts, then the next time they restart the sql-server, the root account would no longer be present. This behavior has surprised several customers (see #5759) and is different from MySQL's behavior, which creates a persistent root superuser as part of initialization.

This change modifies this behavior so that a root superuser is created, and persisted, the first time a SQL server is started for a database, unless the --skip-root-user-initialization flag is specified, or if an ephemeral super user is requested with the --user option. Subsequent runs of dolt sql-server do not automatically create the root superuser – only the first time dolt sql-server is started when there is no privileges database yet, will trigger the root user to be created and the privileges database to be initialized

Internally, this is implemented by detecting the presence of any user account and privilege data stored to disk (by default, in the .doltcfg/privileges.db file). When no user account and privilege data exists, the root superuser initialization logic will run. This means the privileges.db data is now always created on the first run of dolt sql-server, even if the data is empty.

As part of this change, the root superuser is now scoped to localhost, instead of % (i.e. any host). This improves the default security posture of a Dolt sql-server and better aligns with MySQL's behavior. Customers who rely on using the root account to connect from non-localhost hosts, will need to either log in and alter the root account to allow connections from the hosts they need, or they can specify the DOLT_ROOT_HOST and/or DOLT_ROOT_PASSWORD environment variables to override the default host (localhost) and password ("") for the root account when it is initialized the first time a sql-server is launched.

One side effect of this change is that dolt sql -u <user> may work differently for some uses. Previously, if there was no user account and privilege data persisted to disk yet (i.e. the .doltcfg/privileges.db file), then users could specify any username and password to dolt sql (e.g. dolt sql -u doesnotexist) and they would still be logged in – user authentication was ignored since no user account and privilege data existed. Now that the user account and privilege data is always initialized when running dolt sql-server, customers may no longer use dolt sql --user <user> to log in with unknown user accounts. The workaround for this is to simply run dolt sql without the --user option, and Dolt will use the default local account.

Fixes: #5759

Depends on: dolthub/go-mysql-server#2797

Related to: dolthub/doltgresql#1113

Documentation updates: dolthub/docs#2460

@fulghum fulghum force-pushed the fulghum/persist_root_superuser branch from a66e815 to 0aa16c6 Compare December 20, 2024 00:17
@dolthub dolthub deleted a comment from coffeegoddd Dec 20, 2024
@dolthub dolthub deleted a comment from coffeegoddd Dec 20, 2024
@dolthub dolthub deleted a comment from coffeegoddd Dec 23, 2024
@fulghum fulghum force-pushed the fulghum/persist_root_superuser branch 3 times, most recently from 61fd270 to bb27504 Compare December 23, 2024 22:32
@dolthub dolthub deleted a comment from coffeegoddd Jan 2, 2025
@dolthub dolthub deleted a comment from coffeegoddd Jan 2, 2025
@fulghum fulghum force-pushed the fulghum/persist_root_superuser branch from bb27504 to 4f7b73a Compare January 3, 2025 23:59
@dolthub dolthub deleted a comment from coffeegoddd Jan 4, 2025
@fulghum fulghum force-pushed the fulghum/persist_root_superuser branch from 4f7b73a to e4b0423 Compare January 4, 2025 01:54
@dolthub dolthub deleted a comment from coffeegoddd Jan 6, 2025
@dolthub dolthub deleted a comment from coffeegoddd Jan 8, 2025
@fulghum fulghum force-pushed the fulghum/persist_root_superuser branch 2 times, most recently from 776eab1 to 3864f5d Compare January 9, 2025 00:51
@dolthub dolthub deleted a comment from coffeegoddd Jan 9, 2025
@fulghum fulghum force-pushed the fulghum/persist_root_superuser branch from 3864f5d to 5ac80df Compare January 9, 2025 01:21
@fulghum fulghum marked this pull request as ready for review January 9, 2025 05:13
@fulghum fulghum requested a review from zachmu January 9, 2025 18:21
Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

Some concerns about the security of this approach, take a look and see if you agree.

go/libraries/doltcore/servercfg/yaml_config.go Outdated Show resolved Hide resolved
go/libraries/doltcore/servercfg/serverconfig.go Outdated Show resolved Hide resolved
go/cmd/dolt/commands/sqlserver/server.go Outdated Show resolved Hide resolved
@fulghum fulghum force-pushed the fulghum/persist_root_superuser branch 3 times, most recently from 5e83d5f to d4d17aa Compare January 11, 2025 01:47
@dolthub dolthub deleted a comment from coffeegoddd Jan 13, 2025
@dolthub dolthub deleted a comment from coffeegoddd Jan 13, 2025
@fulghum fulghum force-pushed the fulghum/persist_root_superuser branch from 7651fc1 to 9eab71d Compare January 14, 2025 00:26
Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

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

LGTM, seems like a good compromise

@fulghum fulghum force-pushed the fulghum/persist_root_superuser branch from d1ef725 to 5253ec7 Compare January 14, 2025 22:20
@dolthub dolthub deleted a comment from coffeegoddd Jan 14, 2025
@dolthub dolthub deleted a comment from coffeegoddd Jan 14, 2025
@fulghum fulghum force-pushed the fulghum/persist_root_superuser branch from 5253ec7 to d38e569 Compare January 15, 2025 01:53
@dolthub dolthub deleted a comment from coffeegoddd Jan 15, 2025
@coffeegoddd
Copy link
Contributor

@fulghum DOLT

comparing_percentages
100.000000 to 100.000000
version result total
1265e00 ok 5937457
version total_tests
1265e00 5937457
correctness_percentage
100.0

@dolthub dolthub deleted a comment from coffeegoddd Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dolt's disappearing root user is confusing
3 participants