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

设置数据库审核

注意

此功能不适用于以下任何部署:

  • 免费集群

  • Flex 集群

要学习;了解更多信息,请参阅限制。

数据库 Atlas 审核允许管理员追踪具有多个用户的部署的系统活动。Atlas管理员可以选择要Atlas 审核的操作、数据库用户、 Atlas角色和LDAP群组。Atlas支持Atlas 审核大多数记录的系统事件操作。

authCheck 事件操作将记录试图对项目集群中的数据库执行读取和写入的用户的授权尝试。Atlas 会审核以下特定命令:

authCheck Reads
authCheck Writes

mapReduce(在MongoDB 5.0 中已弃用)

mapReduce (deprecated in MongoDB 5.0)

geoNear(已在MongoDB 4.2 中删除)

geoSearch(已在MongoDB 5.0 中删除)

群组(已在MongoDB 4.2 中删除)

Atlas 将 authCheck 事件操作实现为以下四个单独的操作:

事件操作
说明

authChecksReadFailures

authCheck 事件操作,适用于当 auditAuthorizationSuccess 参数设置为 false 时的所有失败的读取。此事件操作是与读取相关的事件操作的默认设置。

authChecksReadAll

authCheck 事件操作(针对包括成功和失败的所有读取)。此事件操作与 authChecksReadFailures 相同,但 auditAuthorizationSuccess 参数设置为“真”。

警告:如果启用auditAuthorizationSuccess ,可能会严重影响集群性能。 请谨慎启用此选项。

authChecksWriteFailures

authCheck 事件操作,适用于当 uditAuthorizationSuccess 参数设置为 false 时的所有失败的读取。该事件操作是写相关事件操作的默认操作。

authChecksWriteAll

authCheck 所有写入的事件操作,包括写入成功和写入失败。此事件操作与 authChecksWriteFailures 相同,但 auditAuthorizationSuccess 参数设置为“真”。

警告:如果启用auditAuthorizationSuccess ,可能会严重影响集群性能。 请谨慎启用此选项。

要了解 MongoDB 如何将审核事件写入到磁盘,请参阅《MongoDB 手册》中的审核保证

要配置审核日志,必须对待更新项目具有 Project Owner 访问权限,或者对包含待更新项目的组织具有 Organization Owner 访问权限。

要学习;了解审核和日志记录的建议,包括我们建议审核的事件,请参阅Atlas架构中心的Atlas审核和日志记录指南

注意

The MongoDB Atlas Shared Responsibility Model defines the complementary duties of MongoDB and its customers in maintaining a secure and resilient data environment. Under this framework, MongoDB manages the security and operational integrity of the underlying platform, while customers are responsible for the configuration, management, and data policies of their specific deployments. For a detailed breakdown of ownership across security and operational excellence, see Shared Responsibility Model.

要实施在项目中的所有集群上启用数据库Atlas 审核,请使用Atlas资源策略。您可以使用资源策略,要求在创建或修改集群之前进行数据库Atlas 审核。

注意

要了解有关审核临时数据库用户操作的最佳实践,请参阅审核临时数据库用户

采取以下步骤设置数据库审计:

1
  1. 如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。

  2. 如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。

  3. 在侧边栏中,单击 Security 标题下的 Database & Network Access

  4. 在侧边栏中,单击 Advanced

    显示“高级”页面。

2
3

默认情况下,Atlas 会在 节点的审核日志中记录已知和未知用户失败的身份验证尝试。

4

或者,单击 Use Custom JSON Filter(使用自定义 JSON 过滤器)以 JSON 字符串的形式手动输入审核过滤器。有关在 Atlas 中配置自定义审核过滤器的更多信息,请参阅配置自定义审核过滤器。

5

注意

取消选择authenticate操作可防止 Atlas 审核身份验证失败。

注意

When selecting the authorization success granularity of auditing for the authCheck event action, Atlas does not support different selections for reads and writes. For example, you may not select Successes and Failures for authCheck Reads and Failures for authCheck Writes. If you select both authCheck Reads and authCheck Writes, Atlas automatically applies your selected granularity to both.

6

要检索 Atlas 中的审核日志,请参阅 MongoDB 日志。要使用 API 检索审核日志,请参阅日志

注意

此功能不适用于以下任何部署:

  • 免费集群

  • Flex 集群

要学习;了解更多信息,请参阅限制。

Atlas 支持指定 JSON 格式的审核过滤器,以自定义 MongoDB 审核。

自定义审核筛选器可让用户放弃托管 Atlas UI 审核筛选器构建器,转而对事件审核进行手工定制的精细控制。 Atlas 仅检查自定义筛选器是否使用有效的 JSON 语法,而不会验证或测试筛选器的功能。

The audit filter document must resolve to a query that matches one or more fields in the audit event message. The filter document can use combinations of query operators and equality conditions to match the desired audit messages.

如需查看示例审核过滤器,请参阅示例审核过滤器。如需了解有关配置 MongoDB 审核过滤器的更多信息,请参阅配置审核过滤器

