On this page本页内容
setAuditConfig
New in version 5.0.在版本5.0中新增。
setAuditConfig
is an administrative command that sets new audit configurations for 是一个管理命令,用于在运行时为mongod
and mongos
server instances at runtime.mongod
和mongos
服务器实例设置新的审计配置。
The command syntax is:命令语法为:
{ setAuditConfig: 1, filter: <Filter Document>, auditAuthorizationSuccess: <Boolean> }
setAuditConfig
has the following fields:具有以下字段:
setAuditConfig | integer | setAuditConfig |
filter | document | |
auditAuthorizationSuccess | boolean |
Use the 使用db.adminCommand( { command } )
method to run setAuditConfig
against the admin
database.db.adminCommand( { command } )
方法对管理数据库运行setAuditConfig
。
Enable Auditing to use 启用审核以在运行时使用setAuditConfig
at runtime.setAuditConfig
。
auditAuthorizationSuccess
enables auditing of authorization success for the authCheck action. auditAuthorizationSuccess
启用authCheck操作的授权成功审核。The parameter value must be 参数值必须为true
to audit read and write operations. true
才能审核读写操作。However, when 然而,当auditAuthorizationSuccess
is false
auditing has less performance impact because the audit system only logs authorization failures.auditAuthorizationSuccess
为false
时,审计对性能的影响较小,因为审计系统只记录授权失败。
Configuration updates are distributed via the oplog mechanism which means updates on 配置更新是通过oplog机制分发的,这意味着mongod
nodes are distributed to secondary nodes very quickly. mongod
节点上的更新会很快分发到次要节点。There is a different distribution mechanism on mongos
nodes. mongos
节点上有不同的分发机制。mongos
nodes have to poll
the primary server at regular intervals for configuration updates. mongos
节点必须定期poll
主服务器以获取配置更新。You may see stale data due to polling delay if you run 如果在主服务器上运行setAuditConfig
on the primary server and getAuditConfig
on a shard before the shard has polled the primary server for updated configuration details.setAuditConfig
并在分片轮询主服务器以获取更新的配置详细信息之前在分片上运行getAuditConfig
,则可能会由于轮询延迟而看到过时的数据。
In these examples the audit messages have been reformatted. They appear on a single line in the log file.在这些示例中,审核消息已重新格式化。它们出现在日志文件的一行中。
Enable auditing when a collection is created or deleted.在创建或删除集合时启用审核。
db.admin.runCommand( { setAuditConfig: 1, filter: { atype: { $in: [ "createCollection", "dropCollection" ] } }, auditAuthorizationSuccess: false } )
When the 当在inventory
collection is created in the sales
database, the audit system will log a message like this:sales
数据库中创建inventory
集合时,审计系统将记录如下消息:
{ "atype" : "createCollection", "ts" : { "$date" : "2021-08-09T13:45:05.372+00:00" }, "uuid" : { "$binary" : "RKU/YLizS6K9se2GUU7ZVQ==", "$type" : "04" }, "local" : { "ip" : "127.0.0.1", "port" : 27502 }, "remote" : { "ip" : "127.0.0.1", "port" : 51918 }, "users" : [], "roles" : [], "param" : { "ns" : "sales.inventory" }, "result" : 0 }
When the 当inventory
collection is dropped from the sales
database, the audit system will log a message like this:inventory
集合从sales
数据库中删除时,审计系统将记录如下消息:
{ "atype" : "dropCollection", "ts" : { "$date" : "2021-08-09T13:45:00.661+00:00" }, "uuid" : { "$binary" : "0gle4/pSQli+LUcz43ykag==", "$type" : "04" }, "local" : { "ip" : "127.0.0.1", "port" : 27502 }, "remote" : { "ip" : "127.0.0.1", "port" : 51928 }, "users" : [], "roles" : [], "param" : { "ns" : "sales.inventory" }, "result" : 0 }
Set 将auditAuthorizationSuccess
to true
and create a filter which includes actions of interest to audit read and write operations.auditAuthorizationSuccess
设置为true
,并创建一个筛选器,其中包含审核读写操作所需的操作。
db.admin.runCommand( { setAuditConfig: 1, filter: { atype: "authCheck", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }, auditAuthorizationSuccess: true } )
Search the 使用inventory
collection in the sales
database using the find
command to create an audit log entry like this one:find
命令搜索sales
数据库中的inventory
集合,以创建如下审核日志条目:
{ "atype" : "authCheck", "ts" : { "$date" : "2021-08-09T15:28:10.788+00:00" }, "uuid" : { "$binary" : "ngwRt5CRTZqgE4TsfleoqQ==", "$type" : "04" }, "local" : { "ip" : "127.0.0.1", "port" : 27502 }, "remote" : { "ip" : "127.0.0.1", "port" : 51930 }, "users" : [], "roles" : [], "param" : { "command" : "find", "ns" : "sales.inventory", "args" : { "find" : "inventory", "filter" : { "widget" : 1 }, "lsid" : { "id" : { "$binary" : "FNWNxiitQ8GHKrHx8eJSbg==", "$type" : "04" } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1628521381, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } }, "$db" : "sales" } }, "result" : 0 }