对于AI助手:文档索引位于 https://www.mongodb.com/zh-cn/docs/llms.txt — 通过将 .md 附加到任何URL路径,可以获得所有页面的降价版本。
Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
MongoDB Branding Shape
Click here >
Docs 菜单

Atlas 资源策略

Atlas资源策略是控件,它启用Organization Owners 限制开发者在创建或配置Atlas集群时可以使用的特定配置选项。

注意

MongoDB Atlas责任共担模型定义了MongoDB及其客户在维护安全和弹性数据环境方面的互补职责。在此框架下, MongoDB管理根本的平台的安全性和操作完整性,而客户则负责其特定部署的配置、管理和数据策略。有关安全性和卓越运营之间所有权的详细划分,请参阅责任共担模型。

通过资源策略,您可以:

  • 限制可以在项目中创建的集群数量。

  • 将集群部署限制在特定的云平台(Amazon Web Services、 Google Cloud Platform、Azure)。

  • 将集群部署限制在云提供商内的指定区域。 示例,aws:us-east-1

  • 禁止使用通配符 IPv4 CIDR 范围(任何 /0 掩码,例如 0.0.0.0/010.0.0.0/0),以实施更严格的网络控制。

  • 通过要求IP访问列表保持为空或阻止向现有IP访问列表添加内容,禁止通过公共网络的流量。

    注意

    如果您将任何 IPv4 /0 CIDR(例如 0.0.0.0/010.0.0.0/0)添加到项目访问列表,Atlas 会向所有直接被授予项目角色或通过团队成员间接被授予项目角色(如果团队被授予项目角色)的所有用户发送警报电子邮件。

  • 要求项目配置维护窗口

  • 防止修改云提供商的VPC对等互连和私有端点连接。

  • 对集群连接实施最低TLS版本或要求特定的TLS密码套件配置。

  • 在整个组织中实施最小和最大集群层以及自动伸缩大小。如果启用,此策略将阻止用户将集群预配、更新或自动伸缩到高于或低于指定阈值的层级。

  • 要求分片的集群仅使用专用配置服务器,而不是嵌入式配置服务器。

  • 为所有集群强制执行最小和最大磁盘大小。

  • 实施仅使用特定的集群拓扑结构(副本集、集群或Atlas全球集群)。

  • 实施分片集群的最小和最大分片数。

  • 要求对项目中的所有集群进行数据库 Atlas 审核。

  • 需要使用客户管理的密钥对项目中的所有集群进行静态加密。

  • 需要使用客户托管的密钥对项目中所有专用搜索部署进行静态加密。

重要

默认情况下,Atlas资源策略是组织范围的。这些策略会自动在组织内的所有项目和集群中实施标准。

但是,Atlas提供了灵活性。如有必要,您可以从Atlas资源策略中排除特定项目。此功能允许大多数项目继承一致的组织范围标准,同时为具有独特需求的案例启用例外。

除了Atlas用户界面和Atlas管理API之外,您还可以使用 HashiCorp Terraform MongoDB Atlas Provider MongoDB Atlas Amazon Web Services CloudFormation Resources 或Amazon Web Services CloudFormation 来配置和管理Atlas资源策略。

注意

对于HashiCorp Terraform MongoDB Atlas Provider,请使用 1.33.0 或更高版本来实施最低TLS版本,或者要求为集群连接配置特定的TLS密码套件。Atlas可能会区块来自早期版本的 Terraform 的连接。

  • 我们强烈建议您使用 /orgs/{ORG-ID}/nonCompliantResources 端点主动监控不合规资源列表。Atlas资源策略确保合规既定目标,但不实施中间或过渡状态。示例,如果下游组件发生故障,策略可能会暂时进入不合规中间状态。

  • 每个Atlas资源策略都必须有一个唯一名称。如果您尝试使用现有名称创建Atlas资源策略,服务器将返回 400 (Bad Request) 状态代码。

  • 可以创建具有不同名称的相同Atlas资源策略。虽然这不会导致功能冲突,但可能导致策略管理冗余和混乱。

  • Atlas资源策略默认为允许。 如果不存在Atlas资源策略,则用户可以在Atlas集群上执行其Atlas 用户角色允许的所有操作。

  • 我们实施的Cedar 策略语言版本仅支持每个 .cedar文件一个 Cedar 策略,但您可以在Atlas资源策略中列出多个 Cedar 策略(.cedar 文件)。每个 .cedar文件在Atlas 管理 API响应中都标识为 policies.id 之后的唯一 24-十六进制字符串。

  • 如果现有集群的自动伸缩限制与新的Atlas资源策略不匹配,则集群可能会超出策略定义的边界。要解决此问题,请使用 /orgs/{ORG-ID}/nonCompliantResources 端点识别和监控不合规资源,以便对其更新以满足策略要求。

  • 如果现有的自动伸缩限制超过新的Atlas资源策略,集群可以继续自动扩展以超出策略边界。但是,您无法手动将集群扩展至超出策略限制。使用 /orgs/{ORG-ID}/nonCompliantResources 终结点识别和监控不合规资源。

  • 在启用网络层控制之前,查看现有的IP访问列表,确保其中包含所有必要的访问权限点。

  • Cedar 策略语言 中的私有端点定义要求您输入单个IP地址,因为不支持通配符操作。

  • 在实施磁盘大小时,请确保考虑实例大小的特定要求和云提供商限制。

  • 如果您实施大于 1 的最小分片数,则必须在策略中明确允许集群转换的过渡状态(示例&& !context.cluster.isConvertingToSharded )。如果没有这个例外, Atlas会阻止用户将副本集转换为分片集群,因为转换进程需要一种中间状态,在该状态下,集群只有一个分片。

  • Atlas将副本集视为分片计数为 1。如果您实施大于 1 的最小分片数而不检查集群是否为分片的集群,项目中的所有副本集都将被标记为不合规。

MongoDB使用开源Cedar 策略语言来定义Atlas资源策略。Cedar 的设计平衡了表现力和简单性,采用简洁的语法,简化了资源策略的编写和理解。

要快速创建Atlas资源策略,请调整示例并使用Atlas用户界面或Atlas管理API添加到Atlas ,具体方法请参阅创建Atlas资源策略配置。

要学习;了解有关Cedar 策略语言的更多信息,请参阅:

Cedar Element
Descripton
Atlas资源策略选项

forbid

如果满足 when 子句中的条件,则拒绝指定的动作。 Atlas资源策略中不允许使用反向元素 permit

示例: forbid (principal, action, resource) when { ... };

principal

定义受策略影响的用户。

默认下普遍应用。 请勿更改或省略。

action

表示策略中正在控制的动作。

可用操作:

  • 限制IP访问列表: ResourcePolicy::Action::"project.ipAccessList.modify"

  • 限制集群属性: ResourcePolicy::Action::"cluster.modify"

  • 修改维护窗口: ResourcePolicy::Action::"project.maintenanceWindow.modify"

  • 限制搜索索引修改: ResourcePolicy::Action::"search.index.modify"

  • 限制搜索部署操作: ResourcePolicy::Action::"search.deployment.modify"

ResourcePolicy::Cluster::"<CLUSTER-ID>"

指的是特定集群

要查找集群ID,请使用Atlas Administration API返回项目中的所有集群。

ResourcePolicy::Project::"<PROJECT_ID>"

指的是一个具体的项目。 示例, ResourcePolicy::Project::"6217f7fff7957854e2d09179"

要查找您的项目ID,请参阅 管理项目设置。

context.cluster.project

指定集群所属的项目。

要查找您的项目ID,请参阅 管理项目设置。

context.cluster.cloudProviders

指定允许的云提供商。