重要

Atlas 采用滚动更新策略,在 Atlas 项目的所有集群中启用或更新审核配置设置。滚动更新要求每个副本集至少进行一次选举。

要详细了解如何测试应用程序对副本集选举的弹性,请参阅测试主故障转移。要了解有关 Atlas 如何提供高可用性的更多信息,请参阅 Atlas 高可用性

1
  1. 如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。

  2. 如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。

  3. 在侧边栏中,单击 Security 标题下的 Database & Network Access

  4. 在侧边栏中,单击 Advanced

    显示“高级”页面。

2
3
4
5

警告

启用 Audit authorization successes 会严重影响集群性能。请谨慎启用此选项。

For audit filters specifying the authCheck action type, the auditing system logs only authorization failures for any specified param.command by default. Enabling Audit authorization successes directs the auditing system to also log authorization successes. If you don't enable auditAuthorizationSuccess, your audit system can't log successful CRUD operations specified in the action type. To learn more, see auditAuthorizationSuccess.

6

您可以随时编辑筛选器:

1
  1. 如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。

  2. 如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。

  3. 在侧边栏中,单击 Security 标题下的 Database & Network Access

  4. 在侧边栏中,单击 Advanced

    显示“高级”页面。

2
  1. Database Auditing(数据库审核) Configure Your Auditing Filter (配置审核过滤器)下,单击 Use Custom JSON Filter(使用自定义 JSON 过滤器)。

  2. 进行所需的更改。

  3. 单击 Save(连接)。

1
  1. 如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。

  2. 如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。

  3. 在侧边栏中,单击 Security 标题下的 Database & Network Access

  4. 在侧边栏中,单击 Advanced

    显示“高级”页面。

2

您的自定义审核过滤器显示在 Database Auditing 下方。

使用以下审核筛选器示例,指导您构建自己的筛选器。

重要

这些示例不适合在生产环境中使用,也不能取代熟练使用 MongoDB 审核文档

{
"atype": "authenticate"
}
{
"$or": [
{
"users": []
},
{
"atype": "authenticate"
}
]
}

注意

需要执行 authenticate 操作,以记录已知用户和未知用户的身份验证失败事件。

{
"atype": "authenticate",
"param": {
"user": "myClusterAdministrator",
"db": "admin",
"mechanism": "SCRAM-SHA-256"
}
}
{
"atype": "authCheck",
"param.command": {
"$in": [
"insert",
"update",
"delete"
]
}
}
{
"atype": {
"$in": [
"createUser",
"dropUser",
"directAuthMutation"
]
}
}

注意

directAuthMutation操作追踪对 admin.system.usersadmin.system.roles 集合的直接修改。这包括Atlas直接在 admin数据库中执行的SCRAM用户创建和修改操作。

启用数据库 Atlas 审核时,您可能会在 Atlas 审核日志中观察到来自 mms-monitoring-agent 用户的查询。这些查询是 Atlas 用于收集监控功能的指标和性能数据的内部操作。

The mms-monitoring-agent user has the clusterMonitor and directShardOperations roles and performs queries on behalf of the following Atlas monitoring features:

  • 查询见解:收集查询性能统计信息和形状,帮助您识别缓慢查询。

  • Namespace Insights: Gathers collection-level latency statistics using $collStats aggregation pipelines with latencyStats histograms.

  • 其他性能指标:检索用于监控仪表盘的数据库和集群统计信息。

The following example shows an audit log entry for a Namespace Insights query. This query uses the $collStats stage to collect latency statistics for a collection:

{
"atype": "authCheck",
"ts": {
"$date": "2025-11-20T13:44:20.201+00:00"
},
"users": [
{
"user": "mms-monitoring-agent",
"db": "admin"
}
],
"roles": [
{
"role": "clusterMonitor",
"db": "admin"
},
{
"role": "directShardOperations",
"db": "admin"
}
],
"param": {
"command": "aggregate",
"ns": "test_db.people_1234",
"args": {
"aggregate": "people_1234",
"pipeline": [
{
"$collStats": {
"latencyStats": {
"histograms": true
}
}
}
],
"$readPreference": {
"mode": "nearest"
}
}
},
"result": 0
}

这些查询是预期行为,无需采取操作。如果您想从审计日志中排除监控智能体查询,可以创建自定义审计过滤器。要了解更多信息,请参阅配置自定义审核过滤器。

您可以使用Atlas CLI管理项目的数据库Atlas 审核配置。

要使用Atlas CLI更新指定项目的Atlas 审核配置,运行以下命令:

atlas auditing update [options]

要学习;了解有关命令语法和参数的更多信息,请参阅Atlas CLI文档的 atlas auditing 更新。

要使用 Atlas CLI 返回指定项目的审核配置, 请运行以下命令:

atlas auditing describe [options]

要了解有关命令语法和参数的更多信息,请参阅 Atlas CLI 文档中的 atlas auditing describe