配置审计过滤器

在本页

MongoDB Atlas 中的审计

MongoDB Atlas支持对所有M10和更大的集群进行审计。

Atlas支持在配置审计过滤器中指定JSON格式的审计过滤器,并使用Atlas审计过滤器构建器来简化审计配置。

要了解更多信息,请参阅Atlas文档中的设置数据库审计配置自定义审计过滤器

MongoDB 企业版支持审计各种操作。

启用审计功能会默认的记录所有可审计的操作,如审计事件操作,详细信息和结果

为了能指定那些事件需要被记录,审计功能包含--auditFilter选项。

注意

从mongoDB 3.6开始,mongod and mongos默认绑定localhost。

如果你部署的实例运行在不同的主机上或者如果你希望远程客户端连接到部署实例,你必须指定--bind_ip or net.bindIp.

更多信息,请查看Localhost 绑定兼容性更改

绑定到其他IP地址之前,请考虑启用访问控制“安全性检查表”中的列出的其他安全措施,以防止未经授权的访问。

--auditFilter 选项

--auditFilter`选项采用以下查询文档的字符串的表示形式:

复制

{ <field1>: <expression1>, ... }

指定一个审计过滤器,可以将过滤器文档括在单引号中使其转成字符串。

配置文件中指定审计过滤器,必须使用配置文件的YAML格式。

例子

多种操作类型的过滤器

以下示例通过使用过滤器仅审计 createCollectiondropCollection操作:

复制

{ atype: { $in: ["createCollection", "dropCollection"] } }

指定一个审计过滤器,可以将过滤器文档括在单引号中使其转成字符串。

复制

mongod --dbpath data/db --auditDestination file --auditFilter '{ atype: { $in: [ "createCollection", "dropCollection" ] } }' --auditFormat BSON --auditPath data/db/auditLog.bson

包括配置所需的其他选项。例如,如果您希望远程客户端连接到您的部署,或者您的部署成员在不同的主机上运行,​​请指定--bind_ip参数。更多信息,请参见Localhost绑定兼容性更改

配置文件中指定审计过滤器,必须使用配置文件的YAML格式。

复制

storage:
   dbPath: data/db
auditLog:
   destination: file
   format: BSON
   path: data/db/auditLog.bson
   filter: '{ atype: { $in: [ "createCollection", "dropCollection" ] } }'

筛选单个数据库上的身份验证操作

<field>可以包含审计消息中的任何字段。对于身份认证操作(即,atype: "authenticate"),审计消息中的 param 文档中包含 db 字段。

以下示例使用过滤器仅审计针对test数据库的身份验证操作。

复制

{ atype: "authenticate", "param.db": "test" }

指定一个审计过滤器,可以将过滤器文档括在单引号中使其转成字符串。

复制

mongod --dbpath data/db --auth --auditDestination file --auditFilter '{ atype: "authenticate", "param.db": "test" }' --auditFormat BSON --auditPath data/db/auditLog.bson

包括配置所需的其他选项。例如,如果您希望远程客户端连接到您的部署,或者您的部署成员在不同的主机上运行,请指定--bind_ip参数。更多信息,请参见Localhost绑定兼容性更改

配置文件中指定审计过滤器,必须使用配置文件的YAML格式。

复制

storage:
   dbPath: data/db
security:
   authorization: enabled
auditLog:
   destination: file
   format: BSON
   path: data/db/auditLog.bson
   filter: '{ atype: "authenticate", "param.db": "test" }'

要过滤数据库中的所有身份验证操作,请使用过滤器{ atype: "authenticate" }

筛选单个数据库的集合创建和删除操作

<field>可以包含审计消息中的任何字段。对于集合创建和删除操作(即,atype: "createCollection"atype: "dropCollection"),审计消息中的 param 文档中包含ns 字段。

以下示例使用过滤器仅审计针对test数据库的创建集合和删除集合操作。

注意

正则表达式需要两个反斜杠(\\)才能转义(.)

复制

{ atype: { $in: [ "createCollection", "dropCollection" ] }, "param.ns": /^test\\./ } }

将过滤器文档括在单引号中使其转成字符串来指定一个审计过滤器。

复制

mongod --dbpath data/db --auth --auditDestination file --auditFilter '{ atype: { $in: [ "createCollection", "dropCollection" ] }, "param.ns": /^test\\./ } }' --auditFormat BSON --auditPath data/db/auditLog.bson

包括配置所需的其他选项。例如,如果您希望远程客户端连接到您的部署,或者您的部署成员在不同的主机上运行,请指定 --bind_ip参数。更多信息,请参见Localhost绑定兼容性更改

配置文件中指定审计过滤器,必须使用配置文件的YAML格式。

复制

storage:
   dbPath: data/db
security:
   authorization: enabled
auditLog:
   destination: file
   format: BSON
   path: data/db/auditLog.bson
   filter: '{ atype: { $in: [ "createCollection", "dropCollection" ] }, "param.ns": /^test\\./ } }'

通过授权角色进行筛选

以下示例通过使用过滤器来审计test数据库上具有 readWrite角色的用户的操作,包括具有从[readWrite]继承的角色的用户:

复制

{ roles: { role: "readWrite", db: "test" } }

指定一个审计过滤器,可以将过滤器文档括在单引号中使其转成字符串。

复制

mongod --dbpath data/db --auth --auditDestination file --auditFilter '{ roles: { role: "readWrite", db: "test" } }' --auditFormat BSON --auditPath data/db/auditLog.bson

包括配置所需的其他选项。例如,如果您希望远程客户端连接到您的部署,或者您的部署成员在不同的主机上运行,请指定 --bind_ip参数。更多信息,请参见Localhost绑定兼容性更改

配置文件中指定审计过滤器,必须使用配置文件的YAML格式。

复制

storage:
   dbPath: data/db
security:
   authorization: enabled
auditLog:
   destination: file
   format: BSON
   path: data/db/auditLog.bson
   filter: '{ roles: { role: "readWrite", db: "test" } }'

读写操作中的过滤器

要在审计中进行捕获读和写操作,必须设置审计参数使审计系统记录身份验证成功。1

注意

启用审计授权成功与仅记录授权失败相比会使性能下降更多。

下面的例子用来审计find(), insert(), remove(), update(), save()findAndModify()这些操作,过滤器如下:

复制

{ atype: "authCheck", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }

指定一个审计过滤器,可以将过滤器文档括在单引号中使其转成字符串。

复制

mongod --dbpath data/db --auth --setParameter auditAuthorizationSuccess=true --auditDestination file --auditFilter '{ atype: "authCheck", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify"] } }' --auditFormat BSON --auditPath data/db/auditLog.bson

包括配置所需的其他选项。例如,如果您希望远程客户端连接到您的部署,或者您的部署成员在不同的主机上运行,请指定--bind_ip参数。更多信息,请参见Localhost绑定兼容性更改

配置文件中指定审计过滤器,必须使用配置文件的YAML格式。

复制

storage:
   dbPath: data/db
security:
   authorization: enabled
auditLog:
   destination: file
   format: BSON
   path: data/db/auditLog.bson
   filter: '{ atype: "authCheck", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }'
setParameter: { auditAuthorizationSuccess: true }

过滤集合的读写操作

要在审计中进行捕获读和写操作,还必须使用 auditAuthorizationSuccess 参数使审计系统能够记录授权成功。 1

注意

启用审计授权成功与仅记录授权失败相比,启用会使性能下降更多。

下面的例子用来审计在test数据库的orders集合上的find(), insert(), remove(), update(), save(), and findAndModify()操作,过滤器如下:

复制

{ atype: "authCheck", "param.ns": "test.orders", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }

指定一个审计过滤器,可以将过滤器文档括在单引号中使其转成字符串。

复制

mongod --dbpath data/db --auth --setParameter auditAuthorizationSuccess=true --auditDestination file --auditFilter '{ atype: "authCheck", "param.ns": "test.orders", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }' --auditFormat BSON --auditPath data/db/auditLog.bson

包括配置所需的其他选项。例如,如果您希望远程客户端连接到您的部署,或者您的部署成员在不同的主机上运行,请指定 --bind_ip参数。有关更多信息,请参见Localhost绑定兼容性更改

配置文件中指定审计过滤器,必须使用配置文件的YAML格式。

复制

storage:
   dbPath: data/db
security:
   authorization: enabled
auditLog:
   destination: file
   format: BSON
   path: data/db/auditLog.bson
   filter: '{ atype: "authCheck", "param.ns": "test.orders", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }'
setParameter: { auditAuthorizationSuccess: true }

也可以看看

配置审计, 审计, 系统事件审计消息

[1](1,2)可以启用审计授权成功参数不启用 --auth; 但是所有操作将返回成功以进行授权检查。

原文链接:https://docs.mongodb.com/manual/tutorial/configure-audit-filters/

译者:谢伟成

参见

原文 - Configure Audit Filters

Copyright © 上海锦木信息技术有限公司 all right reserved,powered by Gitbook文件修订时间: 2023-09-01 17:10:26

results matching ""

    No results matching ""