可用选项:

  • ResourcePolicy::CloudProvider::"aws"

  • ResourcePolicy::CloudProvider::"azure"

  • ResourcePolicy::CloudProvider::"gcp"

该值因操作而异。对于 cluster.modify,包含集群mongod节点的云提供商。对于 search.index.modify,包含mongod和MongoDB Search 节点的云提供商(当前状态)。对于 search.deployment.modify,包含请求完成后MongoDB Search 节点的云提供商。对于删除操作,此值为空。

context.cluster.clusterType

指定集群拓扑结构:副本集分片集群Atlas全球集群。

可用选项:

  • ResourcePolicy::ClusterType::"replicaset"

  • ResourcePolicy::ClusterType::"sharded"

  • ResourcePolicy::ClusterType::"geosharded"

context.cluster.diskSizeGB

指定磁盘大小(以GB为单位)。

示例,context.cluster.diskSizeGB < 100 会匹配存储小于 100 GB的集群。

context.cluster.minShardCount

当前的实际分片数量。仅用于实施 最小 分片计数。警告:请勿使用此属性来实施最大值

示例,context.cluster.minShardCount < 3 会匹配当前分片少于三个的集群。

context.cluster.maxShardCount

分片的最大可能数量。仅用于实施最大分片限制。警告:请勿使用此属性来实施最小值

示例,context.cluster.maxShardCount > 10 匹配具有十个以上分片的集群。

context.cluster.isConvertingToSharded

检查当前操作是否正在将副本集转换为分片集群。实施最小分片计数以允许初始转换时必需的。

例如, context.cluster.isConvertingToSharded == true

context.cluster.regions

根据部署区域限制访问权限。

示例,ResourcePolicy::Region::"aws:us-east-1"。有关按云提供商的可用区域列表,请参阅Amazon Web Services (AWS)Google Cloud Platform (GCP)Microsoft Azure。与 search.deployment.modify 一起使用时,包含请求完成后MongoDB搜索节点的区域。对于删除操作,此值为空。

context.cluster has <PROPERTY>

检查集群上下文中是否存在特定属性。

可用属性:

  • 最低常规类集群层minGeneralClassInstanceSizeValue

  • 最大常规类集群层maxGeneralClassInstanceSizeValue

  • 磁盘大小 (GB): diskSizeGB

context.cluster.minGeneralClassInstanceSizeValue

设置集群扩展到的最小集群层

示例,context.cluster.minGeneralClassInstanceSizeValue < 30 匹配当前层级或最小自动伸缩大小小于M30 的集群。

context.cluster.maxGeneralClassInstanceSizeValue

设置集群扩展到的最大集群层

示例,context.cluster.maxGeneralClassInstanceSizeValue < 60 匹配当前层级或最大自动伸缩大小小于M60 的集群。

context.cluster.encryptionAtRest.customerManagedKey.enabled

检查是否为集群启用了用于静态加密的客户管理密钥。与 cluster.modify操作一起使用。

示例,context.cluster.encryptionAtRest.customerManagedKey.enabled == false 检查集群是否未启用集合扫描 。

context.project.clustersInProject

指定项目中当前集群的数量。

示例,context.project.clustersInProject <= 3 会匹配具有三个或更少集群的项目。

context.project.hasDefinedMaintenanceWindow

要求项目配置维护窗口

示例,context.project.hasDefinedMaintenanceWindow == false 检查项目是否未配置维护窗口。

context.project.databaseAuditing.enabled

检查是否为项目启用了数据库 Atlas 审核。与 cluster.modify操作一起使用。

示例,context.project.databaseAuditing.enabled == false 检查项目是否禁用了数据库 Atlas 审核。

context.project.ipAccessList

指定可以访问权限集群的IP地址。

您可以区块通配符IP ip("0.0.0.0/0") 以增强安全性。

context.project.peeringConnections

指特定的VPC对等互连。

要针对特定的云提供商进行格式化,请参阅防止修改网络对对等互连。

context.project.privateEndpoints

指特定的私有端点。

要针对特定云提供商进行格式化,请参阅防止修改私有端点。

containsAnycontainsAll

检查是否包含列表中的一个或多个元素 (containsAny) 或所有元素 (containsAll)。

示例: context.cluster.regions.containsAny([ResourcePolicy::Region::"aws:us-east-1"])

unless

指定策略的例外情况。 除非满足某些条件,否则禁止采取行动。

示例: forbid (principal, action, resource) unless { condition };

isEmpty

检查列表是否为空。示例,禁止访问权限公共网络要求IP访问列表为空。

forbid (principal, action == ResourcePolicy::Action::"project.ipAccessList.modify", resource) unless { context.project.ipAccessList.isEmpty() };

