This topic describes how to configure and use the caching_sha2_password authentication plugin in Oracle-compatible mode, covering version requirements, the authentication process, user creation, client connection configuration, and troubleshooting common errors.
For more information about the features and authentication mechanism of the caching_sha2_password plugin, see Authentication.
Note
This feature is supported starting from V4.4.2 BP2.
Limitations and version requirements
When using the caching_sha2_password authentication plugin, the versions of the OBServer node, ODP, and client components must all meet the following requirements; otherwise, the connection may fail.
Component/Driver |
Version requirement |
|---|---|
| OceanBase Database (OBServer node) | From V4.4.2 BP2 (V4.4.2.2) to before V4.5.0.0, and V5.0.1 and later |
| OceanBase Database Proxy (ODP) | V4.4.0 and later |
| OBClient | V2.2.13 and later (requires libobclient V2.2.13 and later) |
| OB-JDBC | V2.4.18 and later |
| Connector/J | 8.0.9 and later |
| libmysqlclient-based client | 5.7.23 and later, or 8.0.4 and later |
| OBCI | V2.1.1.3 and later |
| ODBC Driver | V2.0.9.8 and later |
Notice
Native MySQL protocol clients (such as the mysql client or Connector/J) only support connecting directly to OBServer nodes for Oracle-compatible tenants. When connecting to an Oracle-compatible tenant via ODP, you must use obclient or OB-JDBC; otherwise, the connection will be rejected by ODP.
Authentication process
Before configuration, understand the authentication process of caching_sha2_password. This plugin supports two modes: fast authentication and full authentication:
- Fast authentication: The OBServer node caches authenticated user information. When a user reconnects from the same OBServer node with an unchanged password, a cache hit occurs, completing fast authentication without transmitting the password over a secure channel.
- Full authentication: The plugin performs full authentication for the first connection, after a password change, after the authentication plugin is changed, or when the cache expires. Full authentication requires transmitting the password over a secure channel (SSL encryption or RSA public key encryption) to avoid plaintext transmission.
The authentication method varies depending on the connection scenario:
Connection scenario |
Authentication method |
Secure channel requirement |
|---|---|---|
| The first connection after user creation or a password change | Full authentication | Either SSL or RSA required |
| Subsequent connections from the same OBServer node when the password has not been changed | Fast authentication | Not required |
| Connection via ODP | Full authentication | Either SSL or RSA required |
RSA security channel
When performing full authentication using the RSA method, the client first requests the RSA public key from the target OBServer node, then encrypts the password with this key before transmission.
The OBServer node automatically generates an RSA key pair upon startup (controlled by the system variable sha256_password_auto_generate_rsa_keys, enabled by default). The server side of the RSA link does not require manual generation or configuration of certificate files.
SSL security channel
When performing full authentication using the SSL method, SSL configuration (certificate placement and enabling) must be completed on the OBServer node first. For details, see OBServer transmission encryption.
Step 1: Create a user using caching_sha2_password
Log in to the Oracle-compatible tenant as the
SYSuser.obclient -h10.xxx.xxx.1 -P2881 -usys@oracle001 -p****** -ACreate a user that uses the
caching_sha2_passwordauthentication plugin.obclient> CREATE USER user1 IDENTIFIED WITH caching_sha2_password BY "******"; Query OK, 0 rows affectedYou can also switch an existing user to the
caching_sha2_passwordauthentication plugin usingALTER USER:obclient> ALTER USER user1 IDENTIFIED WITH caching_sha2_password BY "******"; Query OK, 0 rows affectedNote
After creating a user or changing the user's password or authentication plugin, the authentication cache for that user on the OBServer node immediately becomes invalid. The next connection will trigger full authentication.
Grant the
CREATE SESSIONprivilege to the user. In Oracle-compatible mode, users must be granted theCREATE SESSIONprivilege to log in to the database.obclient> GRANT CREATE SESSION TO user1; Query OK, 0 rows affected
Optional: Set caching_sha2_password as the default authentication plugin
If not set, newly created users use the ob_native_password authentication plugin by default. If you want newly created users to use caching_sha2_password by default, you can set the system variable default_authentication_plugin:
obclient> SET GLOBAL default_authentication_plugin = 'caching_sha2_password';
Query OK, 0 rows affected
Notice
This setting takes effect asynchronously and may have a delay of several seconds. Users created immediately after the setting takes effect may still use the default plugin ob_native_password. It is recommended to wait a short while before creating users and then confirm the actual effective plugin by following the method described in the next section, "View a user's authentication plugin".
To restore the default plugin:
obclient> SET GLOBAL default_authentication_plugin = 'ob_native_password';
Query OK, 0 rows affected
Step 2: Connect from the client
Command-line client
obclient versions that meet the version requirements do not require additional configuration parameters. During full authentication, the password is automatically encrypted and transmitted using an RSA public key:
obclient -h10.xxx.xxx.1 -P2881 -uuser1@oracle001 -p****** -A
Notice
obclient versions earlier than V2.2.13 do not support the caching_sha2_password authentication plugin. When connecting, an error indicating plugin loading failure will be reported. Please upgrade the client version. For common errors, see the section "Common errors and troubleshooting" below.
JDBC applications
When connecting using OB-JDBC (V2.4.18 or later), if the connection may trigger full authentication (first connection, connection after changing the password, or connection through ODP), you need to configure one of the following parameters in the connection properties:
allowPublicKeyRetrieval=true: Allows the client to request the RSA public key from the server (default isfalse).sslMode=REQUIRED: Transmits the password over an SSL-encrypted channel. SSL configuration must be completed on the OBServer side.
Example connection string (direct connection to OBServer):
Properties props = new Properties();
props.setProperty("user", "user1@oracle001");
props.setProperty("password", "******");
props.setProperty("allowPublicKeyRetrieval", "true");
Connection conn = DriverManager.getConnection("OB-JDBC connection string", props);
Note
When connecting directly to an OBServer, if the user's authentication cache on that node has already hit (the full authentication was successfully performed before and the password has not changed), a connection can succeed even without configuring the above parameters. Since client connection parameters cannot detect whether the cache has hit, it is recommended to uniformly configure allowPublicKeyRetrieval=true or sslMode=REQUIRED to avoid connection failures after the password changes.
Notes on connections through ODP
When connecting to users using the caching_sha2_password authentication plugin via ODP, note the following:
- The ODP version must be V4.4.0 or later. No additional configuration is required on the ODP side for RSA links.
- Each connection through ODP is treated as a full authentication. The client must configure
allowPublicKeyRetrieval=true(for RSA links) orsslMode=REQUIRED(for SSL links). - When connecting to an Oracle-compatible tenant via ODP, you must use obclient or OB-JDBC. Native MySQL protocol clients (such as the mysql client or Connector/J) will be rejected by ODP when connecting to an Oracle-compatible tenant via ODP (with error ERROR 1235). This restriction is unrelated to the authentication plugin.
- If the client-to-ODP connection uses SSL, refer to ODP transmission encryption for SSL configuration on the ODP side.
View a user's authentication plugin
obclient> SELECT username, plugin FROM SYS.DBA_USERS WHERE username = 'USER1';
When the value in the plugin column is caching_sha2_password, it indicates the user uses the caching_sha2_password authentication plugin. For more information about the DBA_USERS view, see the corresponding reference documentation.
Verify whether SSL is enabled for a connection
Execute the status (or \s) command in the mysql client. The value in the SSL line of the output indicates whether SSL encryption is enabled for the current connection:
SSL: Cipher in use is TLS_AES_256_GCM_SHA384: SSL is enabled for the current connection.SSL: Not in use: SSL is not enabled for the current connection.
Note
OceanBase Database does not currently support viewing SSL encryption information for the current connection using the SHOW STATUS LIKE 'Ssl_cipher' statement (this statement returns an empty set). Use the client's status command to view it.
Common errors and troubleshooting
Error message |
Possible causes |
Solution |
|---|---|---|
| ERROR 1045 (42000): Plugin caching_sha2_password could not be loaded: .../caching_sha2_password.so: cannot open shared object file: No such file or directory | The client version is lower than the required version (for example, obclient earlier than V2.2.13), or the caching_sha2_password plugin is missing |
Upgrade the client to the corresponding version in the "Limitations and version requirements" section. |
| Public Key Retrieval is not allowed | Full authentication is triggered for the connection, which requires transmitting the password via RSA. However, the client has not been granted permission to obtain the server's RSA public key (the JDBC parameter allowPublicKeyRetrieval defaults to false) |
Set allowPublicKeyRetrieval=true in the JDBC connection properties, or set sslMode=REQUIRED to use an SSL connection. |
| ERROR 1045 (42000): Access denied for user 'user1'@'xxx.xxx.xxx.xxx' (using password: YES) | Incorrect password | Retry after verifying the password is correct. |
| ERROR 5361 (HY000): user user1 lacks CREATE SESSION privilege; logon denied | The user has not been granted the CREATE SESSION privilege and cannot log in. |
Execute GRANT CREATE SESSION TO user1; as the administrator user and try again. |
| ERROR 1235 (0A000): Oracle tenant for current client driver is not supported | Connect to an Oracle-compatible tenant by using a native MySQL protocol client (such as the mysql client or Connector/J) through ODP. | Use obclient or OB-JDBC to connect to the Oracle-compatible tenant, or use a native MySQL protocol client to connect directly to the OBServer node. |