注意
本页面同时适用于 Atlas Infinite 和 Atlas Core。
Database auditing lets administrators track system activity for deployments with multiple users. Atlas administrators can select the actions, database users, Atlas roles, and LDAP groups that they want to audit. Atlas supports auditing most of the documented system event actions.
authCheck 事件操作将记录试图对项目集群中的数据库执行读取和写入的用户的授权尝试。Atlas 会审核以下特定命令:
authCheck Reads | authCheck Writes |
|---|---|
mapReduce (deprecated in MongoDB 5.0) | mapReduce (deprecated in MongoDB 5.0) |
geoNear (removed in MongoDB 4.2) | |
geoSearch (removed in MongoDB 5.0) | |
group (removed in MongoDB 4.2) | resetError (removed in MongoDB 5.0) |
getLastError (removed in MongoDB 5.1) | |
getPrevError (removed in MongoDB 4.2) |
Atlas 将 authCheck 事件操作实现为以下四个单独的操作:
事件操作 | 说明 |
|---|---|
|
|
|
警告:如果启用auditAuthorizationSuccess ,可能会严重影响集群性能。 请谨慎启用此选项。 |
|
|
|
警告:如果启用auditAuthorizationSuccess ,可能会严重影响集群性能。 请谨慎启用此选项。 |
To learn about how MongoDB writes audit events to disk, see Audit Guarantee in the MongoDB Manual.
必需的访问权限
要配置审核日志,必须对待更新项目具有 Project Owner 访问权限,或者对包含待更新项目的组织具有 Organization Owner 访问权限。
To learn about recommendations for auditing and logging, including the events that we recommend auditing, see Guidance for Atlas Auditing and Logging in the Atlas Architecture Center.
注意
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 审核。
步骤
注意
要了解有关审核临时数据库用户操作的最佳实践,请参阅审核临时数据库用户。
采取以下步骤设置数据库审计:
AtlasGoAdvanced在Atlas中,Go项目的 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。
如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。
在侧边栏中,单击 Security 标题下的 Database & Network Access。
在侧边栏中,单击 Advanced。
显示“高级”页面。
确认要审核身份验证失败事件。
By default, Atlas logs the failed authentication attempts of both known and unknown users in the audit log of the primary node.
在 Select users and roles(选择用户和角色)中,选择要接受操作审核的数据库用户、Atlas 角色和 LDAP 组。
或者,单击 Use Custom JSON Filter(使用自定义 JSON 过滤器)以 JSON 字符串的形式手动输入审核过滤器。有关在 Atlas 中配置自定义审核过滤器的更多信息,请参阅配置自定义审核过滤器。
在 Select actions to audit(选择要审核的操作)中选择要审核的事件操作。
注意
取消选择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.
To retrieve the audit logs in Atlas, see MongoDB Logs. To retrieve the audit logs using the API, see Logs.
配置自定义审核筛选器
Atlas 支持指定 JSON 格式的审核过滤器,以自定义 MongoDB 审核。
Custom audit filters let users forgo the managed Atlas UI auditing filter builder in favor of hand-tailored granular control of event auditing. Atlas checks only that the custom filter uses valid JSON syntax, and doesn't validate or test the filter's functionality.
审核过滤器文档必须解析为与审核事件消息中的一个或多个字段匹配的查询。过滤器文档可以使用查询操作符和等值条件的组合来匹配所需的审核消息。
To view example auditing filters, see Example Auditing Filters. To learn more about configuring MongoDB auditing filters, see Configure Audit Filter.
重要
Atlas 采用滚动更新策略,在 Atlas 项目的所有集群中启用或更新审核配置设置。滚动更新要求每个副本集至少进行一次选举。
要详细了解如何测试应用程序对副本集选举的弹性,请参阅测试主故障转移。要了解有关 Atlas 如何提供高可用性的更多信息,请参阅 Atlas 高可用性。
步骤
AtlasGoAdvanced在Atlas中,Go项目的 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。
如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。
在侧边栏中,单击 Security 标题下的 Database & Network Access。
在侧边栏中,单击 Advanced。
显示“高级”页面。
切换 Audit authorization successes(启用 DevTools)。
警告
启用 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.
编辑自定义审核过滤器
您可以随时编辑筛选器:
AtlasGoAdvanced在Atlas中,Go项目的 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。
如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。
在侧边栏中,单击 Security 标题下的 Database & Network Access。
在侧边栏中,单击 Advanced。
显示“高级”页面。
查看自定义审核筛选器
AtlasGoAdvanced在Atlas中,Go项目的 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。
如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。
在侧边栏中,单击 Security 标题下的 Database & Network Access。
在侧边栏中,单击 Advanced。
显示“高级”页面。
审核筛选器示例
使用以下审核筛选器示例,指导您构建自己的筛选器。
重要
These examples are not intended for use in production environments, nor are they a replacement for familiarity with the MongoDB Auditing Documentation.
审核已知用户的所有身份验证事件
{ "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" ] } }
Atlas 审核用户创建和删除事件
{ "atype": { "$in": [ "createUser", "dropUser", "directAuthMutation" ] } }
注意
directAuthMutation操作追踪对 admin.system.users 和 admin.system.roles 集合的直接修改。这包括Atlas直接在 admin数据库中执行的SCRAM用户创建和修改操作。
Atlas 审核日志中的监控代理查询
启用数据库 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
latencyStatshistograms.其他性能指标:检索用于监控仪表盘的数据库和集群统计信息。
示例 Atlas 审核日志条目
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 审核配置
要使用Atlas CLI更新指定项目的Atlas 审核配置,运行以下命令:
atlas auditing update [options]
要学习;了解有关命令语法和参数的更多信息,请参阅Atlas CLI文档的 atlas auditing 更新。
查看 Atlas 审核配置
要使用 Atlas CLI 返回指定项目的审核配置, 请运行以下命令:
atlas auditing describe [options]
要了解有关命令语法和参数的更多信息,请参阅 Atlas CLI 文档中的 atlas auditing describe。