逻辑操作符(&&||!

在一项策略中组合多个条件。

可用选项:

  • && (AND):要求所有条件都为 true。

  • || (OR):要求至少有一个条件为 true。

  • ! (NOT):要求条件为 false。

context.cluster.configServerManagementMode

检查分片的集群上的配置服务器管理模式。

可用选项:

  • ResourcePolicy::ConfigServerManagementMode::"fixed_to_dedicated" 用于专用配置服务器。

  • ResourcePolicy::ConfigServerManagementMode::"atlas_managed" 用于嵌入式配置服务器。

context.search.hasDedicatedNodes

检查集群是否有专用的MongoDB搜索节点。对于 search.deployment.modify,此属性反映请求完成后的状态,而不是当前状态。

示例,context.search.hasDedicatedNodes == true。与 search.index.modifysearch.deployment.modify 操作一起使用。

context.search.hasIndexes

检查集群是否具有MongoDB Search 索引。

示例,context.search.hasIndexes == true。与 search.deployment.modifycluster.modify 操作一起使用。

context.search.encryptionAtRest.customerManagedKey.enabled

检查是否为专用搜索部署有效启用了用于静态加密的客户托管密钥。仅当启用两个搜索节点集合扫描且在项目级别配置了至少一个KMS提供商时,此值才计算为 true。与 search.deployment.modify操作一起使用。

示例,context.search.encryptionAtRest.customerManagedKey.enabled == false 检查搜索部署是否未有效启用集合扫描 。

IP寻址 (ip)

指策略中的特定IP地址或范围。

可用选项:

  • 特定IP地址,格式为 ip("1.2.3.4/32")

  • ip("0.0.0.0/0") 用于通配符IP。任何 IPV4 /0 CIDR 都代表完整的 IPv4解决空间。 Atlas将此类 CIDR 标准化为 0.0.0.0/0,以便进行策略评估。

context.search.index.isAutoEmbed

检查搜索索引是否使用自动嵌入。如果为 true,search index 使用 Voyage AI embedding model 自动生成 vector embeddings。

示例: context.search.index.isAutoEmbed == true

这会匹配使用自动嵌入的索引,并允许您限制创建或修改自动嵌入索引,以合规或费用管理。您仍然可以创建 vector 类型索引。

要创建Atlas资源策略,请按照以下过程使用Cedar 策略语言构建策略,并使用Atlas用户用户界面、 Atlas管理API或 Terraform 添加到Atlas 。

警告

我们建议您在非生产环境中测试此功能,方法是使用新集群创建新组织。 这可确保您可以安全地评估该功能,而在提高技能时不会影响现有系统。

要使用 Atlas 管理 API 创建 Atlas 资源策略,请使用 Cedar 策略语言 构建策略,并通过 POST 请求使用 policies 参数将其传递给 Atlas 管理 API 。

2

使用 POST 动词为您的组织创建Atlas资源策略。 该请求必须包括:

  • name: Atlas资源策略的名称。

  • policies : 您在上一步中用Cedar 策略语言定义的集群限制。如果在 policies.body 中使用引号 ("),请使用反斜杠 (\) 转义。

POST请求示例:

注意

curl 命令使用服务帐户访问权限令牌 (OAuth 2.0) 而不是API密钥进行身份验证。要学习;了解更多信息,请参阅Atlas 管理 API入门。

curl --header "Authorization: Bearer {ACCESS-TOKEN}" \
--header "Content-Type: application/json" \
--header "Accept: application/vnd.atlas.2024-08-05+json" \
--include \
--request POST "https://cloud.mongodb.com/api/atlas/v2/orgs/{ORG-ID}/resourcePolicies?pretty=true" \
--data '{
"name": "MyResourcePolicy",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when {context.cluster.regions.contains(ResourcePolicy::Region::\"aws:us-west-1\")};"
}
]
}'

响应示例:

1{
2 "createdByUser" : {
3 "id" : "66ce81217d08f463824f3b80",
4 "name" : "ecwwjhop"
5 },
6 "createdDate" : "2024-08-28T02:22:49Z",
7 "id" : "66ce89f9b535d00a2cb02f83",
8 "lastUpdatedByUser" : {
9 "id" : "66ce81217d08f463824f3b80",
10 "name" : "ecwwjhop"
11 },
12 "lastUpdatedDate" : "2024-08-28T02:22:49Z",
13 "name" : "MyResourcePolicy",
14 "orgId" : "{ORG-ID}",
15 "policies" : [ {
16 "body" : "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when {context.cluster.regions.contains(ResourcePolicy::Region::\"aws:us-west-1\")};",
17 "id" : "66ce89f9b535d00a2cb02f82"
18 } ],
19 "version" : "v1"

要使用新的Atlas用户界面编辑器创建Atlas资源策略,请使用以下过程将示例策略复制并粘贴到编辑器中,然后根据您的组织对其进行修改。

1
  1. 如果尚未显示,组织从导航栏中的Organizations菜单。

  2. 在侧边栏中,单击 Organization Settings

显示“组织设置”页面。

2

在侧边栏中,单击 Configurations 标题下的 Resource Policies

显示“资源策略”页面。

3
4
  1. 为您的Atlas资源策略指定一个唯一名称。

  2. (可选)添加说明。

  3. 复制并修改组织的以下示例策略,然后将代码粘贴到 Cedar Policy字段中。

    注意

    我们建议创建多个简单的Atlas资源策略,以便更轻松地进行跟踪。 示例,如果您想限制云提供商和多个地区,请考虑创建一个限制云提供商的Atlas资源策略和另一个限制地区的Atlas资源策略。

5

此Atlas资源策略适用于所有新集群。对于不符合Atlas资源策略的现有集群, Atlas只允许用户对集群进行更改,以使集群合规。示例,如果 cluster0Amazon Web Services上运行,而您应用了阻止Amazon Web Services上的集群的Atlas资源策略,则在 cluster0 不合规时,用户可以对它进行的唯一更改是将云提供商切换到Azure或Google Cloud Platform。

要返回不符合Atlas资源策略的现有集群列表,请使用GET /orgs/{ORG- ID}/nonCompliantResources资源。

当您创建、更新或删除Atlas资源策略时, Atlas会生成操作日志事件。为了帮助识别操作日志事件并简化跟踪,我们建议创建多个简单的Atlas资源策略。示例,如果您想限制云提供商和多个区域的使用,可以考虑创建一个限制云提供商的Atlas资源策略和另一个限制区域的Atlas资源策略。

注意

其他先决条件

请先完成以下步骤,然后再继续阅读本指南:

要使用 Terraform 创建 Atlas 资源策略,请配置 MongoDB Atlas Terraform 提供程序,然后使用 Cedar 策略语言 构建策略并在 main.tf Terraform 文件中指定它。

1

在项目目录中创建一个名为 main.tf 的新文件。粘贴以下代码,用于配置MongoDB Atlas Provider 并指定公钥和私钥:

terraform {
required_version = ">=1.4"
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "~>1.31"
}
}
}
provider "mongodbatlas" {}
variable "org_id" {
type = string
description = "<Organization ID>"
}

创建文件后,运行以下命令以下载最新版本的提供商并初始化 Terraform:

terraform init -upgrade
2

使用 Cedar 策略语言 指定限制资源的规则。您可以复制并修改组织的以下示例策略:

注意

我们建议创建多个简单的Atlas资源策略,以便更轻松地进行跟踪。 示例,如果您想限制云提供商和多个地区,请考虑创建一个限制云提供商的Atlas资源策略和另一个限制地区的Atlas资源策略。

3

main.tf文件中定义所需的策略后,运行以下命令以创建策略:

terraform apply

复制并修改以下示例策略以用于您的组织。所有示例都使用 Cedar 策略语言,但对于Atlas Administration API,这些示例包装在JSON中,因此您可以将它们直接粘贴到API调用中。要学习;了解更多信息,请参阅创建Atlas资源策略配置。

以下示例禁止用户在项目中创建超过 2 个集群:

{
"name": "Prohibit More Than 2 Clusters in a Project",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { context.project.clustersInProject > 2 };"
}
]
}

以下示例禁止用户在Google Cloud Platform上创建集群:

{
"name": "Policy Preventing GCP Clusters",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { context.cluster.cloudProviders.contains(ResourcePolicy::CloudProvider::\"gcp\") };"
}
]
}

以下示例使用unless 子句允许用户仅在Google Cloud Platform上创建集群:

{
"name": "Policy Allowing Only GCP Clusters",
"policies": [
{
"body": "forbid(principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) unless { context.cluster.cloudProviders == [ResourcePolicy::CloudProvider::\"gcp\"] };"
}
]
}

以下示例使用 when 子句防止用户在ID为 6217f7fff7957854e2d09179 的项目中创建或编辑集群,除非Google Cloud Platform是唯一的云提供商:

{
"name": "Policy Allowing Only GCP Clusters for One Project",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { resource in ResourcePolicy::Project::\"6217f7fff7957854e2d09179\" && context.cluster.cloudProviders == [ResourcePolicy::CloudProvider::\"gcp\"] };"
}
]
}

当Google Cloud Platform是云提供商时,以下示例阻止对ID为 3217e2gdf79a4c54e2d0827 的集群进行修改:

{
"name": "Forbid Modifications to Specific GCP Cluster",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { resource in ResourcePolicy::Project::\"65dcbf5ccd12a54df59a54e6\" && resource == ResourcePolicy::Cluster::\"670968dfc0a2297ef46bc02a\" && context.cluster.cloudProviders == [ResourcePolicy::CloudProvider::\"gcp\"]};"
}
]
}

以下示例禁止用户在地区aws:us-east-1 中创建或编辑集群:

{
"name": "Prohibit Cluster Deployment in the US-EAST-1 Region",
"policies": [
{
"body": "forbid (principal,action == ResourcePolicy::Action::\"cluster.modify\",resource) when {context.cluster.regions.contains(ResourcePolicy::Region::\"aws:us-east-1\")};"
}
]
}

以下示例禁止用户在地区aws:us-west-1 中创建集群:

{
"name": "Policy Preventing Clusters in AWS:us-west-1",
"policies": [
{
"body": "forbid(principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { context.cluster.regions.contains(ResourcePolicy::Region::\"aws:us-west-1\") };"
}
]
}

以下示例禁止用户在 aws:us-east-1aws:us-west-1azure:westeurope 区域中创建集群:

{
"name": "Policy Preventing Clusters in 3 AWS Regions",
"policies": [
{
"body": "forbid(principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { context.cluster.regions.containsAny([ResourcePolicy::Region::\"aws:us-east-1\", ResourcePolicy::Region::\"aws:us-west-1\", ResourcePolicy::Region::\"azure:westeurope\"]) };"
}
]
}

