您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Mysql:来源于Mariadb的【审计】插件:server_audit

bubuko 2022/1/25 20:05:40 mysql 字数 36376 阅读 748 来源 http://www.bubuko.com/infolist-5-1.html

一:直接从mariadb的GA版本中提取server_audit{.so|.dll},根据测试,不支持 Mysql 8+ 主要的、最近的版本 都已经是 1.4.4+: 完整的功能了。 CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML, QUERY_DCL, QU ...

一:直接从mariadb的GA版本中提取server_audit{.so|.dll},根据测试,不支持 Mysql 8+

  主要的、最近的版本 都已经是 1.4.4+: 完整的功能了。

    CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML, QUERY_DCL, QUERY_DML_NO_SELECT    (MariaDB Audit Plugin >= 1.4.4)

二:根据测试,Mysql可以通过--plugin-load选项加载; 通过install plugin方式加载在重启mysqld服务器后会出现问题!

三:基本配置

plugin-load=server_audit=server_audit.dll
server_audit=force_plus_permanent
server_audit_logging=on
server_audit_output_type=file
server_audit_file_path=d:/server_audit.log
server_audit_file_rotate_size=1024024024
server_audit_query_log_limit=2048

 

四:参考资料

A full list of related system variables is detailed on the Server_Audit System Variables page, and status variables on the Server_Audit Status Variables page of this documentation. Some of the major ones are highlighted below:

