The following sections provide a reference to MySQL Enterprise Firewall elements:
MySQL Enterprise Firewall maintains profile information on a per-group and
per-account basis, using tables in the firewall database for
persistent storage and Information Schema and Performance
Schema tables to provide views into in-memory cached data.
When enabled, the firewall bases operational decisions on the
cached data. The firewall database can be the
mysql system database or a custom schema
(see Installing MySQL Enterprise Firewall).
Tables in the firewall database are covered in this section. For information about MySQL Enterprise Firewall Information Schema and Performance Schema tables, see Section 28.7, “INFORMATION_SCHEMA MySQL Enterprise Firewall Tables”, and Section 29.12.17, “Performance Schema Firewall Tables”, respectively.
Firewall Group Profile Tables
MySQL Enterprise Firewall maintains group profile information using tables in the
firewall database (mysql or custom) for
persistent storage and Performance Schema tables to provide
views into in-memory cached data.
Each system and Performance Schema table is accessible only by
accounts that have the SELECT
privilege for it.
The
table lists names and operational modes of registered firewall
group profiles. The table has the following columns (with the
corresponding Performance Schema
firewall-database.firewall_groupsfirewall_groups table having
similar but not necessarily identical columns):
NAMEThe group profile name.
MODEThe current operational mode for the profile. Permitted mode values are
OFF,DETECTING,PROTECTING, andRECORDING. For details about their meanings, see Firewall Concepts.USERHOSTThe training account for the group profile, to be used when the profile is in
RECORDINGmode. The value isNULL, or a non-NULLaccount that has the format:user_name@host_nameIf the value is
NULL, the firewall records allowlist rules for statements received from any account that is a member of the group.If the value is non-
NULL, the firewall records allowlist rules only for statements received from the named account (which should be a member of the group).
The
table lists allowlist rules of registered firewall group
profiles. The table has the following columns (with the
corresponding Performance Schema
firewall-database.firewall_group_allowlistfirewall_group_allowlist table
having similar but not necessarily identical columns):
NAMEThe group profile name.
RULEA normalized statement indicating an acceptable statement pattern for the profile. A profile allowlist is the union of its rules.
IDAn integer column that is a primary key for the table.
The
table lists the members (accounts) of registered firewall
group profiles. The table has the following columns (with the
corresponding Performance Schema
firewall-database.firewall_membershipfirewall_membership table having
similar but not necessarily identical columns):
GROUP_IDThe group profile name.
MEMBER_IDThe name of an account that is a member of the profile.
Firewall Account Profile Tables
MySQL Enterprise Firewall maintains account profile information using tables in
the firewall database for persistent storage and
INFORMATION_SCHEMA tables to provide views
into in-memory cached data. The firewall database can be the
mysql system database or a custom schema
(see Installing MySQL Enterprise Firewall).
Each default database table is accessible only by accounts
that have the SELECT privilege
for it. The INFORMATION_SCHEMA tables are
accessible by anyone.
These tables are deprecated, and subject to removal in a future MySQL version. See Migrating Account Profiles to Group Profiles.
The
table lists names and operational modes of registered firewall
account profiles. The table has the following columns (with
the corresponding
firewall-database.firewall_usersMYSQL_FIREWALL_USERS table having
similar but not necessarily identical columns):
USERHOSTThe account profile name. Each account name has the format
.user_name@host_nameMODEThe current operational mode for the profile. Permitted mode values are
OFF,DETECTING,PROTECTING,RECORDING, andRESET. For details about their meanings, see Firewall Concepts.
The
table lists allowlist rules of registered firewall account
profiles. The table has the following columns (with the
corresponding
firewall-database.firewall_whitelistMYSQL_FIREWALL_WHITELIST table
having similar but not necessarily identical columns):
USERHOSTThe account profile name. Each account name has the format
.user_name@host_nameRULEA normalized statement indicating an acceptable statement pattern for the profile. A profile allowlist is the union of its rules.
IDAn integer column that is a primary key for the table.
MySQL Enterprise Firewall stored procedures perform tasks such as registering profiles with the firewall, establishing their operational mode, and managing transfer of firewall data between the cache and persistent storage. These procedures invoke administrative functions that provide an API for lower-level tasks.
Firewall stored procedures are created in the firewall
database. The firewall database can be the
mysql system database or a custom schema
(see Installing MySQL Enterprise Firewall).
To invoke a firewall stored procedure, either do so while the
specified firewall database is the default database, or
qualify the procedure name with the database name. For
example, if mysql is the firewall database:
CALL mysql.sp_set_firewall_group_mode(group, mode);In MySQL 8.4, firewall stored procedures are transactional; if an error occurs during execution of a firewall stored procedure, all changes made by it up to that point are rolled back, and an error is reported.
If you have installed MySQL Enterprise Firewall in a custom schema, then make
appropriate substitution for your system. For example, if
the firewall is installed in the fwdb
schema, then execute the stored procedures like this:
CALL fwdb.sp_set_firewall_group_mode(group, mode);
Firewall Group Profile Stored Procedures
These stored procedures perform management operations on firewall group profiles:
sp_firewall_group_delist(group,user)This stored procedure removes an account from a firewall group profile.
If the call succeeds, the change in group membership is made to both the in-memory cache and persistent storage.
Arguments:
group: The name of the affected group profile.user: The account to remove, as a string informat.user_name@host_name
Example:
CALL mysql.sp_firewall_group_delist('g', 'fwuser@localhost');sp_firewall_group_enlist(group,user)This stored procedure adds an account to a firewall group profile. It is not necessary to register the account itself with the firewall before adding the account to the group.
If the call succeeds, the change in group membership is made to both the in-memory cache and persistent storage.
Arguments:
group: The name of the affected group profile.user: The account to add, as a string informat.user_name@host_name
Example:
CALL mysql.sp_firewall_group_enlist('g', 'fwuser@localhost');sp_reload_firewall_group_rules(group)This stored procedure provides control over firewall operation for individual group profiles. The procedure uses firewall administrative functions to reload the in-memory rules for a group profile from the rules stored in the
table.firewall-database.firewall_group_allowlistArguments:
group: The name of the affected group profile.
Example:
CALL mysql.sp_reload_firewall_group_rules('myapp');WarningThis procedure clears the group profile in-memory allowlist rules before reloading them from persistent storage, and sets the profile mode to
OFF. If the profile mode was notOFFprior to thesp_reload_firewall_group_rules()call, usesp_set_firewall_group_mode()to restore its previous mode after reloading the rules. For example, if the profile was inPROTECTINGmode, that is no longer true after callingsp_reload_firewall_group_rules()and you must set it toPROTECTINGagain explicitly.sp_set_firewall_group_mode(group,mode)This stored procedure establishes the operational mode for a firewall group profile, after registering the profile with the firewall if it was not already registered. The procedure also invokes firewall administrative functions as necessary to transfer firewall data between the cache and persistent storage. This procedure may be called even if the
mysql_firewall_modesystem variable isOFF, although setting the mode for a profile has no operational effect until the firewall is enabled.If the profile previously existed, any recording limitation for it remains unchanged. To set or clear the limitation, call
sp_set_firewall_group_mode_and_user()instead.Arguments:
group: The name of the affected group profile.mode: The operational mode for the profile, as a string. Permitted mode values areOFF,DETECTING,PROTECTING, andRECORDING. For details about their meanings, see Firewall Concepts.
Example:
CALL mysql.sp_set_firewall_group_mode('myapp', 'PROTECTING');sp_set_firewall_group_mode_and_user(group,mode,user)This stored procedure registers a group with the firewall and establishes its operational mode, similar to
sp_set_firewall_group_mode(), but also specifies the training account to be used when the group is inRECORDINGmode.Arguments:
group: The name of the affected group profile.mode: The operational mode for the profile, as a string. Permitted mode values areOFF,DETECTING,PROTECTING, andRECORDING. For details about their meanings, see Firewall Concepts.user: The training account for the group profile, to be used when the profile is inRECORDINGmode. The value isNULL, or a non-NULLaccount that has the format:user_name@host_nameIf the value is
NULL, the firewall records allowlist rules for statements received from any account that is a member of the group.If the value is non-
NULL, the firewall records allowlist rules only for statements received from the named account (which should be a member of the group).
Example:
CALL mysql.sp_set_firewall_group_mode_and_user('myapp', 'RECORDING', 'myapp_user1@localhost');
Firewall Account Profile Stored Procedures
These stored procedures perform management operations on firewall account profiles:
sp_reload_firewall_rules(user)This stored procedure provides control over firewall operation for individual account profiles. The procedure uses firewall administrative functions to reload the in-memory rules for an account profile from the rules stored in the
table.firewall-database.firewall_whitelistArguments:
user: The name of the affected account profile, as a string informat.user_name@host_name
Example:
CALL sp_reload_firewall_rules('fwuser@localhost');WarningThis procedure clears the account profile in-memory allowlist rules before reloading them from persistent storage, and sets the profile mode to
OFF. If the profile mode was notOFFprior to thesp_reload_firewall_rules()call, usesp_set_firewall_mode()to restore its previous mode after reloading the rules. For example, if the profile was inPROTECTINGmode, that is no longer true after callingsp_reload_firewall_rules()and you must set it toPROTECTINGagain explicitly.This procedure is deprecated, and subject to removal in a future MySQL version. See Migrating Account Profiles to Group Profiles.
sp_set_firewall_mode(user,mode)This stored procedure establishes the operational mode for a firewall account profile, after registering the profile with the firewall if it was not already registered. The procedure also invokes firewall administrative functions as necessary to transfer firewall data between the cache and persistent storage. This procedure may be called even if the
mysql_firewall_modesystem variable isOFF, although setting the mode for a profile has no operational effect until the firewall is enabled.Arguments:
user: The name of the affected account profile, as a string informat.user_name@host_namemode: The operational mode for the profile, as a string. Permitted mode values areOFF,DETECTING,PROTECTING,RECORDING, andRESET. For details about their meanings, see Firewall Concepts.
Switching an account profile to any mode but
RECORDINGsynchronizes its firewall cache data to the firewall database tables that provide persistent underlying storage (mysqlor custom). Switching the mode fromOFFtoRECORDINGreloads the allowlist from thetable into the cache.firewall-database.firewall_whitelistIf an account profile has an empty allowlist, its mode cannot be set to
PROTECTINGbecause the profile would reject every statement, effectively prohibiting the account from executing statements. In response to such a mode-setting attempt, the firewall produces a diagnostic message that is returned as a result set rather than as an SQL error:mysql> CALL sp_set_firewall_mode('a@b','PROTECTING'); +----------------------------------------------------------------------+ | set_firewall_mode(arg_userhost, arg_mode) | +----------------------------------------------------------------------+ | ERROR: PROTECTING mode requested for a@b but the allowlist is empty. | +----------------------------------------------------------------------+This procedure is deprecated, and subject to removal in a future MySQL version. See Migrating Account Profiles to Group Profiles.
Firewall Miscellaneous Stored Procedures
These stored procedures perform miscellaneous firewall management operations.
sp_migrate_firewall_user_to_group(user,group)The
sp_migrate_firewall_user_to_group()stored procedure converts a firewall account profile to a group profile with the account as its single enlisted member. Run thefirewall_profile_migration.sqlscript to install it. The conversion procedure is discussed in Migrating Account Profiles to Group Profiles.This routine requires the
FIREWALL_ADMINprivilege.Arguments:
user: The name of the account profile to convert to a group profile, as a string informat. The account profile must exist, and must not currently be inuser_name@host_nameRECORDINGmode.group: The name of the new group profile, which must not already exist. The new group profile has the named account as its single enlisted member, and that member is set as the group training account. The group profile operational mode is taken from the account profile operational mode.
Example:
CALL sp_migrate_firewall_user_to_group('fwuser@localhost', 'mygroup);
MySQL Enterprise Firewall administrative functions provide an API for lower-level tasks such as synchronizing the firewall cache with the underlying system tables.
Under normal operation, these functions are invoked by the firewall stored procedures, not directly by users. For that reason, these function descriptions do not include details such as information about their arguments and return types.
Firewall Group Profile Functions
These functions perform management operations on firewall group profiles:
firewall_group_delist(group,user)This function removes an account from a group profile. It requires the
FIREWALL_ADMINprivilege.Example:
SELECT firewall_group_delist('g', 'fwuser@localhost');firewall_group_enlist(group,user)This function adds an account to a group profile. It requires the
FIREWALL_ADMINprivilege.It is not necessary to register the account itself with the firewall before adding the account to the group.
Example:
SELECT firewall_group_enlist('g', 'fwuser@localhost');read_firewall_group_allowlist(group,rule)This aggregate function updates the recorded-statement cache for the named group profile through a
SELECTstatement on thetable. It requires thefirewall-database.firewall_group_allowlistFIREWALL_ADMINprivilege.Example:
SELECT read_firewall_group_allowlist('my_fw_group', fgw.rule) FROM mysql.firewall_group_allowlist AS fgw WHERE NAME = 'my_fw_group';read_firewall_groups(group,mode,user)This aggregate function updates the firewall group profile cache through a
SELECTstatement on thetable. It requires thefirewall-database.firewall_groupsFIREWALL_ADMINprivilege.Example:
SELECT read_firewall_groups('g', 'RECORDING', 'fwuser@localhost') FROM mysql.firewall_groups;set_firewall_group_mode(group,mode[,user])This function manages the group profile cache, establishes the profile operational mode, and optionally specifies the profile training account. It requires the
FIREWALL_ADMINprivilege.If the optional
userargument is not given, any previoususersetting for the profile remains unchanged. To change the setting, call the function with a third argument.If the optional
userargument is given, it specifies the training account for the group profile, to be used when the profile is inRECORDINGmode. The value isNULL, or a non-NULLaccount that has the format:user_name@host_nameIf the value is
NULL, the firewall records allowlist rules for statements received from any account that is a member of the group.If the value is non-
NULL, the firewall records allowlist rules only for statements received from the named account (which should be a member of the group).
Example:
SELECT set_firewall_group_mode('g', 'DETECTING');
Firewall Account Profile Functions
These functions perform management operations on firewall account profiles:
read_firewall_users(user,mode)This aggregate function updates the firewall account profile cache through a
SELECTstatement on thetable. It requires thefirewall-database.firewall_usersFIREWALL_ADMINprivilege or the deprecatedSUPERprivilege.Example:
SELECT read_firewall_users('fwuser@localhost', 'RECORDING') FROM mysql.firewall_users;This function is deprecated, and subject to removal in a future MySQL version. See Migrating Account Profiles to Group Profiles.
read_firewall_whitelist(user,rule)This aggregate function updates the recorded-statement cache for the named account profile through a
SELECTstatement on thetable. It requires thefirewall-database.firewall_whitelistFIREWALL_ADMINprivilege or the deprecatedSUPERprivilege.Example:
SELECT read_firewall_whitelist('fwuser@localhost', fw.rule) FROM mysql.firewall_whitelist AS fw WHERE USERHOST = 'fwuser@localhost';This function is deprecated, and subject to removal in a future MySQL version. See Migrating Account Profiles to Group Profiles.
This function manages the account profile cache and establishes the profile operational mode. It requires the
FIREWALL_ADMINprivilege or the deprecatedSUPERprivilege.Example:
SELECT set_firewall_mode('fwuser@localhost', 'RECORDING');This function is deprecated, and subject to removal in a future MySQL version. See Migrating Account Profiles to Group Profiles.
Firewall Miscellaneous Functions
These functions perform miscellaneous firewall operations:
This function resets several firewall status variables to 0:
This function requires the
FIREWALL_ADMINprivilege or the deprecatedSUPERprivilege.Example:
SELECT mysql_firewall_flush_status();This function normalizes an SQL statement into the digest form used for allowlist rules. It requires the
FIREWALL_ADMINprivilege or the deprecatedSUPERprivilege.Example:
SELECT normalize_statement('SELECT * FROM t1 WHERE c1 > 2');NoteThe same digest functionality is available outside firewall context using the
STATEMENT_DIGEST_TEXT()SQL function.
MySQL Enterprise Firewall supports the following system variables. Use them to configure firewall operation. These variables are unavailable unless the firewall is installed (see Section 8.4.7.2, “Installing or Uninstalling MySQL Enterprise Firewall”).
-
Command-Line Format --mysql-firewall-database[=value]System Variable mysql_firewall_databaseScope Global Dynamic No SET_VARHint AppliesNo Type String Default Value mysqlSpecifies the database from which MySQL Enterprise Firewall reads data. Typically, the
MYSQL_FIREWALLserver-side plugin stores its internal data (tables, stored procedures, and functions) in themysqlsystem database, but you can create and use a custom schema instead (see Installing MySQL Enterprise Firewall). This variable permits specifying an alternative database name at startup. -
Command-Line Format --mysql-firewall-mode[={OFF|ON}]System Variable mysql_firewall_modeScope Global Dynamic Yes SET_VARHint AppliesNo Type Boolean Default Value ONWhether MySQL Enterprise Firewall is enabled (the default) or disabled.
mysql_firewall_reload_interval_secondsCommand-Line Format --mysql-firewall-reload-interval-seconds[=value]System Variable mysql_firewall_reload_interval_secondsScope Global Dynamic No SET_VARHint AppliesNo Type Integer Default Value 0Minimum Value 60 (unless 0: OFF)Maximum Value INT_MAXUnit seconds Specifies the interval (in seconds) that the server-side plugin uses to reload its internal cache from firewall tables. When
mysql_firewall_reload_interval_secondshas a value of zero (the default), no periodic reloading of data from tables occurs at runtime. Values between0and60(1 to 59) are not acknowledged by the plugin. Instead, these values adjust to60automatically.This variable requires that the
schedulercomponent be enabled (ON). For more information, see Scheduling Firewall Cache Reloads.-
Command-Line Format --mysql-firewall-trace[={OFF|ON}]System Variable mysql_firewall_traceScope Global Dynamic Yes SET_VARHint AppliesNo Type Boolean Default Value OFFWhether the MySQL Enterprise Firewall trace is enabled or disabled (the default). When
mysql_firewall_traceis enabled, forPROTECTINGmode, the firewall writes rejected statements to the error log.
MySQL Enterprise Firewall supports the following status variables. Use them to
obtain information about firewall operational status. These
variables are unavailable unless the firewall is installed
(see Section 8.4.7.2, “Installing or Uninstalling MySQL Enterprise Firewall”). Firewall status
variables are set to 0 whenever the
MYSQL_FIREWALL plugin is installed or the
server is started. Many of them are reset to zero by the
mysql_firewall_flush_status()
function (see MySQL Enterprise Firewall Administrative Functions).
The number of statements rejected by MySQL Enterprise Firewall.
The number of statements accepted by MySQL Enterprise Firewall.
The number of statements logged by MySQL Enterprise Firewall as suspicious for users who are in
DETECTINGmode.The number of statements recorded by MySQL Enterprise Firewall, including duplicates.