以下示例使用unless 子句,允许用户仅在区域aws:us-east-1azure:westeurope 中创建集群:

{
"name": "Policy Allowing Clusters Only in 2 AWS Regions",
"policies": [
{
"body": "forbid(principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) unless { [ResourcePolicy::Region::\"aws:us-east-1\", ResourcePolicy::Region::\"azure:westeurope\"].containsAll(context.cluster.regions) };"
}
]
}

以下示例使用 when 子句限制用户在区域 aws:us-east-1aws:us-west-1 中编辑ID为 3217e2gdf79a4c54e2d0827 的集群:

{
"name": "Policy Restricting Edits to One Cluster from 2 AWS Regions",
"policies": [
{
"body": "forbid(principal, action == ResourcePolicy::Action::\"cluster.modify\", resource == ResourcePolicy::Cluster::\"3217e2gdf79a4c54e2d0827\") when { context.cluster.regions.containsAny([ResourcePolicy::Region::\"aws:us-east-1\",ResourcePolicy::Region::\"aws:us-west-1\"]) };"
}
]
}

以下示例限制Atlas用户在Google Cloud Platform或Amazon Web Services区域 aws:us-east-1aws:us-west-1 中创建Atlas集群。

{
"name": "Policy Restricting All GCP Clusters and Some AWS Regions",
"policies": [
{
"body": "forbid (principal,action == ResourcePolicy::Action::\"cluster.modify\", resource) when {context.cluster.cloudProviders.containsAny([ResourcePolicy::CloudProvider::\"gcp\"]) || context.cluster.regions.containsAny([ResourcePolicy::Region::\"aws:us-east-1\", ResourcePolicy::Region::\"aws:us-west-1\"])};"}
}
]
}

注意

如果您将任何 IPv4 /0 CIDR(例如 0.0.0.0/010.0.0.0/0)添加到项目访问列表,Atlas 会向所有直接被授予项目角色或通过团队成员间接被授予项目角色(如果团队被授予项目角色)的所有用户发送警报电子邮件。

以下示例禁止用户从通配符IP (0.0.0.0/0) 编辑项目。Atlas将任何 IPv4 /0 CIDR 视为相当于 0.0.0.0/0 的通配符,因此此策略也会阻止 10.0.0.0/01.2.3.4/0 之类的条目。:

{
"name": "Policy Restricting Wildcard IP",
"policies": [
{
"body": "forbid(principal, action == ResourcePolicy::Action::\"project.ipAccessList.modify\", resource) when { context.project.ipAccessList.contains(ip(\"0.0.0.0/0\")) };"
}
]
}

以下示例使用unless 子句,允许用户仅编辑来自IP地址1.2.3.4/328.8.8.8/324.4.4.4/32 的项目:

{
"name": "Policy Restricting Project Edits to Specified IPs",
"policies": [
{
"body": "forbid(principal, action == ResourcePolicy::Action::\"project.ipAccessList.modify\", resource) unless { [ip(\"1.2.3.4/32\"), ip(\"8.8.8.8/32\"), ip(\"4.4.4.4/32\")].containsAll(context.project.ipAccessList) };"
}
]
}

以下示例要求IP访问列表为空,以确保禁止通过公共网络流向集群的所有流量。

{
"name": "Policy Preventing Access Over Public Networks",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"project.ipAccessList.modify\", resource) unless {context.project.ipAccessList.isEmpty() };"
}
]
}

以下示例使用 when 子句将Atlas预配或扩展集群限制为小于 M30 或大于 M60

注意

此策略不限制集群类别为 Low CPU NVMe 固态硬盘的集群类。

{
"name": "Policy Restricting Min/Max Cluster Size",
"policies": [
{
"body": "forbid(principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { (context.cluster has minGeneralClassInstanceSizeValue && context.cluster.minGeneralClassInstanceSizeValue < 30) || (context.cluster has maxGeneralClassInstanceSizeValue && context.cluster.maxGeneralClassInstanceSizeValue > 60) };"
}
]
}

以下示例要求项目配置维护窗口

{
"name": "Policy Enforcing Existence of a Project Maintenance Window",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"project.maintenanceWindow.modify\", resource) when {context.project.hasDefinedMaintenanceWindow == false};"
}
]
}

以下示例要求先对项目启用数据库 Atlas 审核,然后才能创建或修改集群:

{
"name": "Require database auditing",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { !context.project.databaseAuditing.enabled };"
}
]
}

以下示例要求在项目中的所有集群上启用用于静态加密的客户托管密钥:

{
"name": "Require CMK on clusters",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { !context.cluster.encryptionAtRest.customerManagedKey.enabled };"
}
]
}

以下示例要求在项目中的所有专用搜索部署上启用用于静态加密的客户托管密钥:

{
"name": "Require CMK on search deployments",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"search.deployment.modify\", resource) when { !context.search.encryptionAtRest.customerManagedKey.enabled };"
}
]
}

以下示例在所有组织数据(集群和搜索节点)上实施客户管理的密钥,并将部署限制为仅适用于 AWS。三项策略必须一起应用:

策略 1:要求在此项目中的所有集群上使用集合扫描

{
"name": "Require CMK on clusters",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { !context.cluster.encryptionAtRest.customerManagedKey.enabled };"
}
]
}

策略 2:要求在此项目中的所有搜索部署上使用集合扫描

{
"name": "Require CMK on search deployments",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"search.deployment.modify\", resource) when { !context.search.encryptionAtRest.customerManagedKey.enabled };"
}
]
}

策略3 :将集群和搜索部署限制为仅限 AWS

{
"name": "Restrict to AWS only",
"policies": [
{
"body": "forbid (principal, action in [ResourcePolicy::Action::\"cluster.modify\", ResourcePolicy::Action::\"search.deployment.modify\"], resource) when { !([ResourcePolicy::CloudProvider::\"aws\"].containsAll(context.cluster.cloudProviders)) };"
}
]
}

注意

搜索节点从其集群继承加密,因此对静态数据实施集合扫描还要求集群本身使用集合扫描。集群和搜索部署都可以部署在不同的云提供商上。目前,只有 AWS 支持搜索节点集合扫描,因此需要所有三项策略来确保完全覆盖。

以下示例防止修改不同云提供商( Amazon Web Services 、Google Cloud Platform、 Azure )之间的 VPC 对等连接。

每个云提供商需要不同的VPC对等互连详细信息。收集您的云提供商的以下详细信息,并将其替换到示例中:

Amazon Web Services: aws:<AWS_ACCOUNT_ID>:<VPC_ID>:<VPC_CIDR>

  • AWS_ACCOUNT_ID:您的 AWS 帐号。

  • VPC_ID VPC的ID

  • VPC_CIDR VPC的 CIDR区块。

Azure: azure:<SUBSCRIPTION_ID>:<RESOURCE_GROUP_NAME>:<VNET_NAME>

  • SUBSCRIPTION_ID:您的Azure订阅ID。

  • RESOURCE_GROUP_NAME:虚拟网络 (VNet) 所在的资源群组。

  • VNET_NAME:VNet 的名称。

Google Cloud: gcp:<GCP_PROJECT_ID>:<VPC_NAME>

  • GCP_PROJECT_ID: Google Cloud Platform项目的ID 。

  • VPC_NAME:Google Cloud 中VPC的名称。

{
"name": "Policy Preventing Modifications to Peering Across Providers",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"project.vpcPeering.modify\", resource) when {context.project.peeringConnections == [\"aws:000123456789:vpc-0316c47cc923ce313:10.0.0.0/16\", \"azure:fd01aafc-b3re-2193-8497-83lp3m83a1a5:rg-name:vnet\", \"gcp:inductive-cocoa-108200:default\"]};"
}
]
}

