Documentation Home
MySQL 9.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 41.2Mb
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.4 Reference Manual  / ...  / Security  / Security Components and Plugins  / Connection Control Plugins  /  Connection Control Plugin Installation

8.4.3.1 Connection Control Plugin Installation

This section describes how to install the connection control plugins,CONNECTION_CONTROL andCONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS. For general information about installing plugins, seeSection 7.6.1, “Installing and Uninstalling Plugins”.

To be usable by the server, the plugin library file must be located in the MySQL plugin directory (the directory named by theplugin_dir system variable). If necessary, configure the plugin directory location by setting the value ofplugin_dir at server startup.

The plugin library file base name isconnection_control. The file name suffix differs per platform (for example,.so for Unix and Unix-like systems,.dll for Windows).

To load the plugins at server startup, use the--plugin-load-add option to name the library file that contains them. With this plugin-loading method, the option must be given each time the server starts. For example, put these lines in the servermy.cnf file, adjusting the.so suffix for your platform as necessary:

[mysqld]plugin-load-add=connection_control.so

After modifyingmy.cnf, restart the server to cause the new settings to take effect.

Alternatively, to load the plugins at runtime, use these statements, adjusting the.so suffix for your platform as necessary:

INSTALL PLUGIN CONNECTION_CONTROL  SONAME 'connection_control.so';INSTALL PLUGIN CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS  SONAME 'connection_control.so';

INSTALL PLUGIN loads the plugin immediately, and also registers it in themysql.plugins system table to cause the server to load it for each subsequent normal startup without the need for--plugin-load-add.

To verify plugin installation, examine the Information SchemaPLUGINS table or use theSHOW PLUGINS statement (seeSection 7.6.2, “Obtaining Server Plugin Information”). For example:

mysql> SELECT PLUGIN_NAME, PLUGIN_STATUS       FROM INFORMATION_SCHEMA.PLUGINS       WHERE PLUGIN_NAME LIKE 'connection%';+------------------------------------------+---------------+| PLUGIN_NAME                              | PLUGIN_STATUS |+------------------------------------------+---------------+| CONNECTION_CONTROL                       | ACTIVE        || CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS | ACTIVE        |+------------------------------------------+---------------+

If a plugin fails to initialize, check the server error log for diagnostic messages.

If the plugins have been previously registered withINSTALL PLUGIN or are loaded with--plugin-load-add, you can use the--connection-control and--connection-control-failed-login-attempts options at server startup to control plugin activation. For example, to load the plugins at startup and prevent them from being removed at runtime, use these options:

[mysqld]plugin-load-add=connection_control.soconnection-control=FORCE_PLUS_PERMANENTconnection-control-failed-login-attempts=FORCE_PLUS_PERMANENT

If it is desired to prevent the server from running without a given connection control plugin, use an option value ofFORCE orFORCE_PLUS_PERMANENT to force server startup to fail if the plugin does not initialize successfully.

Note

It is possible to install one plugin without the other, but both must be installed for full connection control capability. In particular, installing only theCONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS plugin is of little use because, without theCONNECTION_CONTROL plugin to provide the data that populates theCONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS table, the table is always empty.

Connection Delay Configuration

To enable configuring its operation, theCONNECTION_CONTROL plugin exposes these system variables:

Ifconnection_control_failed_connections_threshold is nonzero, failed-connection counting is enabled and has these properties:

  • The delay is zero up throughconnection_control_failed_connections_threshold consecutive failed connection attempts.

  • Thereafter, the server adds an increasing delay for subsequent consecutive attempts, until a successful connection occurs. The initial unadjusted delays begin at 1000 milliseconds (1 second) and increase by 1000 milliseconds per attempt. That is, once delay has been activated for an account, the unadjusted delays for subsequent failed attempts are 1000 milliseconds, 2000 milliseconds, 3000 milliseconds, and so forth.

  • The actual delay experienced by a client is the unadjusted delay, adjusted to lie within the values of theconnection_control_min_connection_delay andconnection_control_max_connection_delay system variables, inclusive.

  • Once delay has been activated for an account, the first successful connection thereafter by the account also experiences a delay, but failure counting is reset for subsequent connections.

