数据库 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 中删除) | |
resetError(已在MongoDB 5.0 中删除) | |
getLastError(已在MongoDB 5.1 中删除) | |
getPrevError(已在MongoDB 4.2 中删除) |
Atlas 将 authCheck 事件操作实现为以下四个单独的操作:
事件操作 | 说明 |
|---|---|
|
|
|
警告:如果启用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 审核。
步骤
注意
要了解有关审核临时数据库用户操作的最佳实践,请参阅审核临时数据库用户。
采取以下步骤设置数据库审计:
AtlasGoAdvanced在Atlas中,Go项目的 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。
如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。
在侧边栏中,单击 Security 标题下的 Database & Network Access。
在侧边栏中,单击 Advanced。
显示“高级”页面。
确认要审核身份验证失败事件。
默认情况下,Atlas 会在 主节点的审核日志中记录已知和未知用户失败的身份验证尝试。
在 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.
要检索 Atlas 中的审核日志,请参阅 MongoDB 日志。要使用 API 检索审核日志,请参阅日志。
配置自定义审核筛选器
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 高可用性。
步骤
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。
显示“高级”页面。
审核筛选器示例
使用以下审核筛选器示例,指导您构建自己的筛选器。
重要
这些示例不适合在生产环境中使用,也不能取代熟练使用 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" ] } }
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。