以下示例防止跨云提供商(Amazon Web Services、Google Cloud Platform、Azure)修改私有端点连接。

每个云提供商要求提供不同的私有端点详细信息。收集您的云提供商的以下详细信息,并将其替换到示例中:

Amazon Web Services: aws:<VPC_ENDPOINT_ID>

  • VPC_ENDPOINT_ID:AWS VPC端点的ID

Azure: azure:<PRIVATE_ENDPOINT_RESOURCE_ID>:<PRIVATE_ENDPOINT_IP_ADDRESS>

  • PRIVATE_ENDPOINT_RESOURCE_ID Azure私有端点的完整资源ID路径。

  • PRIVATE_ENDPOINT_IP_ADDRESS:分配给私有端点的IP解决。

Google Cloud: gcp:<GCP_PROJECT_ID>:<VPC_NAME>

  • GCP_PROJECT_ID: Google Cloud Platform项目的ID 。

  • VPC_NAME:Google Cloud 中与该连接关联的VPC的名称。

{
"name": "Policy Preventing Modifications to Private Endpoints Across Providers",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"project.privateEndpoint.modify\", resource) when {context.project.privateEndpoints == [\"aws:vpce-042d72ded1748f314\", \"azure:/subscriptions/fd01aafc-b3re-2193-8497-83lp3m83a1a5/resourceGroups/rg-name/providers/Microsoft.Network/privateEndpoints/pe-name:10.0.0.4\", \"gcp:inductive-cocoa-108200:default\"]};"
}
]
}

以下示例将集群接受的传入连接的最低TLS版本限制为TLS 1.2。

minTLSVersion 的可能值包括:

  • TLS 1.0: ResourcePolicy::TLSVersion::\"tls1_0\"

  • TLS 1.1: ResourcePolicy::TLSVersion::\"tls1_1\"

  • TLS 1.2: ResourcePolicy::TLSVersion::\"tls1_2\"

{
"name": "Policy Restricting Cluster Connections to Minimum TLS 1.2",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) unless {context.cluster.minTLSVersion == ResourcePolicy::TLSVersion::\"tls1_2\"};"
}
]
}

以下示例要求集群通过设置 ResourcePolicy::CipherConfigMode::\"custom\" 使用自定义 TLS 密码套件配置 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384

自定义 TLS 密码套件配置的可能值为:

  • ResourcePolicy::CipherSuite::\"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384\"

  • ResourcePolicy::CipherSuite::\"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256\"

{
"name": "Policy Requiring Specific TLS Cipher Suite",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) unless {context.cluster.cipherConfigMode == ResourcePolicy::CipherConfigMode::\"custom\" && context.cluster.cipherSuites == [ResourcePolicy::CipherSuite::\"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384\"]};"
}
]
}

以下示例要求集群使用默认TLS密码套件配置。

{
"name": "Policy Requiring Default TLS Cipher Suite",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) unless {context.cluster.cipherConfigMode == ResourcePolicy::CipherConfigMode::\"default\"};"
}
]
}

以下示例通过禁止任何大于 (>) 限制的值来实施 4 TB 的最大磁盘大小。

要防止创建小于特定大小的集群,请在禁止策略中使用小于操作符(<)。

{
"name": "Limit Max Disk Size to 4000GB",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { context.cluster has diskSizeGB && context.cluster.diskSizeGB > 4096 };"
}
]
}

以下示例允许用户创建副本集集群。

{
"name": "Require Replica Set Clusters",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) unless { context.cluster.clusterType == ResourcePolicy::ClusterType::\"replicaset\" };"
}
]
}

要支持不同的集群拓扑结构,请使用以下值之一:

  • 分片集群ResourcePolicy::ClusterType::"sharded" 用于标准水平扩展,其中数据分布式在多个分片上以支持大型数据集或高吞吐量。

  • Atlas全球集群ResourcePolicy::ClusterType::"geosharded" 用于位置感知部署,其中数据分布式在特定地理区域,以确保数据靠近用户。

以下示例要求分片的集群至少有三个分片。

重要

  • 如果实施大于 1 的最小分片数,则必须在策略中明确允许集群转换的过渡状态(示例&& !context.cluster.isConvertingToSharded)。如果没有这个例外,Atlas会阻止用户将副本集转换为集群,因为转换进程需要一种中间状态,在该状态下,集群只有一个分片。

  • Atlas将副本集视为分片计数为 1。如果您实施大于 1 的最小分片数而不检查集群是否为分片的集群,项目中的所有副本集都将被标记为不合规。

  • 使用 minShardCount 仅实施最小值(示例,< 3),使用 maxShardCount 仅实施最大值(示例,> 10)。对这些属性使用相反的比较操作符会导致策略评估错误。

{
"name": "Require Minimum 3 Shards",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { context.cluster.minShardCount < 3 && !context.cluster.isConvertingToSharded };"
}
]
}

以下示例可防止用户创建具有嵌入式配置服务器的分片的集群,确保他们从一开始就使用专用的配置服务器。

{
"name": "Enforce config server management mode to fixed_to_dedicated for sharded clusters",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when { context.cluster.clusterType == ResourcePolicy::ClusterType::\"sharded\" && context.cluster has configServerManagementMode && context.cluster.configServerManagementMode != ResourcePolicy::ConfigServerManagementMode::\"fixed_to_dedicated\" };"
}
]
}

注意

search.index.modify操作限制仅创建和修改MongoDB Search索引。Atlas始终允许删除MongoDB Search 索引。

以下示例禁止用户添加或编辑MongoDB搜索索引,除非存在专用的MongoDB搜索节点:

{
"name": "Require Search Nodes Before Adding Search Indexes",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"search.index.modify\", resource) when { !context.search.hasDedicatedNodes };"
}
]
}

以下示例禁止用户创建或修改使用 autoEmbed 类型的搜索索引。这样,您就可以出于合规或费用管理的目的限制自动嵌入的使用,同时仍允许创建 vector 类型索引。

{
"name": "Prevent Automated Embedding Indexes",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"search.index.modify\", resource) when { context.search.index.isAutoEmbed };"
}
]
}

以下示例将阻止用户添加或编辑MongoDB搜索索引,除非存在专用的MongoDB搜索节点且全部位于 AWS 上:

{
"name": "Require Search Nodes on AWS Before Adding Search Indexes",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"search.index.modify\", resource) when { !context.search.hasDedicatedNodes || !([ResourcePolicy::CloudProvider::\"aws\"].containsAll(context.cluster.cloudProviders)) };"
}
]
}

以下示例禁止用户从具有MongoDB Search 索引的集群中删除专用的MongoDB Search 节点:

{
"name": "Prevent Removing Search Nodes When Indexes Exist",
"policies": [
{
"body": "forbid (principal, action == ResourcePolicy::Action::\"search.deployment.modify\", resource) when { context.search.hasIndexes && !context.search.hasDedicatedNodes };"
}
]
}

以下示例禁止将MongoDB Search 部署到具有MongoDB Search 索引的集群上的非AWS提供商:

{
"name": "Prevent Non-AWS Search Deployment When Indexes Exist",
"policies": [
{
"body": "forbid (principal, action in [ResourcePolicy::Action::\"cluster.modify\", ResourcePolicy::Action::\"search.deployment.modify\"], resource) when { context.search.hasIndexes && !([ResourcePolicy::CloudProvider::\"aws\"].containsAll(context.cluster.cloudProviders)) };"
}
]
}

以下示例禁止用户在项目中创建超过 2 个集群:

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { context.project.clustersInProject > 2 };

