Security

MySQL and MariaDB accounts

How the SQL front-end finds and checks accounts: bootstrap administrators in the configuration, accounts made by CREATE USER, host matching, ALTER USER, SET PASSWORD, DROP USER and what is refused.

The accounts of the SQL front-end are modelled on MySQL's (decision D54). raftdb-mysql checks them itself; they are not accounts of raftdb-server.

Where accounts live#

KindDefined byPrivilegesChangeable with SQL
Bootstrap administratorA user = NAME:PASSWORD line of mysql.conf (or --user)Every privilege, WITH GRANT OPTIONNo. SET PASSWORD for one answers: the password of an account named in the configuration is set there.
Stored accountCREATE USERWhat GRANT gives itYes

Stored accounts are documents in the table accounts of the hidden Raft DB database __rdb_accounts (names that start __rdb_ are never listed). Each document keeps the two double hashes the password plugins check, SHA1(SHA1(password)) and SHA256(SHA256(password)), never the password, and the account's grants.

Keep at least one bootstrap administrator. It is how you create the first stored account, and it works even if the hidden database has a problem.

Syntax#

SQL
CREATE USER [IF NOT EXISTS] 'name'@'host' [IDENTIFIED BY 'password'] [, ...];
CREATE USER 'name'@'host' IDENTIFIED WITH mysql_native_password AS '*HASH';
ALTER USER [IF EXISTS] 'name'@'host' IDENTIFIED BY 'password';
SET PASSWORD [FOR 'name'@'host'] = 'password';
RENAME USER 'old'@'host' TO 'new'@'host';
DROP USER [IF EXISTS] 'name'@'host' [, ...];

How a client is matched to an account#

A client logs in as the stored account with the most specific host that matches: an exact address, a pattern with %, localhost for a loopback client, or %. A bootstrap administrator is looked at first: if the name is in the configuration, the configured password is used whatever the host. A client from a loopback address is shown in messages as localhost, as MySQL does (Login refused for user 'bob'@'localhost' (password supplied: YES)).

IDENTIFIED WITH mysql_native_password AS '*HASH' (the text mysql.user shows) works, and a client that offers caching_sha2_password for such an account is switched to the native plugin, because an account made from a native hash alone has no SHA-256 hash.

Remarks#

  • A change to any account raises a counter that every session of this front-end compares, so a GRANT or REVOKE takes effect on the next statement of connections that are already open. Several front-ends in front of one server each have their own counter: a change made through another one is seen when a session next logs in.
  • FLUSH needs RELOAD and has nothing to flush.
  • SHOW DATABASES, SHOW TABLES, information_schema and DESCRIBE show only what the account may see (an account with SHOW DATABASES sees all databases).
  • Passwords in CREATE USER ... IDENTIFIED BY 'x' travel in the statement, in clear text (no TLS), and appear in RAFTDB_MYSQL_TRACE output.
  • There is no password policy, expiry, lock or failed-login counter.

Not supported yet (refused with error 1235)#

ACCOUNT LOCK, PASSWORD EXPIRE, REQUIRE SSL / X509, resource limits, roles, proxy grants, privileges on routines, IDENTIFIED BY RANDOM PASSWORD. The dynamic global privileges (SYSTEM_VARIABLES_ADMIN and others) are unknown; mysql.user and mysql.db are not provided as tables.

Examples#

From the privilege checks (run as seven different users against Raft DB and against a real MySQL 9.7):

SQL
CREATE USER 'bob'@'%' IDENTIFIED BY 'bobpw';
CREATE USER IF NOT EXISTS 'bob'@'%';
SHOW GRANTS FOR 'bob'@'%';

CREATE USER 'bob'@'%' a second time fails with error 1396 (Operation CREATE USER failed for 'bob'@'%'); with IF NOT EXISTS it succeeds.

See also#