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

AtlasCustomRole 自定义资源

重要

旧版子资源自相应的 CRD发布以来已被弃用。如果您的配置当前依赖于此资源定义的子资源形式,迁移到 CRD。

The AtlasCustomRole custom resource defines a custom database role to allocate privileges to your database users.

要在给定项目中创建此自定义角色,您必须:

  • 对于使用Atlas Kubernetes Operator管理的项目,请在 自定义资源中引用 AtlasProject自定义资源名称AtlasCustomRole

  • Reference the project ID of your Atlas project in the AtlasCustomRole custom resource, for projects you don't manage with Atlas Kubernetes Operator

重要

自定义资源不再默认删除对象

  • Atlas Kubernetes Operator使用自定义资源配置文件来管理Atlas配置,但从Atlas Kubernetes Operator2.0 开始,您在Kubernetes中删除的自定义资源不再(默认)在Atlas中删除。相反, Atlas Kubernetes Operator只是停止管理Atlas中的这些资源。 AtlasProject示例,如果您在Kubernetes中删除 自定义资源,默认默认, Atlas Kubernetes Operator不再自动从Atlas中删除相应的项目。这种行为更改旨在帮助防止意外删除。 要学习;了解详情,包括如何将此行为恢复为在Atlas Kubernetes Operator.2 0之前使用的默认,请参阅新默认值: Atlas Kubernetes2 Operator.0 中的删除保护。

    同样,如果您使用Atlas Kubernetes Operator从Kubernetes中的Atlas项目中删除团队,则Atlas Kubernetes Operator不会从Atlas中删除团队。

  • 显式定义所需的配置详细信息,以避免隐式使用默认Atlas配置值。 在某些情况下,继承Atlas默认值可能会导致协调循环,从而阻止自定义资源实现 READY 状态。 示例,在 AtlasDeployment 自定义资源中显式定义所需的自动伸缩行为(如所包含的示例所示)可确保自定义资源中的静态实例大小不会重复应用于已启用自动伸缩的Atlas部署。

    autoScaling:
    diskGB:
    enabled: true
    compute:
    enabled: true
    scaleDownEnabled: true
    minInstanceSize: M30
    maxInstanceSize: M40

Atlas Kubernetes Operator使用Atlas自定义数据库角色API资源执行以下操作之一:

  • 创建新的自定义数据库角色。

  • 更新现有的自定义数据库角色。

以下示例显示了一个定义 shard-operator自定义角色的 AtlasCustomRole 自定义资源,该角色具有备份和监控my-project项目中的分片的集群的特权。

apiVersion: atlas.mongodb.com/v1
kind: AtlasCustomRole
metadata:
name: shard-operator-role
namespace: mongodb-atlas-system
labels:
mongodb.com/atlas-reconciliation-policy: keep
spec:
projectRef:
name: my-project
namespace: my-operator-namespace
role:
name: my-role
actions:
- name: getShardMap
resources:
cluster: true
- name: shardingState
resources:
cluster: true
- name: connPoolStats
resources:
cluster: true
- name: getLog
resources:
cluster: true
inheritedRoles:
- name: operator-role-1
role: backup

The following example shows an AtlasCustomRole independent CRD that defines the same shard-operator custom role defined in the Basic Example. This custom resource definition allows you to create this role in a project you don't manage in the same instance of Atlas Kubernetes Operator with which you define this resource. To enable independent operation, you must use an externalProjectRef instead of a projectRef, and you must supply a connectionSecret directly since this resource can't inherit API credentials from its parent project.

apiVersion: atlas.mongodb.com/v1
kind: AtlasCustomRole
metadata:
name: shard-operator-role
namespace: mongodb-atlas-system
labels:
mongodb.com/atlas-reconciliation-policy: keep
spec:
externalProjectRef:
id: 671998971c8520583f24f411
connectionSecret:
name: my-atlas-key
role:
name: my-role
actions:
- name: getShardMap
resources:
cluster: true
- name: shardingState
resources:
cluster: true
- name: connPoolStats
resources:
cluster: true
- name: getLog
resources:
cluster: true
inheritedRoles:
- name: operator-role-1
role: backup

本部分介绍可用的AtlasCustomRole自定义资源参数。

metadata.name