以下示例禁止用户在Google Cloud Platform上创建集群:

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { context.cluster.cloudProviders.contains(ResourcePolicy::CloudProvider::"gcp") };

以下示例使用unless 子句允许用户仅在Google Cloud Platform上创建集群:

forbid(
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
unless { context.cluster.cloudProviders == [ResourcePolicy::CloudProvider::"gcp"] };

以下示例使用 when 子句防止用户在ID为 6217f7fff7957854e2d09179 的项目中创建或编辑集群,除非Google Cloud Platform是唯一的云提供商:

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when {resource in ResourcePolicy::Project::"6217f7fff7957854e2d09179" && context.cluster.cloudProviders == [ResourcePolicy::CloudProvider::"gcp"] };

当Google Cloud Platform是云提供商时,以下示例阻止对ID为 3217e2gdf79a4c54e2d0827 的集群进行修改:

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when {resource in ResourcePolicy::Project::"65dcbf5ccd12a54df59a54e6" && resource == ResourcePolicy::Cluster::"670968dfc0a2297ef46bc02a" && context.cluster.cloudProviders == [ResourcePolicy::CloudProvider::"gcp"]};

以下示例禁止用户在地区aws:us-east-1 中创建或编辑集群:

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when {context.cluster.regions.contains(ResourcePolicy::Region::"aws:us-east-1")};

以下示例禁止用户在地区aws:us-west-1 中创建集群:

forbid(
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { context.cluster.regions.contains(ResourcePolicy::Region::"aws:us-west-1") };

以下示例禁止用户在 aws:us-east-1aws:us-west-1azure:westeurope 区域中创建集群:

forbid(
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { context.cluster.regions.containsAny([ResourcePolicy::Region::"aws:us-east-1",ResourcePolicy::Region::"aws:us-west-1",ResourcePolicy::Region::"azure:westeurope"]) };

以下示例使用unless 子句,允许用户仅在区域aws:us-east-1azure:westeurope 中创建集群:

forbid(
principal,
action == ResourcePolicy::Action::\"cluster.modify\",
resource
)
unless { [ResourcePolicy::Region::"aws:us-east-1", ResourcePolicy::Region::"azure:westeurope"].containsAll(context.cluster.regions) };

以下示例使用 when 子句限制用户在区域 aws:us-east-1aws:us-west-1 中编辑ID为 3217e2gdf79a4c54e2d0827 的集群:

forbid(
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource == ResourcePolicy::Cluster::"3217e2gdf79a4c54e2d0827"
)
when { context.cluster.regions.containsAny([ResourcePolicy::Region::"aws:us-east-1",ResourcePolicy::Region::"aws:us-west-1"]) };

注意

如果您将任何 IPv4 /0 CIDR(例如 0.0.0.0/010.0.0.0/0)添加到项目访问列表,Atlas 会向所有直接被授予项目角色或通过团队成员间接被授予项目角色(如果团队被授予项目角色)的所有用户发送警报电子邮件。

以下示例禁止用户从通配符IP (0.0.0.0/0) 编辑项目:

forbid(
principal,
action == ResourcePolicy::Action::"project.ipAccessList.modify",
resource
)
when { context.project.ipAccessList.contains(ip("0.0.0.0/0")) };

以下示例使用unless 子句,允许用户仅编辑来自IP地址1.2.3.4/328.8.8.8/324.4.4.4/32 的项目:

forbid(
principal,
action == ResourcePolicy::Action::"project.ipAccessList.modify",
resource
)
unless { [ip("1.2.3.4/32"), ip("8.8.8.8/32"), ip("4.4.4.4/32")].containsAll(context.project.ipAccessList) };

以下示例要求IP访问列表为空,以确保禁止通过公共网络流向集群的所有流量。

forbid (
principal,
action == ResourcePolicy::Action::"project.ipAccessList.modify",
resource
)
unless { context.project.ipAccessList.isEmpty() };

以下示例使用 when 子句将Atlas预配或扩展集群限制为小于 M30 或大于 M60

注意

此策略不限制集群类别为 Low CPU NVMe 固态硬盘的集群类。

forbid(
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { (context.cluster has minGeneralClassInstanceSizeValue && context.cluster.minGeneralClassInstanceSizeValue < 30) || (context.cluster has maxGeneralClassInstanceSizeValue && context.cluster.maxGeneralClassInstanceSizeValue > 60) };

以下示例要求项目配置维护窗口

forbid (
principal,
action == ResourcePolicy::Action::"project.maintenanceWindow.modify",
resource
)
when {context.project.hasDefinedMaintenanceWindow == false};

以下示例要求先对项目启用数据库 Atlas 审核,然后才能创建或修改集群:

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { !context.project.databaseAuditing.enabled };

以下示例要求在项目中的所有集群上启用用于静态加密的客户托管密钥:

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { !context.cluster.encryptionAtRest.customerManagedKey.enabled };

以下示例要求在项目中的所有专用搜索部署上启用用于静态加密的客户托管密钥:

forbid (
principal,
action == ResourcePolicy::Action::"search.deployment.modify",
resource
)
when { !context.search.encryptionAtRest.customerManagedKey.enabled };

以下示例在所有组织数据(集群和搜索节点)上实施客户管理的密钥,并将部署限制为仅适用于 AWS。三项策略必须一起应用:

策略 1:要求在此项目中的所有集群上使用集合扫描

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { !context.cluster.encryptionAtRest.customerManagedKey.enabled };

策略 2:要求在此项目中的所有搜索部署上使用集合扫描

forbid (
principal,
action == ResourcePolicy::Action::"search.deployment.modify",
resource
)
when { !context.search.encryptionAtRest.customerManagedKey.enabled };

策略3 :将集群和搜索部署限制为仅限 AWS

forbid (
principal,
action in [
ResourcePolicy::Action::"cluster.modify",
ResourcePolicy::Action::"search.deployment.modify"
],
resource
)
when { !([ResourcePolicy::CloudProvider::"aws"].containsAll(context.cluster.cloudProviders)) };

注意

搜索节点从其集群继承加密,因此对静态数据实施集合扫描还要求集群本身使用集合扫描。集群和搜索部署都可以部署在不同的云提供商上。目前,只有 AWS 支持搜索节点集合扫描,因此需要所有三项策略来确保完全覆盖。

以下示例防止修改不同云提供商( Amazon Web Services 、Google Cloud Platform、 Azure )之间的 VPC 对等连接。

每个云提供商需要不同的VPC对等互连详细信息。收集您的云提供商的以下详细信息,并将其替换到示例中:

Amazon Web Services: aws:<AWS_ACCOUNT_ID>:<VPC_ID>:<VPC_CIDR>

  • AWS_ACCOUNT_ID:您的 AWS 帐号。

  • VPC_ID VPC的ID

  • VPC_CIDR VPC的 CIDR区块。

Azure: azure:<SUBSCRIPTION_ID>:<RESOURCE_GROUP_NAME>:<VNET_NAME>

  • SUBSCRIPTION_ID:您的Azure订阅ID。

  • RESOURCE_GROUP_NAME:虚拟网络 (VNet) 所在的资源群组。

  • VNET_NAME:VNet 的名称。

Google Cloud: gcp:<GCP_PROJECT_ID>:<VPC_NAME>

  • GCP_PROJECT_ID: Google Cloud Platform项目的ID 。

  • VPC_NAME:Google Cloud 中VPC的名称。

forbid (
principal,
action == ResourcePolicy::Action::"project.vpcPeering.modify",
resource
)
when {context.project.peeringConnections == ["aws:000123456789:vpc-0316c47cc923ce313:10.0.0.0/16", "azure:fd01aafc-b3re-2193-8497-83lp3m83a1a5:rg-name:vnet", "gcp:inductive-cocoa-108200:default"]};

以下示例防止跨云提供商(Amazon Web Services、Google Cloud Platform、Azure)修改私有端点连接。

每个云提供商要求提供不同的私有端点详细信息。收集您的云提供商的以下详细信息,并将其替换到示例中:

Amazon Web Services: aws:<VPC_ENDPOINT_ID>

  • VPC_ENDPOINT_ID:AWS VPC端点的ID

Azure: azure:<PRIVATE_ENDPOINT_RESOURCE_ID>:<PRIVATE_ENDPOINT_IP_ADDRESS>

  • PRIVATE_ENDPOINT_RESOURCE_ID Azure私有端点的完整资源ID路径。

  • PRIVATE_ENDPOINT_IP_ADDRESS:分配给私有端点的IP解决。

Google Cloud: gcp:<GCP_PROJECT_ID>:<PRIVATE_ENDPOINT_GROUP_NAME>

  • GCP_PROJECT_ID: Google Cloud Platform项目的ID 。

  • PRIVATE_ENDPOINT_GROUP_NAME:Google Cloud 中与连接关联的私有端点群组的名称。

Google Cloud 基于端口的路由: gcp:<GCP_PROJECT_ID>:<PRIVATE_ENDPOINT_NAME>:<PRIVATE_ENDPOINT_IP_ADDRESS>

  • GCP_PROJECT_ID: Google Cloud Platform项目的ID 。

  • PRIVATE_ENDPOINT_NAME:Google Cloud 中与连接关联的私有端点的名称。

  • PRIVATE_ENDPOINT_IP_ADDRESS:分配给私有端点的IP解决。

forbid (
principal,
action == ResourcePolicy::Action::"project.privateEndpoint.modify",
resource
)
when {context.project.privateEndpoints == ["aws:vpce-042d72ded1748f314", "azure:/subscriptions/fd01aafc-b3re-2193-8497-83lp3m83a1a5/resourceGroups/rg-name/providers/Microsoft.Network/privateEndpoints/pe-name:10.0.0.4", "gcp:inductive-cocoa-108200:default"]};

以下示例将集群接受的传入连接的最低TLS版本限制为TLS 1.2。

minTLSVersion 的可能值包括:

  • TLS 1.0: ResourcePolicy::TLSVersion::"tls1_0"

  • TLS 1.1: ResourcePolicy::TLSVersion::"tls1_1"

  • TLS 1.2: ResourcePolicy::TLSVersion::"tls1_2"

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
unless
{ context.cluster.minTLSVersion == ResourcePolicy::TLSVersion::"tls1_2" };

以下示例要求集群通过设置 ResourcePolicy::CipherConfigMode::"custom" 使用自定义 TLS 密码套件配置 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384

自定义 TLS 密码套件配置的可能值为:

  • ResourcePolicy::CipherSuite::"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"

  • ResourcePolicy::CipherSuite::"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
unless
{
context.cluster.cipherConfigMode == ResourcePolicy::CipherConfigMode::"custom" &&
context.cluster.cipherSuites == [ResourcePolicy::CipherSuite::"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"]
};

以下示例要求集群使用默认TLS密码套件配置。

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
unless
{
context.cluster.cipherConfigMode == ResourcePolicy::CipherConfigMode::"default"
};

以下示例通过禁止任何大于 (>) 限制的值来实施 4 TB 的最大磁盘大小。

要防止创建小于特定大小的集群,请在禁止策略中使用小于操作符(<)。

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when
{
context.cluster has diskSizeGB && context.cluster.diskSizeGB > 4096
};

以下示例允许用户创建副本集集群。

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
unless
{
context.cluster.clusterType == ResourcePolicy::ClusterType::"replicaset"
};

要支持不同的集群拓扑结构,请使用以下值之一:

  • 分片集群ResourcePolicy::ClusterType::"sharded" 用于标准水平扩展,其中数据分布式在多个分片上以支持大型数据集或高吞吐量。

  • Atlas全球集群ResourcePolicy::ClusterType::"geosharded" 用于位置感知部署,其中数据分布式在特定地理区域,以确保数据靠近用户。

以下示例要求分片的集群至少有三个分片。

重要

  • 如果实施大于 1 的最小分片数,则必须在策略中明确允许集群转换的过渡状态(示例&& !context.cluster.isConvertingToSharded)。如果没有这个例外,Atlas会阻止用户将副本集转换为集群,因为转换进程需要一种中间状态,在该状态下,集群只有一个分片。

  • Atlas将副本集视为分片计数为 1。如果您实施大于 1 的最小分片数而不检查集群是否为分片的集群,项目中的所有副本集都将被标记为不合规。

  • 使用 minShardCount 仅实施最小值(示例,< 3),使用 maxShardCount 仅实施最大值(示例,> 10)。对这些属性使用相反的比较操作符会导致策略评估错误。

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when
{
context.cluster.minShardCount < 3 && !context.cluster.isConvertingToSharded
};

以下示例可防止用户创建具有嵌入式配置服务器的分片的集群,确保他们从一开始就使用专用的配置服务器。

forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when
{
context.cluster.clusterType == ResourcePolicy::ClusterType::"sharded" &&
context.cluster has configServerManagementMode &&
context.cluster.configServerManagementMode != ResourcePolicy::ConfigServerManagementMode::"fixed_to_dedicated"
};

注意

search.index.modify操作限制仅创建和修改MongoDB Search索引。Atlas始终允许删除MongoDB Search 索引。

以下示例禁止用户添加或编辑MongoDB搜索索引,除非存在专用的MongoDB搜索节点:

forbid (
principal,
action == ResourcePolicy::Action::"search.index.modify",
resource
)
when { !context.search.hasDedicatedNodes };

以下示例禁止用户创建或修改使用 autoEmbed 类型的搜索索引。这样,您就可以出于合规或费用管理的目的限制自动嵌入的使用,同时仍允许创建 vector 类型索引。

forbid (
principal,
action == ResourcePolicy::Action::"search.index.modify",
resource
)
when { context.search.index.isAutoEmbed == true };

以下示例将阻止用户添加或编辑MongoDB搜索索引,除非存在专用的MongoDB搜索节点且全部位于 AWS 上:

forbid (
principal,
action == ResourcePolicy::Action::"search.index.modify",
resource
)
when {
!context.search.hasDedicatedNodes
|| !([ResourcePolicy::CloudProvider::"aws"].containsAll(
context.cluster.cloudProviders))
};

以下示例禁止用户从具有MongoDB Search 索引的集群中删除专用的MongoDB Search 节点:

forbid (
principal,
action == ResourcePolicy::Action::"search.deployment.modify",
resource
)
when { context.search.hasIndexes && !context.search.hasDedicatedNodes };

以下示例禁止将MongoDB Search 部署到具有MongoDB Search 索引的集群上的非AWS提供商:

forbid (
principal,
action in [
ResourcePolicy::Action::"cluster.modify",
ResourcePolicy::Action::"search.deployment.modify"
],
resource
)
when {
context.search.hasIndexes
&& !([ResourcePolicy::CloudProvider::"aws"].containsAll(
context.cluster.cloudProviders))
};

以下示例禁止用户在项目中创建超过 2 个集群:

resource "mongodbatlas_resource_policy" "forbid_more_than_two_clusters" {
org_id = var.org_id
name = "forbid-more-than-two-clusters"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { context.project.clustersInProject > 2 };
EOF
},
]
}

以下示例禁止用户在除Amazon Web Services之外的所有云提供商上创建集群:

resource "mongodbatlas_resource_policy" "allow_only_aws_cloud_provider" {
org_id = var.org_id
name = "cluster-allow-only-aws-cloud-provider"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
unless
{ context.cluster.cloudProviders == [ResourcePolicy::CloudProvider::"aws"] };
EOF
}]
}

