This topic describes the authentication and identification mechanisms in the MySQL-compatible mode of OceanBase Database, including user authentication, the composition of identity identifiers, and the use of authentication plugins.
The authentication and identification feature is used to verify the identity of users logging into the database, confirm whether they can be associated with a database user, and enforce security controls on data access activities based on the permissions of the associated user. The Authentication Plugin is used for user password verification.
User authentication
User authentication in OceanBase Database refers to the process where the client provides valid credentials when attempting to access the OceanBase server. If the OceanBase server confirms that the provided credentials are valid, it allows the client to access OceanBase Database. OceanBase Database uses a protocol called the MySQL Authentication Protocol (MAPI) for user authentication. It is based on the MySQL client account on the client machine to complete authentication. That is, only clients with the correct username and password can connect to the OceanBase server. When the client sends a connection request, the OceanBase server sends a random identifier to the client. The client must use the correct username and password to decode this identifier and then send the decoded result back to the server. If the result is correct, the OceanBase server allows the client to connect.
Identity identifier
In MySQL-compatible mode, a user consists of a user_name and a host. Here is a direct example: create three users with the same username.
Example:
create user 'u1'@'%' identified by '*******';
create user 'u1'@'10.xxx.xxx.1' identified by '*******';
create user 'u1'@'10.xxx.xxx.2' identified by '*******';
Where:
%: Allows any client IP to connect to the tenant.10.xxx.xxx.1: Allows only the IP10.xxx.xxx.1to connect to the tenant.10.xxx.xxx.2: Allows only the IP10.xxx.xxx.2to connect to the tenant.
When a user logs in, the OBServer node controls user login based on the matching of user_name, client_ip, and password.
Authentication plugin
OceanBase Database supports using authentication plugins (Authentication Plugin) to control password hashing and verification methods in MySQL-compatible mode. Currently, the following authentication plugins are supported:
mysql_native_password: The traditional password authentication plugin, using the SHA-1 hash algorithm.
caching_sha2_password: A password authentication plugin based on SHA-256, providing a higher level of security. This plugin is supported starting from V4.4.2 BP2. You can set it as the default plugin for creating new users via the system variable default_authentication_plugin. This plugin has the following features:
- SHA-256 hash algorithm: Replaces SHA-1 with the stronger SHA-256 algorithm and appends a random value (Salt) when generating the hash.
- Dual authentication modes: Supports fast authentication (based on hash cache) and full authentication (based on storage-layer hash, using multiple rounds of SHA-256 computation).
- Secure transmission: Supports SSL and RSA encrypted transmission of user passwords.
- Password caching: The server caches the hashed values of authenticated users to improve subsequent authentication performance.
- Adjustable number of iterations: You can control the number of SHA-256 iterations for the storage-layer hash via the system variable caching_sha2_password_digest_rounds (default is 5000).
ob_sm3_password: This plugin fully reuses
caching_sha2_passwordfor its authentication protocol and state machine (AuthSwitch, fast authentication/full authentication, TLS/RSA key transmission), but maintains independent algorithms and metadata. This plugin has the following features:- SM3 hash algorithm (GB/T 32905-2016): Replaces SHA-256 for password storage and authentication verification.
- Dual authentication modes: Fast authentication (memory cache) + Full authentication (disk-stored string + SSL/RSA key transmission).
- Adjustable number of iterations: You can control the number of SM3 iterations performed by the
ob_sm3_passwordauthentication plugin when generating the password authentication string via the system variable ob_sm3_password_digest_rounds (default is 5000).
Note
For V4.4.2, the authentication plugin
ob_sm3_passwordis supported starting from V4.4.2 BP3.
Component and driver version requirements
When using the caching_sha2_password or ob_sm3_password authentication plugin, the database components and client drivers must meet the following version requirements:
Components/drivers |
caching_sha2_password |
ob_sm3_password |
|---|---|---|
| OceanBase Database Proxy (ODP) | V4.4.0 and later | V4.4.2.0 and later |
| OBClient | V2.2.13 and later | V2.2.14 and later |
| libobclient | V2.2.13 and later | V2.2.14 and later |
| OB-JDBC | V2.4.18 and later | V2.4.20 and later |
Examples
When creating or modifying a user, you can specify the authentication plugin using the IDENTIFIED WITH auth_plugin syntax. If not specified by the default_authentication_plugin variable, mysql_native_password is used by default.
Create the user
user1, specifying to use thecaching_sha2_passwordauthentication plugin (supported starting from V4.4.2 BP2).obclient> CREATE USER user1 IDENTIFIED WITH caching_sha2_password BY '*******';Create the user
user2, specifying to use themysql_native_passwordauthentication plugin.obclient> CREATE USER user2 IDENTIFIED WITH mysql_native_password BY '*******';Modify the authentication plugin for the user
user2.obclient> ALTER USER 'u1'@'%' IDENTIFIED WITH caching_sha2_password BY '*******';Create the user
sm3_user, explicitly specifying to useob_sm3_password.obclient> CREATE USER sm3_user IDENTIFIED WITH ob_sm3_password BY '******';View the authentication plugin information of a user.
obclient> SELECT user, plugin, authentication_string FROM mysql.user WHERE user LIKE 'user_%';
References
For more details about the IDENTIFIED WITH syntax, see CREATE USER.