Docs 菜单
Docs 主页
/ /
/ / /

Atlas 审核指导

如要监控 Atlas 平台活动,请使用审核功能。

数据库审计功能可在 M10+ 集群上使用,使您能够追踪多个用户部署的系统活动。

作为 Atlas 管理员,您可以在 MongoDB 中创建自定义 JSON 审核过滤器,以精确控制整个系统中要 Atlas 审核的内容。

与 Atlas 用户界面中的标准过滤器构建器相比,这种方法允许您准确指定应监控的操作、数据库用户和 Atlas 角色,从而对您的 Atlas 审核过程进行更细粒度的控制。

通过手动审核配置,您可以监控 Atlas 中几乎所有记录的系统事件操作

全面的数据库审核功能提供详细的跟踪:

  • DDL(数据定义语言)操作

  • DML(数据操作语言)操作

  • DCL(数据控制语言)操作。

这提供了对数据库模式更改、数据修改和权限调整的完整可见性。

有关实现指导,包括完整的事件列表和实用的配置示例,请参阅 MongoDB 审核示例审核过滤器文档。更多设置说明可参阅设置数据库审核部分。

您可以创建审核过滤器,将审核限制为仅对关注某些操作。当您启用操作审核时,Atlas 会记录所有可审核的操作,详见审核事件操作、详情和结果。

如需限制 Atlas 应记录的事件,您可以指定事件审核过滤器。

以下文档定义了一个审核过滤器,该过滤器将审核限制为仅针对 test 数据库发生的身份验证操作。如要了解更多信息,请参阅配置审核过滤器。

{ "atype": "authenticate", "param.db": "test" }

如要启用审核过滤器,请使用 --enabled 标志运行 atlas auditing update 命令,并将审核过滤器文档用单引号括起来,以 string 形式传递文档:

atlas auditing update --enabled --auditFilter '{"atype": "authenticate", "param.db": "test"}'

自定义审核过滤器使您可以放弃托管的 {atlas-ui+} 审核过滤器生成器,转而使用手工量身定制的事件审核精细控制。Atlas 只确认自定义过滤器使用了有效的 JSON 语法,而不验证或测试过滤器的功能。

审核过滤器文档:

  • 必须解析为与审核事件消息中的一个或多个字段匹配的查询。

  • 可以使用查询操作符和等值条件的组合来匹配所需的审核消息。

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

为您的自定义过滤器配置 JSON 配置文件也很有用,因为如果您需要创建一个大型过滤器,将过滤器的配置存储在单独的文件中会更容易管理和维护。

以下 Atlas CLI 命令启用在指定的 JSON 配置文件中定义的审核过滤器:

atlas auditing update --enabled -f filter.json

以下建议适用于所有部署范式。

我们建议您在预配集群时设置数据库审核

数据库审核会增加集群资源使用量和运营开销。

  • 为了保持最佳性能并控制费用,请考虑仅对必要用户执行审核,并在不需要的开发环境中关闭审核。

  • 出于合规原因,某些行业(例如医疗保健和金融服务)可能会选择在开发环境中保持开启审核功能。

我们建议您至少Atlas 审核以下事件:

  • 登录失败

  • 会话活动

  • 登录和注销

  • 尝试执行未经授权的功能

  • 更改密码

  • 数据库用户访问权限更改

  • DDL 和系统配置存储过程

  • 修改原生审核

  • 执行备份或恢复操作

  • 更改 DBMS 原生审核设置

  • 更改安全设置

  • 运行数据库启动和停止命令

提示

有关在所有支柱上实施我们建议的 Terraform 示例,请参阅Github中的以下示例之一:

以下示例展示了如何使用 Atlas 自动化工具来检索和下载日志并配置审核。

如要更新项目的审核配置,请使用 atlas auditing update 命令并指定新的审核过滤器。以下命令将现有的审核过滤器配置替换为新的过滤器,新过滤器会审核项目中已知用户的所有身份验证事件:

atlas auditing update --enabled --auditFilter '{"atype": "authenticate"}'

运行 atlas auditing describe 命令,以返回指定项目的审核配置:

atlas auditing describe --output json

以下示例演示了如何为部署启用审核。在使用 Terraform 创建资源之前,您必须:

  • 创建付款组织并为付款组织创建API密钥。通过在终端中运行以下命令,将公钥和私钥存储为环境变量:

    export MONGODB_ATLAS_PUBLIC_KEY="<insert your public key here>"
    export MONGODB_ATLAS_PRIVATE_KEY="<insert your private key here>"
  • 安装 Terraform。

您可以通过创建Atlas 审核筛选器来配置对大多数记录的系统事件操作的手动审核。要学习;了解有关配置Atlas 审核筛选器的更多信息,请参阅配置审核筛选器。

下面的 Terraform 脚本设置了具有全面数据库审核功能的完整 MongoDB Atlas 基础架构。脚本:

  • 在组织内创建一个新项目,并在美国东部区域的 AWS 上预配一个三节点副本集集群(M10 实例)。

  • 使用监控身份验证事件、用户管理操作和各种数据库命令(包括数据操纵和查询操作)的 JSON 过滤器,启用详细的审核功能。

审核配置特别针对管理员和外部数据库用户,同时跟踪关键操作,例如身份验证尝试、角色修改以及常见的数据库命令,例如 findinsertupdatedelete 操作。