以下示例使用unless 子句,允许用户仅在区域aws:us-east-1aws:eu-central-1 中创建集群:

resource "mongodbatlas_resource_policy" "allow_only_regions" {
org_id = var.org_id
name = "cluster-allow-only-regions"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
) unless {
[ResourcePolicy::Region::"aws:eu-west-1", ResourcePolicy::Region::"aws:eu-central-1"]
.containsAll(context.cluster.regions)};
EOF
},
]
}

以下示例使用 unless 子句,允许用户在 Google Cloud Platform 上或在 aws:us-east-1aws:eu-central-1 区域中创建集群:

resource "mongodbatlas_resource_policy" "allow_only_provider_regions" {
org_id = var.org_id
name = "cluster-allow-only-provider-regions"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
) unless {
context.cluster.cloudProviders == [ResourcePolicy::CloudProvider::"gcp"] ||
[ResourcePolicy::Region::"aws:eu-west-1", ResourcePolicy::Region::"aws:eu-central-1"]
.containsAll(context.cluster.regions)};
EOF
},
]
}

注意

如果您将任何 IPv4 /0 CIDR(例如 0.0.0.0/010.0.0.0/0)添加到项目访问列表,Atlas 会向所有直接被授予项目角色或通过团队成员间接被授予项目角色(如果团队被授予项目角色)的所有用户发送警报电子邮件。

