Skip to content

Commit c20c1c6

Browse files
WL#8885: Introduce a delay in authentication process
based on successive failed login attempts Description: This patch introduces a new audit plugin named connection_control. Using this plugin, it is possible to introduce an incremental delay in server response if consecutive failed login attempts for a given user account crosses user defined threshold value. It is possible to configure threshold value to trigger delay, minimum/maximum amount of delay through system variables introduced by connection_control plugin. This patch also introduces a new information schema view through an information schema plugin, connection_control_failed_attempts_view. This view provides information about consecutive failed attempts for various user account.
1 parent a990191 commit c20c1c6

File tree

55 files changed

+5401
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+5401
-8
lines changed

mysql-test/include/plugin.defs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ innodb_engine plugin/innodb_memcached/innodb_memcache INNODB_ENGINE
4747
validate_password plugin/password_validation VALIDATE_PASSWORD validate_password
4848
mysql_no_login plugin/mysql_no_login MYSQL_NO_LOGIN mysql_no_login
4949
test_udf_services plugin/udf_services TESTUDFSERVICES
50+
connection_control plugin/connection_control CONNECTION_CONTROL_PLUGIN connection_control

mysql-test/mysql-test-run.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ END
163163

164164
# If you add a new suite, please check TEST_DIRS in Makefile.am.
165165
#
166-
my $DEFAULT_SUITES= "main,sys_vars,binlog,federated,rpl,innodb,innodb_fts,innodb_zip,perfschema,funcs_1,opt_trace,parts,auth_sec";
166+
my $DEFAULT_SUITES= "main,sys_vars,binlog,federated,rpl,innodb,innodb_fts,innodb_zip,perfschema,funcs_1,opt_trace,parts,auth_sec,connection_control";
167167
my $opt_suites;
168168