# Add the MongoDB Atlas Provider
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "1.34.0"
}
}
}
# Configure the MongoDB Atlas Provider
provider "mongodbatlas" {
public_key = var.mongodbatlas_public_key
private_key = var.mongodbatlas_private_key
}
# Create a Project
resource "mongodbatlas_project" "this" {
org_id = var.atlas_org_id
name = var.atlas_project_name
}
# Create an Atlas Advanced Cluster
resource "mongodbatlas_advanced_cluster" "atlas-cluster" {
project_id = mongodbatlas_project.atlas-project.id
name = "ClusterPortalProd"
cluster_type = "REPLICASET"
mongo_db_major_version = "8.0"
replication_specs {
region_configs {
electable_specs {
instance_size = "M10"
node_count = 1
}
provider_name = "AWS"
priority = 7
region_name = "US_WEST_1"
}
}
# Advanced configuration
backup_enabled = true
pit_enabled = true
version_release_system = "LTS"
}
# Create comprehensive auditing configuration to capture all possible audit events
resource "mongodbatlas_auditing" "atlas-auditing" {
project_id = mongodbatlas_project.atlas-project.id
# Comprehensive audit filter to capture all possible audit events
audit_filter = jsonencode({
"$or" = [
# Capture all authentication events
{
"atype" = {
"$in" = [
"authenticate",
"authCheck",
"logout"
]
}
},
# Capture all authorization events
{
"atype" = "authCheck"
},
# Capture all CRUD operations
{
"atype" = "authCheck",
"param.command" = {
"$in" = [
# Read operations
"find",
"getMore",
"count",
"distinct",
"aggregate",
"group",
"mapReduce",
"geoNear",
"geoSearch",
"parallelCollectionScan",
"eval",
"getLastError",
"getPrevError",
"resetError",
# Write operations
"insert",
"update",
"delete",
"findAndModify",
"save",
# Index operations
"createIndexes",
"dropIndexes",
"listIndexes",
"reIndex",
# Collection operations
"create",
"drop",
"listCollections",
"collMod",
"convertToCapped",
"emptycapped",
"renameCollection",
# Database operations
"dropDatabase",
"listDatabases",
"copydb",
"clone",
# GridFS operations
"filemd5"
]
}
},
# Capture all DDL (Data Definition Language) operations
{
"atype" = "authCheck",
"param.command" = {
"$in" = [
"create",
"drop",
"createIndexes",
"dropIndexes",
"collMod",
"renameCollection",
"dropDatabase",
"createCollection",
"dropCollection"
]
}
},
# Capture all user and role management operations
{
"atype" = "authCheck",
"param.command" = {
"$in" = [
"createUser",
"dropUser",
"dropAllUsersFromDatabase",
"updateUser",
"grantRolesToUser",
"revokeRolesFromUser",
"createRole",
"updateRole",
"dropRole",
"dropAllRolesFromDatabase",
"grantRolesToRole",
"revokeRolesFromRole",
"grantPrivilegesToRole",
"revokePrivilegesFromRole"
]
}
},
# Capture replica set operations
{
"atype" = "authCheck",
"param.command" = {
"$in" = [
"replSetGetStatus",
"replSetInitiate",
"replSetReconfig",
"replSetStepDown",
"replSetSyncFrom",
"replSetFreeze",
"replSetMaintenance",
"replSetGetConfig"
]
}
},
# Capture sharding operations
{
"atype" = "authCheck",
"param.command" = {
"$in" = [
"shardCollection",
"addShard",
"removeShard",
"movePrimary",
"enableSharding",
"split",
"moveChunk",
"mergeChunks"
]
}
},
# Capture administrative operations
{
"atype" = "authCheck",
"param.command" = {
"$in" = [
"shutdown",
"fsync",
"getParameter",
"setParameter",
"serverStatus",
"dbStats",
"collStats",
"currentOp",
"killOp",
"listCommands",
"buildInfo",
"hostInfo",
"connectionStatus",
"getCmdLineOpts",
"logRotate",
"planCacheClear",
"planCacheListFilters",
"planCacheSetFilter",
"planCacheClearFilters"
]
}
},
# Capture diagnostic operations
{
"atype" = "authCheck",
"param.command" = {
"$in" = [
"explain",
"profile",
"validate",
"dbHash",
"ping",
"ismaster",
"isMaster",
"hello"
]
}
},
# Capture connection and session events
{
"atype" = {
"$in" = [
"createSession",
"endSession",
"refreshSession"
]
}
},
# Capture transaction events
{
"atype" = "authCheck",
"param.command" = {
"$in" = [
"abortTransaction",
"commitTransaction",
"startTransaction"
]
}
},
# Capture change stream events
{
"atype" = "authCheck",
"param.command" = {
"$in" = [
"aggregate"
]
},
"param.pipeline" = {
"$elemMatch" = {
"$changeStream" = {
"$exists" = true
}
}
}
}
]
})
# Enable comprehensive auditing settings
audit_authorization_success = true # Audit both successful and failed operations
enabled = true # Enable auditing
}
# Variables
variable "mongodbatlas_public_key" {
default = ""
description = "MongoDB Atlas Public Key"
type = string
sensitive = true
}
variable "mongodbatlas_private_key" {
default = ""
description = "MongoDB Atlas Private Key"
type = string
sensitive = true
}
variable "atlas_org_id" {
default = ""
description = "MongoDB Atlas Organization ID"
type = string
}
variable "atlas_project_name" {
description = "MongoDB Atlas Project Name"
type = string
default = "Atlas Auditing Example"
}
# Outputs
output "cluster_connection_string" {
description = "Connection string for the Atlas cluster"
value = mongodbatlas_advanced_cluster.atlas-cluster.connection_strings[0].standard_srv
sensitive = true
}
output "cluster_id" {
description = "Atlas cluster ID"
value = mongodbatlas_advanced_cluster.atlas-cluster.cluster_id
}
output "project_id" {
description = "Atlas project ID"
value = mongodbatlas_project.atlas-project.id
}
output "auditing_enabled" {
description = "Whether auditing is enabled"
value = mongodbatlas_auditing.atlas-auditing.enabled
}

后退

审核和日志记录

在此页面上