以下示例禁止用户从通配符IP (0.0.0.0/0) 编辑项目:

resource "mongodbatlas_resource_policy" "forbid_project_access_anywhere" {
org_id = var.org_id
name = "forbid-project-access-anywhere"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"project.ipAccessList.modify",
resource
)
when {context.project.ipAccessList.contains(ip("0.0.0.0/0"))};
EOF
},
]
}

以下示例要求先对项目启用数据库 Atlas 审核,然后才能创建或修改集群:

resource "mongodbatlas_resource_policy" "require_database_auditing" {
org_id = var.org_id
name = "require-database-auditing"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { !context.project.databaseAuditing.enabled };
EOF
},
]
}

以下示例要求在项目中的所有集群上启用用于静态加密的客户托管密钥:

resource "mongodbatlas_resource_policy" "require_cmk_clusters" {
org_id = var.org_id
name = "require-cmk-on-clusters"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { !context.cluster.encryptionAtRest.customerManagedKey.enabled };
EOF
},
]
}

以下示例要求在项目中的所有专用搜索部署上启用用于静态加密的客户托管密钥:

resource "mongodbatlas_resource_policy" "require_cmk_search" {
org_id = var.org_id
name = "require-cmk-on-search-deployments"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"search.deployment.modify",
resource
)
when { !context.search.encryptionAtRest.customerManagedKey.enabled };
EOF
},
]
}

以下示例在所有组织数据(集群和搜索节点)上实施客户管理的密钥,并将部署限制为仅适用于 AWS。

resource "mongodbatlas_resource_policy" "require_cmk_clusters_aws" {
org_id = var.org_id
name = "require-cmk-clusters-aws-policy"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { !context.cluster.encryptionAtRest.customerManagedKey.enabled };
EOF
},
]
}
resource "mongodbatlas_resource_policy" "require_cmk_search_aws" {
org_id = var.org_id
name = "require-cmk-search-aws-policy"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"search.deployment.modify",
resource
)
when { !context.search.encryptionAtRest.customerManagedKey.enabled };
EOF
},
]
}
resource "mongodbatlas_resource_policy" "restrict_to_aws_only" {
org_id = var.org_id
name = "restrict-to-aws-only"
policies = [
{
body = <<EOF
forbid (
principal,
action in [
ResourcePolicy::Action::"cluster.modify",
ResourcePolicy::Action::"search.deployment.modify"
],
resource
)
when { !([ResourcePolicy::CloudProvider::"aws"].containsAll(context.cluster.cloudProviders)) };
EOF
},
]
}

注意

搜索节点从其集群继承加密,因此对静态数据实施集合扫描还要求集群本身使用集合扫描。集群和搜索部署都可以部署在不同的云提供商上。目前,只有 AWS 支持搜索节点集合扫描,因此需要所有三项策略来确保完全覆盖。

以下示例通过禁止任何大于 (>) 限制的值来实施 4 TB 的最大磁盘大小。

要防止创建小于特定大小的集群,请在禁止策略中使用小于操作符(<)。

resource "mongodbatlas_resource_policy" "limit_max_disk_size" {
org_id = var.org_id
name = "limit-max-4096gb-disk"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when { context.cluster has diskSizeGB && context.cluster.diskSizeGB > 4096 };
EOF
},
]
}

以下示例允许用户创建副本集集群。

resource "mongodbatlas_resource_policy" "require_replica_set" {
org_id = var.org_id
name = "require-replica-set"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
unless { context.cluster.clusterType == ResourcePolicy::ClusterType::"replicaset" };
EOF
},
]
}

要支持不同的集群拓扑结构,请使用以下值之一:

  • 分片集群ResourcePolicy::ClusterType::"sharded" 用于标准水平扩展,其中数据分布式在多个分片上以支持大型数据集或高吞吐量。

  • Atlas全球集群ResourcePolicy::ClusterType::"geosharded" 用于位置感知部署,其中数据分布式在特定地理区域,以确保数据靠近用户。

以下示例要求分片的集群至少有三个分片。

重要

  • 如果实施大于 1 的最小分片数,则必须在策略中明确允许集群转换的过渡状态(示例&& !context.cluster.isConvertingToSharded)。如果没有这个例外,Atlas会阻止用户将副本集转换为集群,因为转换进程需要一种中间状态,在该状态下,集群只有一个分片。

  • Atlas将副本集视为分片计数为 1。如果您实施大于 1 的最小分片数而不检查集群是否为分片的集群,项目中的所有副本集都将被标记为不合规。

  • 使用 minShardCount 仅实施最小值(示例,< 3),使用 maxShardCount 仅实施最大值(示例,> 10)。对这些属性使用相反的比较操作符会导致策略评估错误。

resource "mongodbatlas_resource_policy" "require_min_shards" {
org_id = var.org_id
name = "require-min-3-shards"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when {
context.cluster.minShardCount < 3 &&
!context.cluster.isConvertingToSharded
};
EOF
},
]
}

以下示例可防止用户创建具有嵌入式配置服务器的分片的集群,确保他们从一开始就使用专用的配置服务器。

resource "mongodbatlas_resource_policy" "enforce_dedicated_config_server" {
org_id = var.org_id
name = "enforce-dedicated-config-server"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"cluster.modify",
resource
)
when {
context.cluster.clusterType == ResourcePolicy::ClusterType::"sharded" &&
context.cluster has configServerManagementMode &&
context.cluster.configServerManagementMode != ResourcePolicy::ConfigServerManagementMode::"fixed_to_dedicated"
};
EOF
},
]
}

以下示例禁止用户创建或修改使用 autoEmbed 类型的搜索索引。这样,您就可以出于合规或费用管理的目的限制自动嵌入的使用,同时仍允许创建 vector 类型索引。

resource "mongodbatlas_resource_policy" "restrict_auto_embedding" {
org_id = var.org_id
name = "prevent-automated-embedding-indexes"
policies = [
{
body = <<EOF
forbid (
principal,
action == ResourcePolicy::Action::"search.index.modify",
resource
)
when { context.search.index.isAutoEmbed };
EOF
},
]
}