169169
our $opt_verbose= 0; # Verbose output, enable with --verbose
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Following variables should be set:
2+
# $USER Name of the user
3+
# $PASSWORD Password to be supplied
4+
# $SUCCESS Whether a successful connection is expected or not
5+
# $DELAY_STATS Expected value of Connection_control_delay_generated
6+
# $USE_AUTH_PLUGIN Whether an authentication plugin is to be used or not
7+
# $CLIENT_AUTH_PLUGIN Authentication plugin
8+
9+
connection default;
10+
disable_query_log;
11+
disable_result_log;
12+
13+
if ($SUCCESS == 0)
14+
{
15+
--echo # Connection attempt should fail.
16+
if ($USE_AUTH_PLUGIN == 0)
17+
{
18+
--error 1
19+
--exec $MYSQL -u$USER -p$PASSWORD -e "SELECT 1;" 2>&1
20+
}
21+
if ($USE_AUTH_PLUGIN == 1)
22+
{
23+
--error 1
24+
--exec $MYSQL -u$USER $CLIENT_AUTH_PLUGIN -p$PASSWORD -e "SELECT 1;" 2>&1
25+
}
26+
}
27+
28+
if ($SUCCESS != 0)
29+
{
30+
--echo # Connection attempt should succeed.
31+
if ($USE_AUTH_PLUGIN == 0)
32+
{
33+
--exec $MYSQL -u$USER -p$PASSWORD -e "SELECT 1;" 2>&1
34+
}
35+
if ($USE_AUTH_PLUGIN == 1)
36+
{
37+
--exec $MYSQL -u$USER $CLIENT_AUTH_PLUGIN -p$PASSWORD -e "SELECT 1;" 2>&1
38+
}
39+
}
40+
41+
enable_result_log;
42+
--echo Connection_control_delay_generated should be $DELAY_STATS
43+
SHOW STATUS LIKE 'Connection_control_delay_generated';
44+
enable_query_log;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
disable_query_log;
2+
disable_result_log;
3+
# Revoke proxy grants
4+
REVOKE PROXY ON proxied@localhost FROM u1@localhost, u2@localhost, u3@localhost;
5+
6+
# Drop proxy users
7+
DROP USER u1@localhost, u2@localhost, u3@localhost;
8+
9+
# Drop proxied user
10+
DROP USER proxied@localhost;
11+
12+
# Uninstall test_plugin_server
13+
UNINSTALL PLUGIN test_plugin_server;
14+
15+
# Remove plugin library
16+
let $auth_plugin_path= `SELECT SUBSTR('$PLUGIN_AUTH_OPT/$PLUGIN_AUTH', 14)`;
17+
let $connection_control_plugin_path= `SELECT SUBSTR('$CONNECTION_CONTROL_PLUGIN_OPT/$PLUGIN_AUTH', 14)`;
18+
19+
if ($auth_plugin_path != $connection_control_plugin_path)
20+
{
21+
--remove_file $connection_control_plugin_path
22+
}
23+
enable_result_log;
24+
enable_query_log;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
disable_query_log;
2+
#
3+
# Check if server has support for loading plugin
4+
#
5+
if (`SELECT @@have_dynamic_loading != 'YES'`) {
6+
--skip The connection_control plugin requires dynamic loading
7+
}
8+
9+
#
10+
# Check if the variable CONNECTION_CONTROL_PLUGIN is set
11+
#
12+
if (!$CONNECTION_CONTROL_PLUGIN) {
13+
--skip The connection_control plugin requires the environment variable \$CONNECTION_CONTROL_PLUGIN to be set (normally done by mtr)
14+
}
15+
16+
#
17+
# Check if --plugin-dir was setup for null_audit_db
18+
#
19+
if (`SELECT CONCAT('--plugin-dir=', REPLACE(@@plugin_dir, '\\\\', '/')) != '$CONNECTION_CONTROL_PLUGIN_OPT/'`) {
20+
--skip The connection_control plugin requires that --plugin-dir is set to the connection_control plugin dir (either the .opt file does not contain \$CONNECTION_CONTROL_PLUGIN_OPT or another plugin is in use)
21+
}
22+
enable_query_log;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
disable_query_log;
2+
#
3+
# Check if server has support for loading plugin
4+
#
5+
if (`SELECT @@have_dynamic_loading != 'YES'`) {
6+
--skip The connection_control plugin requires dynamic loading
7+
}
8+
9+
#
10+
# Check if the variable PLUGIN_AUTH is set
11+
#
12+
if (!$PLUGIN_AUTH) {
13+
--skip The connection_control plugin requires the environment variable \$PLUGIN_AUTH to be set (normally done by mtr)
14+
}
15+
16+
enable_query_log;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Install connection_control plugin
2+
--replace_result $CONNECTION_CONTROL_PLUGIN CONNECTION_CONTROL_LIB
3+
eval INSTALL PLUGIN connection_control SONAME '$CONNECTION_CONTROL_PLUGIN';
4+
--replace_result $CONNECTION_CONTROL_PLUGIN CONNECTION_CONTROL_LIB
5+
eval INSTALL PLUGIN connection_control_failed_login_attempts SONAME '$CONNECTION_CONTROL_PLUGIN';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# set after marker
2+
# $SERVER_RESPONSE_TIME [IN] Expected delay
3+
disable_query_log;
4+
disable_result_log;
5+
SET @after= TIMESTAMP(current_time());
6+
SET @server_response_time= TIMESTAMPDIFF(SECOND, @before, @after);
7+
enable_result_log;
8+
9+
--eval SELECT @server_response_time >= $SERVER_RESPONSE_TIME
10+
enable_query_log;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Set before marker
2+
disable_query_log;
3+
disable_result_log;
4+
SET @before= TIMESTAMP(current_time());
5+
enable_result_log;
6+
enable_query_log;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
disable_query_log;
2+
disable_result_log;
3+
# Copy PLUGIN_AUTH library to CONNECTION_CONTROL_OPT location
4+
let $auth_plugin_path= `SELECT SUBSTR('$PLUGIN_AUTH_OPT/$PLUGIN_AUTH', 14)`;
5+
let $connection_control_plugin_path= `SELECT SUBSTR('$CONNECTION_CONTROL_PLUGIN_OPT/$PLUGIN_AUTH', 14)`;
6+
7+
if ($auth_plugin_path != $connection_control_plugin_path)
8+
{
9+
--error 0, 1
10+
--remove_file $connection_control_plugin_path
11+
--copy_file $auth_plugin_path $connection_control_plugin_path
12+
}
13+
# Install test_plugin_server
14+
eval INSTALL PLUGIN test_plugin_server SONAME '$PLUGIN_AUTH';
15+
16+
# Create proxied@localhost
17+
CREATE USER proxied@localhost IDENTIFIED BY 'proxied_password';
18+
19+
# Create u1@localhost, u2@localhost, u3@localhst
20+
CREATE USER u1@localhost IDENTIFIED WITH test_plugin_server AS 'proxied';
21+
CREATE USER u2@localhost IDENTIFIED WITH test_plugin_server AS 'proxied';
22+
CREATE USER u3@localhost IDENTIFIED WITH test_plugin_server AS 'proxied';
23+
24+
GRANT PROXY ON proxied@localhost TO u1@localhost, u2@localhost, u3@localhost;
25+
enable_result_log;
26+
enable_query_log;

0 commit comments

Comments
 (0)