Docs 菜单

Docs 主页开发应用程序MongoDB Manual

setAuditConfig

在此页面上

  • 定义
  • 语法
  • 命令字段
  • 行为
  • 举例

重要

setAuditConfig

版本 5.0 中的新增功能

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

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

该命令具有以下语法:

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

该命令具有以下字段:

字段
类型
说明
setAuditConfig
整型
filter
文档
auditAuthorizationSuccess
布尔
记录全部或仅记录失败的访问授权

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

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

配置更新通过 oplog mongod机制分发,这意味着 节点上的更新会非常快速地分发到从节点。 节点上有不同的分发机制。mongos mongospoll节点必须定期 主服务器以进行配置更新。在分片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
}
)

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

提示

另请参阅:

← rotateCertificates