数据库审计
什么是数据库审计系统
数据库审计系统是通过对所有访问数据库操作行为的审计,详细记录用户对数据库进行增删改查、查询、登录等操作行为及返回结果,通过配置安全规则实现对危险操作的实时告警和事后追溯,从而达到保护数据库安全的防护效果的审计产品。通常黑客的SQL注入攻击行为,也可以通过数据库审计发现。
数据库审计系统具备实时监测并智能地分析、还原各种数据库操作过程的功能。它还能根据设置的规则,智能地判断出违规操作数据库的行为,并对违规行为进行记录、报警,甚至阻断攻击行为。
数据库审计系统的主要价值在于:
在发生数据库安全事件(例如数据篡改、泄露)后,为事件的追责定责提供依据。
针对数据库操作的风险行为进行时时告警,帮助管理人员对用户的行为一目了然,真正做到数据库操作行为可监控,违规操作可追溯。
此外,数据库审计系统还可以帮助用户事后生成合规报告,提高数据资产安全。它是数据库安全技术之一,与数据库漏扫、数据库加密、数据库防火墙、数据脱敏等技术共同构成了数据库安全体系。
引用
https://blog.youkuaiyun.com/fullbug/article/details/136227907
MySQL审计
mysql审计功能是企业版付费功能。相关文档:
https://www.mysql.com/cn/products/enterprise/audit.html
https://dev.mysql.com/doc/refman/5.7/en/audit-log.html
其他社区的开源审计插件
- McAfee MySQL Audit Plugin
- MariaDB Audit Plugin
- Percona Audit Log Plugin
MySQL企业版
安装审计日志插件
审计插件位于plugin_dir目录,插件名为audit_log.dll或者audit_log.so
linux
mysql -u root -p < audit_log_filter_linux_install.sql
windows
mysql -u root -p < audit_log_filter_win_install.sql
验证审计插件是否安装
mysql> SELECT PLUGIN_NAME, PLUGIN_STATUS
FROM INFORMATION_SCHEMA.PLUGINS
WHERE PLUGIN_NAME LIKE 'audit%';
+-------------+---------------+
| PLUGIN_NAME | PLUGIN_STATUS |
+-------------+---------------+
| audit_log | ACTIVE |
+-------------+---------------+
激活审计插件
可以使用命令行启动参数 --audit-log或者配置文件配置。
[mysqld]
audit-log=FORCE_PLUS_PERMANENT
审计日志文件格式
支持新版xml格式、旧版xml格式、json格式
https://dev.mysql.com/doc/refman/5.7/en/audit-log-file-formats.html
环境变量配置
audit_log_format=NEW
audit_log_format=OLD
audit_log_format=JSON
McAfee MySQL Audit Plugin
https://github.com/trellix-enterprise/mysql-audit
安装插件文档
https://github.com/trellix-enterprise/mysql-audit/wiki/Installation
MariaDB Audit Plugin
插件文档
https://mariadb.com/kb/en/mariadb-audit-plugin/
github的插件
https://github.com/Vettabase/audit-plugin-for-mysql/tree/mysql-5.7
Percona Audit Log Plugin
插件下载。选择和mysql同版本
https://www.percona.com/downloads
插件文档
https://docs.percona.com/percona-server/5.7/management/audit_log_plugin.html
安装脚本
将server_audit.so上传到mysql的basedir下面的lib/plugin目录下
注意权限设置成755,注意用户和mysql服务启动用户一致
#导入插件到配置文件
vi my.cnf
plugin_load_add=server_audit
#或者直接命令导入插件
INSTALL PLUGIN server_audit SONAME 'server_audit.so';
MySQL审计事件告警
mysql没有提供审计事件告警,需要自己采集、分析审计日志并触发告警。可以使用skywalking采集审计日志并触发告警。
腾讯云MySQL
腾讯云MySQL服务提供审计日志输出,审计规则配置,审计事件告警功能。
https://cloud.tencent.com/document/product/236/81405
Yearning
MySQL SQL审核工具。主要用于生产环境通过Web界面填写SQL语句,经过管理员审核过,执行到数据库。使用go、vue编写,支持二次开发。
https://next.yearning.io/
安装
version: '3'
services:
yearning:
image: yeelabs/yearning:latest
environment:
MYSQL_USER: yearning
MYSQL_PASSWORD: ukC2ZkcG_ZTeb
MYSQL_ADDR: mysql
MYSQL_DB: yearning
SECRET_KEY: dbcjqheupqjsuwsm
IS_DOCKER: is_docker
ports:
- 8000:8000
# 首次使用请先初始化
command: /bin/bash -c "./Yearning install && ./Yearning run"
depends_on:
- mysql
restart: always
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: ukC2ZkcG_ZTeb
MYSQL_DATABASE: yearning
MYSQL_USER: yearning
MYSQL_PASSWORD: ukC2ZkcG_ZTeb
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_general_ci
volumes:
- ./data/mysql:/var/lib/mysql
restart: always
# 默认账号:admin,默认密码:Yearning_admin
docker-compose -f docker-compose.yml up -d
Elasticsearch审计
- Elasticsearch X-Pack 官方安全组件
- Search Guard 第三方安全插件
- Open Distro for Elasticsearch 亚马逊基于开源Elasticsearch开发的软件,支持告警审计等功能。由于Elasticsearch7.10.2之后,把开源协议Apache 2.0修改为SSPL,目前Open Distro for Elasticsearch只支持到7.10.2。
- OpenSearch 亚马逊开源的搜索引擎,不是基于Elasticsearch开源版本开发。
- 腾讯云Elasticsearch X-Pack
Elasticsearch X-Pack
Elasticsearch 7.0以上默认安装,无需额外安装。支持审计日志输出,配置事件日志过滤策略。以上功能需要订阅白金版Elasticsearch服务
审计日志激活
https://www.elastic.co/guide/en/elasticsearch/reference/7.14/enable-audit-logging.html
- Set xpack.security.audit.enabled to true in elasticsearch.yml.
- Restart Elasticsearch.
安全事件会被保存到_audit.json文件。
审计事件列表
https://www.elastic.co/guide/en/elasticsearch/reference/7.14/audit-event-types.html
审计事件过滤
xpack.security.audit.logfile.events.ignore_filters:
example1:
users: ["kibana_system", "admin_user"]
indices: ["app-logs*"]
审计日志采集和告警
- 采集审计日志文件,并推送到Elasticsearch(不知道是否可以通过配置log4j2.properties推送到kafka、jdbc)。通过Elasticsearch的Watcher功能,定期查询审计数据。符合告警条件并发送告警信息。(白金版)
https://www.elastic.co/guide/en/elasticsearch/reference/7.14/xpack-alerting.html - 用skywalking采集审计日志并触发告警。
Search Guard
Search Guard是第三方的Elasticsearch安全插件。支持审计日志、告警等功能。审计日志需要购买企业版license
配置审计日志
https://docs.search-guard.com/latest/audit-logging-compliance
在elasticsearch.yml文件配置
searchguard.audit.type: internal_elasticsearch
过滤审计日志种类
searchguard.audit.config.disabled_rest_categories: AUTHENTICATED, SG_INDEX_ATTEMPT
searchguard.audit.config.disabled_transport_categories: GRANTED_PRIVILEGES
配置审计日志存储类型
支持存储到自身或者外部的Elasticsearch,webhook、log4j等
https://docs.search-guard.com/latest/audit-logging-storage
debug — outputs the events to stdout.
internal_elasticsearch — writes the events to an audit index on the same Elasticsearch cluster.
external_elasticsearch — writes the events to an audit index on a remote Elasticsearch cluster.
webhook - writes the events to an arbitrary HTTP endpoint.
log4j - writes the events to a log4j logger. You can use any log4j appender like SNMP, JDBC, Cassandra, Kafka etc.
支持更细致的审计
可以对读、写数据库进行更细致的监控和审计。 以及对Search Guard、Elasticsearch的配置监控和审计,可配置不可变索引,禁止删除索引,修改和删除索引里面的文档等。
读监控 https://docs.search-guard.com/latest/compliance-read-history
写监控 https://docs.search-guard.com/latest/compliance-write-history
Search Guard配置监控 https://docs.search-guard.com/latest/configuration-integrity
Elasticsearch配置监控 https://docs.search-guard.com/latest/integrity-elasticsearch
不可变索引 https://docs.search-guard.com/latest/immutable-indices
审计日志采集和告警
审计日志可以直接保存到自身的Elasticsearch,通过Search Guard的告警模块,触发审计事件告警。Search Guard提供target为auditlog,记录审计日志时,直接查询索引并触发事件。
{
"type": "search",
"name": "Audit log events",
"target": "auditlog",
"request": {
"indices": [
"audit*"
],
"body": {
"size": 5,
"query": {
"bool": {
"must": [{
"match": {
"audit_category": {
"query": "FAILED_LOGIN"
}
}
},
{
"range": {
"@timestamp": {
"gte": "now-5m"
}
}
}
]
}
},
"aggs": {
"failed_logins": {
"terms": {
"field": "audit_request_effective_user.keyword"
}
}
}
}
}
}
Open Distro for Elasticsearch
基于开源Elasticsearch开发的软件,支持告警、审计日志等功能。由于线上Elasticsearch使用7.14,不再考虑。
https://opendistro.github.io/for-elasticsearch/
OpenSearch
基于Elasticsearch7.10版本后的独立软件。支持告警、审计日志等功能。由于不再是Elasticsearch,不再考虑。
相关文档
https://opensearch.org/docs/latest/security/audit-logs/index/
腾讯云Elasticsearch X-Pack
购买Elasticsearch服务的白金版,提供X-Pack官方安全组件。审计日志和告警功能和Elasticsearch一样。腾讯云不提供额外的审计日志和告警服务。
https://cloud.tencent.com/document/product/845/34926
MongoDB审计
目前没有找到第三方或者开源的MongoDB审计软件
- MongoDB企业版审计功能
- 腾讯云MongoDB审计功能
MongoDB企业版审计
支持审计日志打印和审计事件过滤,需要自己采集审计日志并告警。审计日志文件会先于journal 写入,先写审计日志再写journal ,导致数据库操作性能降低。
https://www.mongodb.com/docs/v5.0/core/auditing/
审计日志激活
支持配置审计日志输出到syslog、console、json文件、bson文件。涉及到所有mongod和mongos
输出到syslog
mongod --dbpath data/db --auditDestination syslog
配置文件形式
storage:
dbPath: data/db
auditLog:
destination: syslog
输出到console
mongod --dbpath data/db --auditDestination console
配置文件形式
storage:
dbPath: data/db
auditLog:
destination: console
输出到json文件
mongod --dbpath data/db --auditDestination file --auditFormat JSON --auditPath data/db/auditLog.json
配置文件形式
storage:
dbPath: data/db
auditLog:
destination: file
format: JSON
path: data/db/auditLog.json
输出到bson文件
mongod --dbpath data/db --auditDestination file --auditFormat BSON --auditPath data/db/auditLog.bson
配置文件形式
storage:
dbPath: data/db
auditLog:
destination: file
format: BSON
path: data/db/auditLog.bson
实时审计日志管理
不需要配置mongod和mongos,也不需要使用配置文件配置。使用admin指令激活审计日志和配置审计事件过滤。有以下好处:
- 关注点分离。不需要使用命令行配置mongod和mongos;也不需要修改对应的配置文件;只能配置审计事件过滤和auditAuthorizationSuccess参数,其他配置项不用关心。
- 可以实时配置审计日志,不需要重启MongoDB服务。
- 确保审计日志过滤的一致性。如果每个mongod或者mongos都有独立一份的命令行参数或者配置文件,不保证审计日志文件的过滤内容一致性。
激活实时审计日志配置
激活实时审计配置后,集群的所有节点会分发审计日志配置。
参数 | 值 |
---|---|
auditLog.runtimeConfiguration | true |
auditLog.filter | Unset |
auditAuthorizationSuccess | Unset |
auditLog.runtimeConfiguration和auditLog.filter、auditAuthorizationSuccess不能同时配置。
审计日志事件过滤
支持静态命令行、配置文件配置,支持admin指令动态配置。
https://www.mongodb.com/docs/v5.0/tutorial/configure-audit-filters/
静态命令行配置
mongod --dbpath data/db --auditDestination file --auditFilter '{ atype: { $in: [ "createCollection", "dropCollection" ] } }' --auditFormat BSON --auditPath data/db/auditLog.bson
静态配置文件配置
storage:
dbPath: data/db
auditLog:
destination: file
format: BSON
path: data/db/auditLog.bson
filter: '{ atype: { $in: [ "createCollection", "dropCollection" ] } }'
动态admin指令配置
db.admin.runCommand(
{
setAuditConfig: 1,
filter:
{
atype:
{
$in: [ "createCollection", "dropCollection" ]
}
},
auditAuthorizationSuccess: false
}
)
db.adminCommand({getAuditConfig: 1})
审计消息格式和审计事件
相关文档:
https://www.mongodb.com/docs/v5.0/reference/audit-message/
审计日志采集和告警
需要自己采集、分析审计日志并告警。可以采用skywalking采集日志并告警
腾讯云MongoDB审计功能
腾讯云的MongoDB审计功能不是MongoDB官方提供的审计功能。是腾讯云的数据库审计的SQL功能。
https://cloud.tencent.com/document/product/240/81770
审计规则配置
腾讯云提供的MongoDB数据库审计规则配置,采用SQL语句相关配置。提供的SQL类型操作为query、insert、delete、update、command等。
审计事件告警
腾讯云的文档没有说明MongoDB数据库审计的告警配置。可能直接使用腾讯云通用的数据库审计告警功能。