类型:字符串

必需

AtlasProject 自定义资源用于将此自定义角色添加到项目中的名称。

metadata.namespace

类型:字符串

Optional

要包含 atlasCustomRole 自定义资源的命名空间。如果未指定, Atlas Kubernetes Operator将使用 kubectl设立的当前命名空间。

spec.connectionSecret.name

类型:字符串

可选的

不透明密钥的名称,其中包含Atlas Kubernetes Operator用于连接到Atlas 的组织ID和API密钥。如果未指定, Atlas Kubernetes Operator会回退到以下任一项:

  • 父级 atlasProject 的 spec.connectionSecretRef.name 参数

  • 默认global 密钥(如果未为父 atlasProject 定义 spec.connectionSecretRef.name

对于独立的 CRD,此参数为必填项。

Atlas Kubernetes Operator 仅监视带有标签 atlas.mongodb.com/type=credentials 的密钥,以避免监视不必要的密钥。

以下示例标记了密钥:

kubectl label secret the-user-password atlas.mongodb.com/type=credentials
spec.externalProjectRef.id

类型:字符串

可选的

ID of the project to which the custom role belongs. You must specify the project ID of an existing Atlas Project. This parameter is required for custom roles that belong to projects managed by either:

  • Atlas Kubernetes Operator的不同实例

  • Atlas Kubernetes Operator以外的工具

对于属于同一Atlas Kubernetes Operator实例托管的项目的自定义角色,如果您不使用 spec.externalProjectRef.id,请使用 spec.projectRef.name。

一个自定义角色只能属于一个项目。 要为多个项目定义相同的自定义角色,请为每个项目创建自定义资源定义。

spec.projectRef.name

类型:字符串

可选的

自定义角色所属项目的名称。 您必须指定现有的AtlasProject 自定义资源。此参数仅适用于属于由同一实例Atlas Kubernetes Operator托管的项目的自定义角色。

对于属于以下任一机构托管的项目的自定义角色:

  • Atlas Kubernetes Operator的不同实例

  • Atlas Kubernetes Operator以外的工具

使用 spec.externalProjectRef.id 。

一个自定义角色只能属于一个项目。 要为多个项目定义相同的自定义角色,请为每个项目创建自定义资源定义。

spec.projectRef.namespace

类型:字符串

可选的

AtlasProject中指定的spec.projectRef.name 自定义资源所在的命名空间。

对于属于以下任一机构托管的项目的自定义角色:

  • Atlas Kubernetes Operator的不同实例

  • Atlas Kubernetes Operator以外的工具

请勿设立此参数。

spec.role.actions

类型:数组

Optional

表示角色授予的各个权限操作的对象列表。

spec.role.actions.name

类型:字符串

必需

Label that identifies the privilege action. For a complete list of actions available in the Atlas Administration API, see /reference/custom-role-actions.

spec.role.actions.resources

类型:数组

Optional

List of objects that indicate a database and collection on which the action is granted, or indicates that the action is granted on the cluster resource.

spec.role.actions.resources.cluster

类型:布尔值

Optional

Flag that indicates that the action is granted on the cluster resource.

注意

This parameter is mutually exclusive with the spec.role.actions.resources.collection and spec.role.actions.resources.database parameters.

spec.role.actions.resources.collection

类型:字符串

Optional

Human-readable label that identifies the collection on which the action is granted. If this value is an empty string, the action is granted on all collections within the database specified in the spec.role.actions.resources.database parameter.

注意

This parameter is mutually exclusive with the spec.role.actions.resources.cluster parameter.

spec.role.actions.resources.database

类型:字符串

Optional

人类可读标签,用于标识授予操作的数据库。

注意

This parameter is mutually exclusive with the spec.role.actions.resources.cluster parameter.

spec.role.inheritedRoles

类型:数组

Optional

表示键值对的对象列表,而键值对指示继承的角色以及授予该角色的数据库。

spec.role.inheritedRoles.database

类型:字符串

Optional

人类可读标签,用于标识授予继承角色的数据库。

注意

This value should be admin for all roles except read and readWrite.

spec.role.inheritedRoles.name

类型:字符串

Optional

Label that uniquely identifies the inherited role. You can specify another custom role or a built-in role.