Type Description Introduced
CONNECT Connects, disconnects and failed connects—including the error code  
QUERY Queries executed and their results in plain text, including failed queries due to syntax or permission errors  
TABLE Tables affected by query execution  
QUERY_DDL Same as QUERY, but filters only DDL-type queries (CREATE, ALTER, DROP, RENAME and TRUNCATE statements—except CREATE/DROP [PROCEDURE / FUNCTION / USER] and RENAME USER (they‘re not DDL) MariaDB 5.5.42. MariaDB 10.0.17, MariaDB 10.1.4
QUERY_DML Same as QUERY, but filters only DML-type queries (DO, CALL, LOAD DATA/XML, DELETE, INSERT, SELECT, UPDATE, HANDLER and REPLACE statements) MariaDB 5.5.42, MariaDB 10.0.17, MariaDB 10.1.4
QUERY_DML_NO_SELECT Same as QUERY_DML, but doesn‘t log SELECT queries. (since version 1.4.4) (DO, CALL, LOAD DATA/XML, DELETE, INSERT, UPDATE, HANDLER and REPLACE statements) MariaDB 5.5.42, MariaDB 10.0.17, MariaDB 10.1.4
QUERY_DCL Same as QUERY, but filters only DCL-type queries (CREATE USER, DROP USER, RENAME USER, GRANT, REVOKE and SET PASSWORD statements) MariaDB 5.5.43, MariaDB 10.0.18, MariaDB 10.1.5

Since there are other types of queries besides DDL and DML, using the QUERY_DDL and QUERY_DML options together is not equivalent to using QUERY. Starting in version 1.3.0 of the Audit Plugin, there is the QUERY_DCL option for logging DCL types of queries (e.g., GRANT and REVOKE statements). In the same version, the server_audit_query_log_limit variable was added to be able to set the length of a log record. Previously, a log entry would be truncated due to long query strings.

  • CONNECT, QUERY, TABLE (MariaDB Audit Plugin < 1.2.0)
  • CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML (MariaDB Audit Plugin >= 1.2.0)
  • CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML, QUERY_DCL (MariaDB Audit Plugin >=1.3.0)
  • CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML, QUERY_DCL, QUERY_DML_NO_SELECT (MariaDB Audit Plugin >= 1.4.4)
  • See MariaDB Audit Plugin - Versions to determine which MariaDB releases contain each MariaDB Audit Plugin versions.

MariaDB Audit Plugin - Versions

Below is a list of the releases of the MariaDB Audit Plugin, the most recent version first, and in which versions of MariaDB each plugin version was included.

Version Introduced
1.4.7 MariaDB 10.1.41, MariaDB 10.2.26, MariaDB 10.3.17, MariaDB 10.4.7
1.4.5 MariaDB 10.2.24, MariaDB 10.3.15, MariaDB 10.4.5
1.4.4 MariaDB 5.5.61, MariaDB 10.0.36, MariaDB 10.1.34, MariaDB 10.2.15, MariaDB 10.3.7, MariaDB 10.4.0
1.4.0 MariaDB 5.5.48, MariaDB 10.0.24, MariaDB 10.1.11
1.3.0 MariaDB 5.5.43, MariaDB 10.0.18, MariaDB 10.1.5
1.2.0 MariaDB 5.5.42, MariaDB 10.0.17, MariaDB 10.1.4
1.1.7 MariaDB 5.5.38, MariaDB 10.0.11, MariaDB 10.1.0
1.1.6 MariaDB 5.5.37, MariaDB 10.0.10
1.1.5 MariaDB 10.0.09
1.1.4 MariaDB 5.5.36
1.1.3 MariaDB 5.5.34, MariaDB 10.0.7

MariaDB Audit Plugin Options and System Variables

There are a several options and system variables related to the MariaDB Audit Plugin, once it has been installed. System variables can be displayed using the SHOW VARIABLES statement like so:

SHOW GLOBAL VARIABLES LIKE ‘%server_audit%‘;

+-------------------------------+-----------------------+
| Variable_name                 | Value                 |
+-------------------------------+-----------------------+
| server_audit_events           | CONNECT,QUERY,TABLE   |
| server_audit_excl_users       |                       |
| server_audit_file_path        | server_audit.log      |
| server_audit_file_rotate_now  | OFF                   |
| server_audit_file_rotate_size | 1000000               |
| server_audit_file_rotations   | 9                     |
| server_audit_incl_users       |                       |
| server_audit_logging          | ON                    |
| server_audit_mode             | 0                     |
| server_audit_output_type      | file                  |
| server_audit_query_log_limit  | 1024                  |
| server_audit_syslog_facility  | LOG_USER              |
| server_audit_syslog_ident     | mysql-server_auditing |
| server_audit_syslog_info      |                       |
| server_audit_syslog_priority  | LOG_INFO              |
+-------------------------------+-----------------------+

To change the value of one of these variables, you can use the SET statement, or set them at the command-line when starting MariaDB. It‘s recommended that you set them in the MariaDB configuration for the server like so:

[mariadb]
...
server_audit_excl_users=‘bob,ted‘
...

System Variables

Below is a list of all system variables related to the Audit Plugin. See Server System Variables for a complete list of system variables and instructions on setting them. See also the full list of MariaDB options, system and status variables.

server_audit_events

  • Description: If set, then this restricts audit logging to certain event types. If not set, then every event type is logged to the audit log. For example: SET GLOBAL server_audit_events=‘connect, query‘
  • Commandline: --server-audit-events=value
  • Scope: Global
  • Dynamic: Yes
  • Data Type: string
  • Default Value: Empty string
  • Valid Values:
    • CONNECT, QUERY, TABLE (MariaDB Audit Plugin < 1.2.0)
    • CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML (MariaDB Audit Plugin >= 1.2.0)
    • CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML, QUERY_DCL (MariaDB Audit Plugin >=1.3.0)
    • CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML, QUERY_DCL, QUERY_DML_NO_SELECT (MariaDB Audit Plugin >= 1.4.4)
    • See MariaDB Audit Plugin - Versions to determine which MariaDB releases contain each MariaDB Audit Plugin versions.

server_audit_excl_users

  • Description: If not empty, it contains the list of users whose activity will NOT be logged. For example: SET GLOBAL server_audit_excl_users=‘user_foo, user_bar‘. CONNECT records aren‘t affected by this variable - they are always logged. The user is still logged if it‘s specified in server_audit_incl_users.
  • Commandline: --server-audit-excl-users=value
  • Scope: Global
  • Dynamic: Yes
  • Data Type: string
  • Default Value: Empty string
  • Size limit: 1024 characters

server_audit_file_path

  • Description: When server_audit_output_type=file, sets the path and the filename to the log file. If the specified path exists as a directory, then the log will be created inside that directory with the name ‘server_audit.log‘. Otherwise the value is treated as a filename. The default value is ‘server_audit.log‘, which means this file will be created in the database directory.
  • Commandline: --server-audit-file-path=value
  • Scope: Global
  • Dynamic: Yes
  • Data Type: string
  • Default Value: server_audit.log

server_audit_file_rotate_now

  • Description: When server_audit_output_type=file, the user can force the log file rotation by setting this variable to ON or 1.
  • Commandline: --server-audit-rotate-now[={0|1}]
  • Scope: Global
  • Dynamic: Yes
  • Data Type: boolean
  • Default Value: OFF

server_audit_file_rotate_size

  • Description: When server_audit_output_type=file, it limits the size of the log file. Reaching that limit turns on the rotation - the current log file is renamed as ‘file_path.1‘. The empty log file is created as ‘file_path‘ to log into it. The default value is 1000000.
  • Commandline: --server-audit-rotate-size=#
  • Scope: Global
  • Dynamic: Yes
  • Data Type: numeric
  • Default Value: 1000000

server_audit_file_rotations

  • Description: When server_audit_output_type=file‘, this specifies the number of rotations to save. If set to 0 then the log never rotates. The default value is 9.
  • Commandline: --server-audit-rotations=#
  • Scope: Global
  • Dynamic: Yes
  • Data Type: numeric
  • Default Value: 9
  • Range: 0 to 999

server_audit_incl_users

  • Description: If not empty, it contains a comma-delimited list of users whose activity will be logged. For example: SET GLOBAL server_audit_incl_users=‘user_foo, user_bar‘. CONNECT records aren‘t affected by this variable - they are always logged. This setting has higher priority than server_audit_excl_users. So if the same user is specified both in incl_ and excl_ lists, they will still be logged.
  • Commandline: --server-audit-incl-users=value
  • Scope: Global
  • Dynamic: Yes
  • Data Type: string
  • Default Value: Empty string
  • Size limit: 1024 characters

server_audit_loc_info


server_audit_logging

  • Description: Enables/disables the logging. Expected values are ON/OFF. For example: SET GLOBAL server_audit_logging=on If the server_audit_output_type is FILE, this will actually create/open the logfile so the server_audit_file_path should be properly specified beforehand. Same about the SYSLOG-related parameters. The logging is turned off by default.
  • Commandline: --server-audit-logging[={0|1}]
  • Scope: Global
  • Dynamic: Yes
  • Data Type: boolean
  • Default Value: OFF

server_audit_mode

  • Description: This variable doesn‘t have any distinctive meaning for a user. Its value mostly reflects the server version with which the plugin was started and is intended to be used by developers for testing.
  • Commandline: --server-audit-mode[=#]

server_audit_output_type

  • Description: Specifies the desired output type. Can be SYSLOG or FILE. For example: SET GLOBAL server_audit_output_type=file file: log records will be saved into the rotating log file. The name of the file set by server_audit_file_path variable. syslog: log records will be sent to the local syslogd daemon with the standard <syslog.h> API. The default value is ‘file‘.
  • Commandline: --server-audit-output-type=value
  • Scope: Global
  • Dynamic: Yes
  • Data Type: enum
  • Default Value: file
  • Valid Values: SYSLOG or FILE

server_audit_query_log_limit

  • Description: Limit on the length of the query string in a record.
  • Commandline: --server-audit-query-log-limit=#
  • Scope: Global
  • Dynamic: Yes
  • Data Type: numeric
  • Default Value: 1024
  • Range: 0 to 2147483647
  • Introduced: MariaDB 5.5.43, MariaDB 10.0.18, MariaDB 10.1.5

server_audit_syslog_facility

  • Description: SYSLOG-mode variable. It defines the ‘facility‘ of the records that will be sent to the syslog. Later the log can be filtered by this parameter.
  • Commandline: --server-audit-syslog-facility=value
  • Scope: Global
  • Dynamic: Yes
  • Data Type: enum
  • Default Value: LOG_USER
  • Valid Values: LOG_USER, LOG_MAIL, LOG_DAEMON, LOG_AUTH, LOG_SYSLOG, LOG_LPR, LOG_NEWS, LOG_UUCP, LOG_CRON, LOG_AUTHPRIV, LOG_FTP, and LOG_LOCAL0LOG_LOCAL7.

server_audit_syslog_ident

  • Description: SYSLOG-mode variable. String value for the ‘ident‘ part of each syslog record. Default value is ‘mysql-server_auditing‘. New value becomes effective only after restarting the logging.
  • Commandline: --server-audit-syslog-ident=value
  • Scope: Global
  • Dynamic: Yes
  • Data Type: string
  • Default Value: mysql-server_auditing

server_audit_syslog_info

  • Description: SYSLOG-mode variable. The ‘info‘ string to be added to the syslog records. Can be changed any time.
  • Commandline: --server-audit-syslog-info=value
  • Scope: Global
  • Dynamic: Yes
  • Data Type: string
  • Default Value: Empty string

server_audit_syslog_priority

  • Description: SYSLOG-mode variable. Defines the priority of the log records for the syslogd.
  • Commandline: --server-audit-syslog-priority=value
  • Scope: Global
  • Dynamic: Yes
  • Data Type: enum
  • Default Value: LOG_INFO
  • Valid Values:LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG

Options

server_audit

  • Description: Controls how the server should treat the plugin when the server starts up.
  • Commandline: --server-audit=val
  • Data Type: enumerated
  • Default Value: ON
  • Valid Values: OFF, ON, FORCE, FORCE_PLUS_PERMANENT

 

Mysql:来源于Mariadb的【审计】插件:server_audit

原文:https://www.cnblogs.com/jinzhenshui/p/12493569.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