For example, with the defaultconnection_control_failed_connections_threshold value of 3, there is no delay for the first three consecutive failed connection attempts by an account. The actual adjusted delays experienced by the account for the fourth and subsequent failed connections depend on theconnection_control_min_connection_delay andconnection_control_max_connection_delay values:

You can set theCONNECTION_CONTROL system variables at server startup or runtime. Suppose that you want to permit four consecutive failed connection attempts before the server starts delaying its responses, with a minimum delay of 2000 milliseconds. To set the relevant variables at server startup, put these lines in the servermy.cnf file:

[mysqld]plugin-load-add=connection_control.soconnection-control-failed-connections-threshold=4connection-control-min-connection-delay=2000

To set and persist the variables at runtime, use these statements:

SET PERSIST connection_control_failed_connections_threshold = 4;SET PERSIST connection_control_min_connection_delay = 2000;

SET PERSIST sets a value for the running MySQL instance. It also saves the value, causing it to carry over to subsequent server restarts. To change a value for the running MySQL instance without having it carry over to subsequent restarts, use theGLOBAL keyword rather thanPERSIST. SeeSection 15.7.6.1, “SET Syntax for Variable Assignment”.

Theconnection_control_min_connection_delay andconnection_control_max_connection_delay system variables both have minimum and maximum values of 1000 and 2147483647. In addition, the permitted range of values of each variable also depends on the current value of the other:

Thus, to make the changes required for some configurations, you might need to set the variables in a specific order. Suppose that the current minimum and maximum delays are 1000 and 2000, and that you want to set them to 3000 and 5000. You cannot first setconnection_control_min_connection_delay to 3000 because that is greater than the currentconnection_control_max_connection_delay value of 2000. Instead, setconnection_control_max_connection_delay to 5000, then setconnection_control_min_connection_delay to 3000.

Connection Failure Assessment

When theCONNECTION_CONTROL plugin is installed, it checks connection attempts and tracks whether they fail or succeed. For this purpose, a failed connection attempt is one for which the client user and host match a known MySQL account but the provided credentials are incorrect, or do not match any known account.

Failed-connection counting is based on the user/host combination for each connection attempt. Determination of the applicable user name and host name takes proxying into account and occurs as follows:

  • If the client user proxies another user, the account for failed-connection counting is the proxying user, not the proxied user. For example, ifexternal_user@example.com proxiesproxy_user@example.com, connection counting uses the proxying user,external_user@example.com, rather than the proxied user,proxy_user@example.com. Bothexternal_user@example.com andproxy_user@example.com must have valid entries in themysql.user system table and a proxy relationship between them must be defined in themysql.proxies_priv system table (seeSection 8.2.19, “Proxy Users”).

  • If the client user does not proxy another user, but does match amysql.user entry, counting uses theCURRENT_USER() value corresponding to that entry. For example, if a useruser1 connecting from a hosthost1.example.com matches auser1@host1.example.com entry, counting usesuser1@host1.example.com. If the user matches auser1@%.example.com,user1@%.com, oruser1@% entry instead, counting usesuser1@%.example.com,user1@%.com, oruser1@%, respectively.

For the cases just described, the connection attempt matches somemysql.user entry, and whether the request succeeds or fails depends on whether the client provides the correct authentication credentials. For example, if the client presents an incorrect password, the connection attempt fails.

If the connection attempt matches nomysql.user entry, the attempt fails. In this case, noCURRENT_USER() value is available and connection-failure counting uses the user name provided by the client and the client host as determined by the server. For example, if a client attempts to connect as useruser2 from hosthost2.example.com, the user name part is available in the client request and the server determines the host information. The user/host combination used for counting isuser2@host2.example.com.

Note

The server maintains information about which client hosts can possibly connect to the server (essentially the union of host values formysql.user entries). If a client attempts to connect from any other host, the server rejects the attempt at an early stage of connection setup:

ERROR 1130 (HY000): Host 'host_name' is notallowed to connect to this MySQL server

Because this type of rejection occurs so early,CONNECTION_CONTROL does not see it, and does not count it.

Connection Failure Monitoring

To monitor failed connections, use these information sources:

Assigning a value toconnection_control_failed_connections_threshold at runtime has these effects: