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

MongoDB 用户资源规范

MongoDBUser自定义资源允许您配置用户访问 所需的身份验证和 角色 MongoDB database。

以下示例显示了MongoDBUser自定义资源的资源规范:

1---
2apiVersion: mongodb.com/v1
3kind: MongoDBUser
4metadata:
5 name: ldap-user-1
6spec:
7 username: "uid=mdb0,dc=example,dc=org"
8 db: "$external"
9 mongodbResourceRef:
10 name: ldap-replica-set
11 roles:
12 - db: "admin"
13 name: "clusterAdmin"
14 - db: "admin"
15 name: "readWriteAnyDatabase"
16 - db: "admin"
17 name: "dbAdminAnyDatabase"
18
19...

本部分介绍必须用于所有MongoDBUser资源的设置。

apiVersion

类型:字符串

MongoDB Kubernetes 资源模式的版本。

kind

类型:字符串

要创建的 MongoDB Kubernetes 资源类型。 将其设置为MongoDBUser

metadata.name

类型:字符串

人类可读的名称,以便您识别此特定的MongoDBUser资源。

资源名称必须少于或等于 44 个字符。

spec.db

类型:字符串

这些用户将访问的MongoDB database的名称。 默认值为admin

spec.db sets the user's authentication database. The Kubernetes Operator uses this database to identify the user. It also sets the authSource parameter in the generated connection string and names the generated connection string secret.

To set the database in the connection string URI path, use spec.connectionStringDatabase.

spec.username

类型:字符串

人类可读标签,用于标识向MongoDB database或集合进行身份验证所需的用户。

MongoDBUser自定义资源可以使用以下设置:

spec.connectionStringDatabase

类型:字符串

Kubernetes Operator 为此用户生成的连接字符串的 URI 路径中的数据库名称。读取连接字符串密钥的客户端默认使用此数据库。

spec.connectionStringDatabase changes the URI path but not authentication, which spec.db controls. For example, a user with a spec.db of admin and a spec.connectionStringDatabase of myapp authenticates against admin and uses myapp by default:

mongodb://my-user:pass@host:27017/myapp?authSource=admin

The Kubernetes Operator applies the database to both the connectionString.standard and connectionString.standardSrv keys of the connection string secret.

Leaving this setting blank results in an empty URI path. In this case, your client determines the active database-for instance, mongosh uses``test`` by default.

spec.connectionStringSecretName

类型:字符串

Operator 创建的连接 密钥的名称。stringKubernetes

当您创建新的MongoDB 数据库用户时, Kubernetes Operator 会自动创建新的Kubernetes 密钥。Kubernetes密钥包含有关新数据库用户的以下信息:

  • username:数据库用户的用户名

  • password:数据库用户的密码

  • connectionString.standard标准连接string ,可以让您以此数据库用户的身份连接到数据库。

  • connectionString.standardSrvDNS 种子列表连接string ,可以让您以此数据库用户的身份连接到数据库。

spec.mongodbResourceRef.name

类型:字符串

与此用户关联的MongoDB 资源的名称。 例如, my-resource

spec.mongodbResourceRef.namespace

类型:字符串

The namespace that contains the secret for this user. If unspecified, the Kubernetes Operator keeps connection secrets in the same namespace as the MongoDBUser custom resource.

spec.passwordSecretKeyRef.name

类型:字符串

metadata.name 存储用户密码的密钥值。 例如, my-secret-name

spec.passwordSecretKeyRef.key

类型:字符串

密钥中包含此MongoDB 数据库用户密码的字段的名称。

要了解更多信息,请参阅 Kubernetes 文档。

spec.roles.db

类型:字符串

MongoDB database on which the role can act. For example, admin.

spec.roles.name

类型:字符串

要授予数据库用户的角色名称。