Atlas 审核和日志记录指导
要监控和日志Atlas平台活动,请使用审核和日志功能。
Atlas 审核和日志记录的功能
审核
数据库审计可用于M10+
个集群,让您追踪多用户部署的系统活动。作为 Atlas 管理员,您可以:
依赖Atlas中的默认审核设置。默认下, Atlas在
M10+
集群中执行数据库身份验证审核以记录身份验证事件,包括与以下内容相关的事件:database users
源IP地址
成功和失败尝试的时间戳
配置 JSON 格式的Atlas 审核过滤器以自定义 MongoDB 审计,并选择要审计的操作、数据库用户、Atlas 角色和LDAP 组。如果您创建了自定义Atlas 审核过滤器,您可以跳过使用托管的 Atlas 用户界面审核过滤器构建者,配置您自己的事件审核过滤器。有关可配置用于Atlas 审核的事件的完整列表和示例,请参阅MongoDB Atlas 审核和示例Atlas 审核过滤器。
您可以对Atlas中记录的大多数 系统事件操作 配置 手动审核 。粒度MongoDB 数据库审核允许您详细追踪所有数据定义语言(DDL)、DML(数据操作语言)和 DCL(数据控制语言)命令的使用情况。另请参阅设置数据库审核。
访问审核日志
Atlas 保留最近 30 天的日志消息和系统事件审核消息。您可以在其保留期结束前的任何时间点,通过 Atlas 用户界面、Atlas 管理 API 和 Atlas CLI 下载 Atlas 日志。
要了解更多信息,请参阅查看和下载 MongoDB 日志。
您可以查看和更新每个项目的审核配置。使用以下Atlas CLI命令:
您可以查看用户使用Atlas CLI、 Atlas Administration API或Atlas用户界面对集群进行的身份验证尝试。Atlas会记录成功和不成功的身份验证尝试,包括每次尝试的时间戳以及哪个用户尝试进行身份验证。
您还可以使用Atlas CLI、 Atlas Administration API或Atlas用户界面查看和过滤组织或项目的操作日志。操作日志会列出组织或项目级别的所有事件。
要执行全面Atlas 审核,您可以结合使用Atlas 审核日志、MongoDB日志消息以及项目和组织操作日志。
关于 Atlas 审核和日志记录的建议
我们建议您在预配集群时设立数据库审核。审核会给集群增加额外负载并增加成本。为了优化成本,您可以在较低的开发环境中禁用审核。出于合规原因,某些行业(例如医疗保健和金融服务)可能会选择在开发环境中继续启用审核。
为所有数据库用户(包括应用程序服务用户)启用审核可能会影响集群性能。我们建议您仅Atlas 审核需要审核的用户操作。
对于暂存和生产环境,启用审核以提高安全性。
我们建议您至少Atlas 审核以下事件:
登录失败
会话活动
登录和注销
尝试执行未经授权的功能
更改密码
数据库用户访问权限更改
DDL 和系统配置存储过程
原生审计的修改
执行备份或还原操作
更改 DBMS 原生Atlas 审核设置
更改安全设置
运行数据库启动和停止命令
对于之前的所有事件,您应在Atlas 审核日志中至少包含以下信息:
会话id
客户端主机名和IP解决
数据库服务器主机名和IP解决
数据库用户
数据库名称
操作系统用户
服务/实例名称
端口
应用程序
查询
SQL命令
对象
时间戳
错误代码(如果适用)
通过编程访问审核日志
为了与内置集成之外的工具进行集成,我们建议您使用以下编程工具来检索日志,并将 JSON 格式的输出传递给外部工具:
要将日志持续推送到Amazon Web Services S3 存储桶,请使用Atlas Administration API端点进行基于推送的日志导出。
要检索部署日志,请使用Atlas CLI中的Atlas部署日志命令。要学习;了解更多信息,请参阅Atlas部署日志。
自动化示例:Atlas 审核和日志记录
以下示例展示了如何使用 Atlas 工具来检索和下载日志,并配置Atlas 审核以实现自动化。
除以下示例外,请参阅博文《使用 Atlas 推送日志导出简化 Amazon S3 的日志管理》。通过 HashiCorp Terraform 实现。
更新审核配置
运行以下 Atlas CLI 命令以进行 Atlas 审核项目中已知用户的所有身份验证事件:
atlas auditing update --auditFilter '{"atype": "authenticate"}'
运行以下Atlas CLI命令以通过配置文件Atlas 审核已知用户:
atlas auditing update -f filter.json
描述审核配置
运行atlas auditing describe Atlas CLI 命令,返回指定atlas项目的审计配置:
atlas auditing describe --output json
创建并使用Atlas 审核过滤器
创建Atlas 审核过滤器,仅审计针对测试数据库的身份验证操作。要了解更多信息,请参阅配置Atlas 审核过滤器。
{ atype: "authenticate", "param.db": "test" }
要使用您创建的Atlas 审核过滤,请使用 atlas auditing 更新 Atlas CLI命令更新Atlas 审核配置:
atlas auditing update --auditFilter '{"atype": "authenticate", "param.db": "test"}'
检索日志
要检索访问权限日志,请使用类似于以下内容的命令。此命令返回JSON格式的列表,其中包含针对ID为 618d48e05277a606ed2496fe
的项目的名为 Cluster0
的集群发出的所有身份验证请求:
atlas accesslogs list --output json --projectId 618d48e05277a606ed2496fe --clusterName Cluster0
在JSON文件中检索组织的所有日志事件
要返回指定组织的所有事件,请使用类似于以下内容的命令。此命令返回ID为 5dd5a6b6f10fab1d71a58495
的组织的JSON格式的事件列表:
atlas events organizations list --orgId 5dd5a6b6f10fab1d71a58495 --output json
下载日志
运行以下Atlas CLI命令以下载压缩文件,其中包含项目中指定托管的MongoDB日志。
atlas logs download atlas-lnmtkm-shard-00-00.ajlj3.mongodb.net mongodb.gz --projectId 56fd11f25f23b33ef4c2a331
以下示例演示了如何为部署启用审核。在使用 Terraform 创建资源之前,您必须:
创建付款组织并为付款组织创建API密钥。通过在终端中运行以下命令,将公钥和私钥存储为环境变量:
export MONGODB_ATLAS_PUBLIC_KEY="<insert your public key here>" export MONGODB_ATLAS_PRIVATE_KEY="<insert your private key here>"
启用Atlas 审核并为集群创建Atlas 审核过滤器
您可以通过创建Atlas 审核筛选器来配置对大多数记录的系统事件操作的手动审核。要学习;了解有关配置Atlas 审核筛选器的更多信息,请参阅配置审核筛选器。
Create a project resource "mongodbatlas_project" "project_test" { name = var.project_name org_id = var.org_id } Create a cluster with three nodes resource "mongodbatlas_advanced_cluster" "cluster_test" { project_id = mongodbatlas_project.project_test.id name = var.cluster_name cluster_type = "REPLICASET" replication_specs { region_configs { priority = 7 provider_name = "AWS" region_name = "US_EAST_1" electable_specs { instance_size = "M10" node_count = 3 } } } } Specify an auditing resource and enable auditing for a project. To configure auditing, specify the unique project ID. If you change this value to a different "project_id", this deletes the current audit settings for the original project. "audit_authorization_success" indicates whether the auditing system captures successful authentication attempts for audit filters using the "atype" : "authCheck" auditing event. Warning! If you set "audit_authorization_success" to "true", this can severely impact cluster performance. Enable this option with caution. "audit_filter" is the JSON-formatted audit filter. "enabled" denotes whether or not the project associated with the specified "{project_id}"" has database auditing enabled. Defaults to "false". Auditing created by API Keys must belong to an existing organization. In addition to arguments listed previously, the following attributes are exported: "configuration_type" denotes the configuration method for the audit filter. Possible values are: - "NONE" - auditing is not configured for the project. - "FILTER_BUILDER" - auditing is configured via the Atlas UI filter builder. - "FILTER_JSON" - auditing is configured via a custom filter in Atlas or API. resource "mongodbatlas_auditing" "test" { project_id = "mongodbatlas_project.project_test.id" audit_filter = "{ 'atype': 'authenticate', 'param': { 'user': 'auditAdmin', 'db': 'admin', 'mechanism': 'SCRAM-SHA-1' }}" audit_authorization_success = false enabled = true }
检索日志
您无法使用 Terraform检索日志。请改用以下Atlas Administration API端点: