对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。

Atlas 资源策略概述

注意

本页面同时适用于 Atlas Infinite 和 Atlas Core。

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/0 或 10.0.0.0/0),以实施更严格的网络控制。

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

    注意

    如果您将任何 IPv4 /0 CIDR(例如 0.0.0.0/0 或 10.0.0.0/0)添加到项目访问列表中,Atlas 会向所有直接被授予该项目角色的用户发送告警邮件;对于通过团队成员身份间接获得项目角色的用户(前提是该团队已被授予项目角色),Atlas 也会发送告警邮件。

  • 要求项目配置维护窗口。

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

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

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

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

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

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

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

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

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

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

  • 防止项目启用原生重排序($rerank 聚合阶段)。

重要

默认情况下,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::Action::"project.rerank.modify"

  • 限制对 Atlas Embedding and Reranking API 的访问: ResourcePolicy::Action::"project.aiModelAPI.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 或 Microsoft Azure。与 search.deployment.modify 一起使用时,包含请求完成后 MongoDB Search 节点的区域。对于删除操作,此值为空。

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.rerankEnabled

检查项目是否启用了原生重新排序($rerank 聚合阶段)。与 project.rerank.modify 操作一起使用。

例如,context.project.rerankEnabled == true 匹配已启用原生重新排序的项目。这可防止用户启用原生重新排序,同时允许已启用原生重新排序的项目将其禁用。

context.project.ipAccessList

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

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

context.project.peeringConnections

指特定的VPC对等互连。

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

context.project.privateEndpoints

指特定的私有端点。

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

containsAny 和 containsAll

检查是否包含列表中的一个或多个元素 (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.modify 和 search.deployment.modify 操作一起使用。

context.search.hasIndexes

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

示例,context.search.hasIndexes == true。与 search.deployment.modify 和 cluster.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 类型索引。

context.aiModelApi.geography

指定 Geography,model API key 的作用域即限定于此。与 project.aiModelAPI.modify 操作一起使用。

可用选项:

  • ResourcePolicy::Geography::"eu" 适用于欧洲。

  • ResourcePolicy::Geography::"us" 适用于美国。

要创建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\")};" } ] }'

响应示例:

{ "createdByUser" : { "id" : "66ce81217d08f463824f3b80", "name" : "ecwwjhop" }, "createdDate" : "2024-08-28T02:22:49Z", "id" : "66ce89f9b535d00a2cb02f83", "lastUpdatedByUser" : { "id" : "66ce81217d08f463824f3b80", "name" : "ecwwjhop" }, "lastUpdatedDate" : "2024-08-28T02:22:49Z", "name" : "MyResourcePolicy", "orgId" : "{ORG-ID}", "policies" : [ { "body" : "forbid (principal, action == ResourcePolicy::Action::\"cluster.modify\", resource) when {context.cluster.regions.contains(ResourcePolicy::Region::\"aws:us-west-1\")};", "id" : "66ce89f9b535d00a2cb02f82" } ], "version" : "v1"

复制并修改以下示例策略以用于您的组织。所有示例都使用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-1、aws:us-west-1 或 azure: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-1 和azure: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-1 和 aws: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-1 或 aws: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/0 或 10.0.0.0/0)添加到项目访问列表中,Atlas 会向所有直接被授予该项目角色的用户发送告警邮件;对于通过团队成员身份间接获得项目角色的用户(前提是该团队已被授予项目角色),Atlas 也会发送告警邮件。

以下示例禁止用户从通配符IP (0.0.0.0/0) 编辑项目。Atlas将任何 IPv4 /0 CIDR 视为相当于 0.0.0.0/0 的通配符,因此此策略也会阻止 10.0.0.0/0 或 1.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/32 、8.8.8.8/32 和4.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) };" } ]}

以下示例限制对组织中所有项目的 Atlas Embedding and Reranking API 的访问。这有效防止用户为组织中的任何项目创建 模型 API 密钥。

{ "name": "Policy Restricting ERAS Access for All Projects", "policies": [ { "body": "forbid (principal, action == ResourcePolicy::Action::\"project.aiModelAPI.modify\", resource);" } ]}

您可以使用策略的 unless 子句将项目指定为例外。以下示例限制对组织中所有项目的 Embedding and Reranking API 的访问,但不包括 ID 为 6217f7fff7957854e2d09179 的项目:

{ "name": "Policy Restricting ERAS Access for All Projects Except One", "policies": [ { "body": "forbid (principal, action == ResourcePolicy::Action::\"project.aiModelAPI.modify\", resource) unless { resource in ResourcePolicy::Project::\"6217f7fff7957854e2d09179\" };" } ]}

您还可以限制用户可以将模型 API 密钥限定在其中的 地理区域。以下示例允许用户仅为欧洲地理区域创建模型 API 密钥:

{ "name": "Policy Restricting ERAS Access to the Europe Geography", "policies": [ { "body": "forbid (principal, action == ResourcePolicy::Action::\"project.aiModelAPI.modify\", resource) unless { context.aiModelApi.geography == ResourcePolicy::Geography::\"eu\" };" } ]}

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

{ "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:您的Amazon Web Services帐号。

  • 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 Platform中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: Amazon Web Services 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 Platform中与该连接关联的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.3。

minTLSVersion 的可能值包括:

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

  • TLS 1.3: ResourcePolicy::TLSVersion::\"tls1_3\"

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

以下示例要求集群通过设置 ResourcePolicy::CipherConfigMode::\"custom\" 来使用自定义 TLS 密码套件配置 TLS_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\"

  • ResourcePolicy::CipherSuite::\"TLS_AES_256_GCM_SHA384\"

  • ResourcePolicy::CipherSuite::\"TLS_CHACHA20_POLY1305_SHA256\"

  • ResourcePolicy::CipherSuite::\"TLS_AES_128_GCM_SHA256\"

  • ResourcePolicy::CipherSuite::\"TLS_AES_128_CCM_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_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 Search 索引,除非存在专用的 MongoDB Search 节点,并且全部都在 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)) };" } ]}

以下示例防止用户为组织中的任何项目启用原生重排名($rerank 聚合阶段)。此策略可阻止项目启用原生重新排序,但不会对已启用原生重新排序的项目禁用 $rerank。要对已启用原生重新排序的项目禁用原生重新排序,请参阅 启用或禁用原生重新排序。

{ "name": "Restrict Native Reranking", "policies": [ { "body": "forbid (principal, action == ResourcePolicy::Action::\"project.rerank.modify\", resource) when { context.project.rerankEnabled == true };" } ]}

要允许对特定项目进行原生重排,请使用 unless 子句将其排除:

{ "name": "Restrict Native Reranking with Exceptions", "policies": [ { "body": "forbid (principal, action == ResourcePolicy::Action::\"project.rerank.modify\", resource) when { context.project.rerankEnabled == true } unless { resource in ResourcePolicy::Project::\"<PROJECT-ID>\" };" } ]}