对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。

setAuditConfig(数据库命令)

重要

在版本 7.1 中已弃用:请改用auditConfig集群参数。

setAuditConfig

版本 5.0 中的新增功能。

setAuditConfig是一条管理命令,用于在运行时为mongod和mongos服务器实例设置新的审核配置。

使用db.adminCommand( { command } )方法对admin数据库运行setAuditConfig 。

此命令可用于以下环境中托管的部署:

该命令具有以下语法:

db.adminCommand( { setAuditConfig: 1, filter: <Filter Document>, auditAuthorizationSuccess: <Boolean> })

该命令具有以下字段:

字段
类型
说明

setAuditConfig

整型

filter

文档

auditAuthorizationSuccess

布尔

记录全部或仅记录失败的访问授权

启用审核以在运行时使用setAuditConfig 。

auditAuthorizationSuccess启用对authCheck动作授权成功的审核。 该参数值必须为true才能Atlas 审核读取和写入操作。 但是,当auditAuthorizationSuccess为false时,审核对性能的影响,因为Atlas 审核系统仅记录授权失败。

配置更新通过oplog机制分发,这意味着mongod节点上的更新会非常快速地分发到从节点。 mongos节点上有不同的分发机制。 mongos节点必须定期poll主服务器以进行配置更新。 在分片轮询主服务器以获取更新的配置详细信息之前,如果您在主服务器上运行setAuditConfig并在分片上运行 { getAuditConfig },则可能会由于轮询延迟而看到过时数据。

在这些示例中,审核消息已重新格式化。 它们在日志文件中显示在一行上。

在创建或删除集合时启用审核。

db.admin.runCommand( { setAuditConfig: 1, filter: { atype: { $in: [ "createCollection", "dropCollection" ] } }, auditAuthorizationSuccess: false })

在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}

从sales数据库删除inventory集合时,审核系统将记录如下消息:

{ "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}

将auditAuthorizationSuccess设置为true并创建一个筛选器,其中包含审核读写操作感兴趣的操作。

db.admin.runCommand( { setAuditConfig: 1, filter: { atype: "authCheck", "param.command": { $in: [ "find", "insert", "delete", "update", "findandmodify" ] } }, auditAuthorizationSuccess: true })

Atlas Search使用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}