MySQL :: MySQL 8.0 Reference Manual :: 8.4.5.11 Audit Log Reference (original) (raw)

8.4.5.11 Audit Log Reference

Audit Log Tables

MySQL Enterprise Audit uses tables in the mysql system database for persistent storage of filter and user account data. The tables can be accessed only by users who have privileges for that database. To use a different database, set the audit_log_database system variable at server startup. The tables use theInnoDB storage engine.

If these tables are missing, the audit_log plugin operates in (deprecated) legacy mode. SeeSection 8.4.5.10, “Legacy Mode Audit Log Filtering”.

The audit_log_filter table stores filter definitions. The table has these columns:

The audit_log_user table stores user account information. The table has these columns:

Audit Log Functions

This section describes, for each audit log function, its purpose, calling sequence, and return value. For information about the conditions under which these functions can be invoked, see Section 8.4.5.7, “Audit Log Filtering”.

Each audit log function returns a string that indicates whether the operation succeeded. OK indicates success. ERROR:_`message`_ indicates failure.

As of MySQL 8.0.19, audit log functions convert string arguments to utf8mb4 and string return values are utf8mb4 strings. Prior to MySQL 8.0.19, audit log functions treat string arguments as binary strings (which means they do not distinguish lettercase), and string return values are binary strings.

If an audit log function is invoked from within themysql client, binary string results display using hexadecimal notation, depending on the value of the--binary-as-hex. For more information about that option, see Section 6.5.1, “mysql — The MySQL Command-Line Client”.

These audit log functions are available:

mysql> SELECT audit_log_encryption_password_get();  
+-------------------------------------+  
| audit_log_encryption_password_get() |  
+-------------------------------------+  
| secret                              |  
+-------------------------------------+  

To retrieve a password by ID, you can determine which audit log keyring IDs exist by querying the Performance Schema keyring_keys table:

mysql> SELECT KEY_ID FROM performance_schema.keyring_keys  
       WHERE KEY_ID LIKE 'audit_log%'  
       ORDER BY KEY_ID;  
