[Bug]: Correct-password login automatically unlocks an administratively locked account when connection control is enabled
Self Checks
- I have read the Contributing Guide.
- This is only for bug report, if you would like to ask a question, please head to Discussions.
- I have searched for existing issues search for existing issues, including closed ones.
- I confirm that I am using English to submit this report, otherwise it will be closed.
- 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- Please do not modify this template :) and fill in all the required fields.
OceanBase version
OceanBase-v4.4.2.1 or higher
Self Hosted
Self Hosted (OCP)
Environment
OS Version and CPU Arch: v2401.ky10.aarch64
SELECT VERSION(): 4.4.2.1 & 5.7.25-OceanBase-v4.4.2.3
Edition of the reproduction environment: Enterprise Edition
Tenant compatibility mode: MySQL
Connection path used in the reproduction: MySQL client -> OBProxy -> OceanBase
Relevant tenant configuration parameters: connection_control_failed_connections_threshold = 5 connection_control_min_connection_delay = 3600000 connection_control_max_connection_delay = 3600000
The same-named system variable connection_control_failed_connections_threshold was 0. The tenant configuration parameter was 5.
Production is Enterprise Edition. For source analysis, we inspected a local source tree named oceanbase-4.4.2_CE_BP1. This source tree is a reference for the analysis, not proof of the exact source revision used by the running binary.
I have not verified the issue also occurs on the latest Community Edition.
Steps to reproduce
Use an isolated, writable MySQL-mode test tenant and a disposable, non-root account. The following steps modify tenant configuration and create/lock a test account; do not run them on production.
As a tenant administrator, inspect the configuration parameters and the same-named system variable:
SHOW PARAMETERS LIKE 'connection_control%'; SHOW GLOBAL VARIABLES LIKE 'connection_control%';Enable connection control using the tenant configuration parameter:
ALTER SYSTEM SET connection_control_failed_connections_threshold = 5;Wait until the configuration is effective on all relevant observers.
Create a fresh disposable account. Do not perform failed-password login attempts with this account:
CREATE USER 'ob_lock_repro'@'%' IDENTIFIED BY '<test-only-strong-password>';Explicitly lock the account as the administrator:
ALTER USER 'ob_lock_repro'@'%' ACCOUNT LOCK;Confirm that the account is locked:
SELECT user_name, host, is_locked FROM oceanbase.DBA_OB_USERS WHERE user_name = 'ob_lock_repro';From a new client connection, log in as ob_lock_repro using its correct password and execute:
mysql -h * -P * -u 'ob_lock_repro@inst#cluster' -p'*' -e 'SELECT 1;'Unexpected result: the connection succeeds and SELECT 1 executes, despite the explicit administrative lock.
From the administrator connection, inspect the account state and SQL audit records. The relevant unexpected internal statement is:
ALTER USER 'ob_lock_repro'@'%' ACCOUNT UNLOCK;Control experiment in the same isolated test tenant:
ALTER SYSTEM SET connection_control_failed_connections_threshold = 0;Wait for the configuration to become effective, then explicitly lock the account again:
ALTER USER 'ob_lock_repro'@'%' ACCOUNT LOCK;Repeat the correct-password login from a new connection.
Observed control result: the login is rejected with:
ERROR 3118 (HY000): User locked
✔️ Expected Behavior
An explicit administrative ACCOUNT LOCK must prevent the account from logging in, even when the supplied password is correct and connection control is enabled.
Automatic expiration of a failed-login lock must not remove an independent administrative lock.
Both policies must be enforceable simultaneously:
- Administratively disable personal accounts when their approved one-day access period expires.
- Lock accounts after five consecutive failed-password attempts.
This must also hold if an administrator locks an account while a failed-login lock is already active: expiration of the failed-login lock must not re-enable the administratively disabled account.
❌ Actual Behavior
With the tenant configuration parameter connection_control_failed_connections_threshold set to 5, a correct-password login can automatically unlock an account that was explicitly locked by an administrator.
With the configuration parameter set to 0 and the account explicitly locked again, the same login is rejected with "User locked".
This defeats our administrative access-expiration policy: a user whose approved access has expired still knows the correct password and can regain access after ACCOUNT LOCK.
This is not a password-authentication bypass: the observed automatic unlock requires a correct password.
Sanitized audit evidence
The original incident contained the following audit characteristics (the username has been replaced):
QUERY_SQL: ALTER USER 'example_personal_user'@'%' ACCOUNT UNLOCK
USER_NAME: root
IS_INNER_SQL: 1
CLIENT_IP: 0.0.0.0
CLIENT_PORT: 0
USER_GROUP: 12
RET_CODE: 0Source analysis
The following analysis is based on the locally available oceanbase-4.4.2_CE_BP1 source tree. Maintainers should verify it against the exact affected build.
File: src/observer/mysql/obmp_connect.cpp
When check_user_access() returns OB_ERR_USER_IS_LOCKED in MySQL mode, the connection handler calls unlock_user_if_time_is_up_mysql().
is_connection_control_enabled() reads the tenant configuration parameter, rather than the same-named system variable, and enables this path when the threshold is greater than zero.
get_connection_control_stat_mysql() initializes its output lock state to false. If the failed-login count is below the threshold, it leaves that output false without evaluating a waiting period.
unlock_user_if_time_is_up_mysql() interprets this false result as permission to unlock the account. It calls switch_lock_status_for_user(..., MYSQL_MODE, false), without checking whether the lock was imposed administratively.
switch_lock_status_for_user() constructs and executes ALTER USER ... ACCOUNT UNLOCK using the internal SQL proxy.
The connection handler then refreshes schema information and retries authentication within the same connection attempt.
The apparent semantic problem is that "not currently within the failed-login lock window" is treated as "the account may be unlocked." These are not equivalent for an administratively locked account.
Simply increasing the connection delay does not address the below-threshold path. Likewise, checking only whether the failure count reached the threshold would not protect an administrative lock imposed while a failed-login lock is already active.
Could you confirm whether this is a known issue and identify an applicable fix or supported workaround that preserves both policies?
Source: oceanbase/oceanbase