+-----------------------------+  
| KEY_ID                      |  
+-----------------------------+  
| audit_log-20190415T152248-1 |  
| audit_log-20190415T153507-1 |  
| audit_log-20190416T125122-1 |  
| audit_log-20190416T141608-1 |  
+-----------------------------+  
mysql> SELECT audit_log_encryption_password_get('audit_log-20190416T125122-1');  
+------------------------------------------------------------------+  
| audit_log_encryption_password_get('audit_log-20190416T125122-1') |  
+------------------------------------------------------------------+  
| segreto                                                          |  
+------------------------------------------------------------------+  
mysql> SELECT audit_log_encryption_password_set(password);  
+---------------------------------------------+  
| audit_log_encryption_password_set(password) |  
+---------------------------------------------+  
| 1                                           |  
+---------------------------------------------+  
mysql> SELECT audit_log_filter_flush();  
+--------------------------+  
| audit_log_filter_flush() |  
+--------------------------+  
| OK                       |  
+--------------------------+  
mysql> SELECT audit_log_filter_remove_filter('SomeFilter');  
+----------------------------------------------+  
| audit_log_filter_remove_filter('SomeFilter') |  
+----------------------------------------------+  
| OK                                           |  
+----------------------------------------------+  
mysql> SELECT audit_log_filter_remove_user('user1@localhost');  
+-------------------------------------------------+  
| audit_log_filter_remove_user('user1@localhost') |  
+-------------------------------------------------+  
| OK                                              |  
+-------------------------------------------------+  
mysql> SET @f = '{ "filter": { "log": false } }';  
mysql> SELECT audit_log_filter_set_filter('SomeFilter', @f);  
+-----------------------------------------------+  
| audit_log_filter_set_filter('SomeFilter', @f) |  
+-----------------------------------------------+  
| OK                                            |  
+-----------------------------------------------+  
mysql> SELECT audit_log_filter_set_user('user1@localhost', 'SomeFilter');  
+------------------------------------------------------------+  
| audit_log_filter_set_user('user1@localhost', 'SomeFilter') |  
+------------------------------------------------------------+  
| OK                                                         |  
+------------------------------------------------------------+  
mysql> SELECT audit_log_read(audit_log_read_bookmark());  
+-----------------------------------------------------------------------+  
| audit_log_read(audit_log_read_bookmark())                             |  
+-----------------------------------------------------------------------+  
| [ {"timestamp":"2020-05-18 22:41:24","id":0,"class":"connection", ... |  
+-----------------------------------------------------------------------+  
mysql> SELECT audit_log_read('null');  
+------------------------+  
| audit_log_read('null') |  
+------------------------+  
| null                   |  
+------------------------+  

Notes:
Prior to MySQL 8.0.19, string return values are binaryJSON strings. For information about converting such values to nonbinary strings, see Section 8.4.5.6, “Reading Audit Log Files”.

mysql> SELECT audit_log_read_bookmark();  
+-------------------------------------------------+  
| audit_log_read_bookmark()                       |  
+-------------------------------------------------+  
| { "timestamp": "2019-10-03 21:03:44", "id": 0 } |  
+-------------------------------------------------+  

Notes:
Prior to MySQL 8.0.19, string return values are binaryJSON strings. For information about converting such values to nonbinary strings, see Section 8.4.5.6, “Reading Audit Log Files”.

mysql> SELECT audit_log_rotate();  

Using audit_log_rotate() requires theAUDIT_ADMIN privilege.

Audit Log Option and Variable Reference
Audit Log Options and Variables

This section describes the command options and system variables that configure operation of MySQL Enterprise Audit. If values specified at startup time are incorrect, theaudit_log plugin may fail to initialize properly and the server does not load it. In this case, the server may also produce error messages for other audit log settings because it does not recognize them.

To configure activation of the audit log plugin, use this option:

If the audit log plugin is enabled, it exposes several system variables that permit control over logging:

mysql> SHOW VARIABLES LIKE 'audit_log%';
+--------------------------------------+--------------+
| Variable_name                        | Value        |
+--------------------------------------+--------------+
| audit_log_buffer_size                | 1048576      |
| audit_log_compression                | NONE         |
| audit_log_connection_policy          | ALL          |
| audit_log_current_session            | OFF          |
| audit_log_database                   | mysql        |
| audit_log_disable                    | OFF          |
| audit_log_encryption                 | NONE         |
| audit_log_exclude_accounts           |              |
| audit_log_file                       | audit.log    |
| audit_log_filter_id                  | 0            |
| audit_log_flush                      | OFF          |
| audit_log_flush_interval_seconds     | 0            |
| audit_log_format                     | NEW          |
| audit_log_format_unix_timestamp      | OFF          |
| audit_log_include_accounts           |              |
| audit_log_max_size                   | 0            |
| audit_log_password_history_keep_days | 0            |
| audit_log_policy                     | ALL          |
| audit_log_prune_seconds              | 0            |
| audit_log_read_buffer_size           | 32768        |
| audit_log_rotate_on_size             | 0            |
| audit_log_statement_policy           | ALL          |
| audit_log_strategy                   | ASYNCHRONOUS |
+--------------------------------------+--------------+

You can set any of these variables at server startup, and some of them at runtime. Those that are available only for legacy mode audit log filtering are so noted.

SHOW VARIABLES LIKE 'component_scheduler%';  
+-----------------------------+-------+  
| Variable_name               | Value |  
+-----------------------------+-------|  
| component_scheduler.enabled | On    |  
+-----------------------------+-------+  

Whenaudit_log_flush_interval_seconds has a value of zero (the default), no automatic refresh of the privileges occurs, even if thescheduler component is enabled (ON).
Values of 1 and 59 are not permitted; instead, these values adjusts to60 automatically and the server emits a warning. Values greater than 60 define the number of seconds the scheduler component waits from startup, or from the beginning of the previous execution, until it attempts to schedule another execution.
To persist this global system variable to themysqld-auto.cnf file without setting the global variable runtime value, precede the variable name by the PERSIST_ONLY keyword or the@@PERSIST_ONLY. qualifier.

SET GLOBAL audit_log_password_history_keep_days = 365;  
SET GLOBAL audit_log_password_history_keep_days = 0;  

Setting the runtime value ofaudit_log_password_history_keep_days requires the AUDIT_ADMIN privilege, in addition to theSYSTEM_VARIABLES_ADMIN privilege (or the deprecatedSUPER privilege) normally required to set a global system variable runtime value.

Audit Log Status Variables

If the audit log plugin is enabled, it exposes several status variables that provide operational information. These variables are available for legacy mode audit filtering (deprecated in MySQL 8.0.34) and JSON mode audit filtering.