The AtlasDatabaseUser custom resource configures the database user
in an Atlas project. You create database users per project, not per
cluster. So, the AtlasDatabaseUser custom resource configuration
contains a reference to the AtlasProject Custom Resource. Create
the AtlasProject Custom Resource beforehand.
Important
Custom Resources No Longer Delete Objects by Default
Atlas Kubernetes Operator uses custom resource configuration files to manage your Atlas configuration, but as of Atlas Kubernetes Operator 2.0, custom resources you delete in Kubernetes are no longer (by default) deleted in Atlas. Instead, Atlas Kubernetes Operator simply stops managing those resources in Atlas. For example, if you delete an
AtlasProjectCustom Resource in Kubernetes, by default the Atlas Kubernetes Operator no longer automatically deletes the corresponding project from Atlas. This change in behavior is intended to help prevent accidental or unexpected deletions. To learn more, including how to revert this behavior to the default used prior to Atlas Kubernetes Operator 2.0, see New Default: Deletion Protection in Atlas Kubernetes Operator 2.0.Similarly, Atlas Kubernetes Operator does not delete teams from Atlas if you remove them from an Atlas project in Kubernetes with the Atlas Kubernetes Operator.
Explicitly define your desired configuration details in order to avoid implicitly using default Atlas configuration values. In some cases, inheriting Atlas defaults may result in a reconciliation loop which can prevent your custom resource from achieving a
READYstate. For example, explicitly defining your desired autoscaling behavior in yourAtlasDeploymentcustom resource, as shown in the included example, ensures that a static instance size in your custom resource is not being repeatedly applied to an Atlas deployment which has autoscaling enabled.autoScaling: diskGB: enabled: true compute: enabled: true scaleDownEnabled: true minInstanceSize: M30 maxInstanceSize: M40
The following example shows a reference to the
AtlasProject Custom Resource:
spec: projectRef: name: my-project
Atlas Kubernetes Operator ensures the database user configuration in Atlas matches the configuration in Kubernetes.
Atlas Kubernetes Operator does one of the following actions using the Atlas Database Users API:
Creates a new database user.
Updates an existing user.
Before you create a database user, you must create an opaque
secret with a single password field to log into the Atlas
cluster database.
Note
You must create the secret in the same namespace where the AtlasDatabaseUser custom resource is located.
The following example creates a secret:
kubectl create secret generic the-user-password --from-literal="password=P@@sword%"
Atlas Kubernetes Operator watches secrets only with the label
atlas.mongodb.com/type=credentials to avoid watching unnecessary
secrets.
The following example labels a secret:
kubectl label secret the-user-password atlas.mongodb.com/type=credentials
Connection Secrets
After Atlas Kubernetes Operator successfully creates or updates the database user in
Atlas, Atlas Kubernetes Operator creates or updates the connection secrets in
the same namespace where the AtlasDatabaseUser custom resource
is located.
Connection secrets contain all the information required to connect to the Atlas clusters including the following parameters:
Parameter | Description |
|---|---|
| Public |
| Public |
| Name that identifies the database user. |
| Password of the database user. |
Applications running in Kubernetes can use this information to connect to Atlas clusters. You can mount the secrets to the application pods as files and the application process can read these files to get data.
The following example shows mounting the secret as an environment variable:
spec: containers: - name: test-app env: - name: "CONNECTIONSTRING" valueFrom: secretKeyRef: name: project-cluster-basic-theuser key: connectionStringStandardSrv
The following example shows mounting the secret as files:
spec: containers: - name: test-app volumeMounts: - mountPath: /var/secrets/ name: theuser-connection volumes: - name: theuser-connection secret: secretName: project-cluster-basic-theuser
By default, Atlas Kubernetes Operator creates the database user connection secret
for each cluster in the same project that the AtlasDatabaseUser
references. You can change this behavior with the
spec.scopes parameter. This parameter restricts the clusters
where the database user gets created. The name of the connection secret
uses the following format:
<project_name>-<cluster_name>-<db_user_name>.
Examples
Project and Clusters
The following example shows an Atlas project and the clusters that reference it:
apiVersion: atlas.mongodb.com/v1 kind: AtlasProject metadata: name: my-project spec: name: p1 projectIpAccessList: - ipAddress: "192.0.2.15" comment: "IP address for Application Server A" apiVersion: atlas.mongodb.com/v1 kind: AtlasDeployment metadata: name: my-aws-cluster spec: name: aws-cluster projectRef: name: my-project providerSettings: instanceSizeName: M10 providerName: AWS regionName: US_EAST_1 apiVersion: atlas.mongodb.com/v1 kind: AtlasDeployment metadata: name: my-gcp-cluster spec: name: gcp-cluster projectRef: name: my-project providerSettings: instanceSizeName: M10 providerName: GCP regionName: EASTERN_US
Database User without Scopes
The following example shows an AtlasDatabaseUser custom resource
specification with spec.scopes omitted:
apiVersion: atlas.mongodb.com/v1 kind: AtlasDatabaseUser metadata: name: my-database-user spec: description: "User for the reporting application." roles: - roleName: readWriteAnyDatabase databaseName: admin projectRef: name: my-project username: theuser passwordSecretRef: name: the-user-password
After you create this custom resource, Atlas Kubernetes Operator creates the following secrets:
p1-aws-cluster-theuserp1-gcp-cluster-theuser
Database User with Scopes
The following example shows an AtlasDatabaseUser custom resource
specification with spec.scopes set to the Google Cloud cluster only:
apiVersion: atlas.mongodb.com/v1 kind: AtlasDatabaseUser metadata: name: my-database-user spec: roles: - roleName: "readWriteAnyDatabase" databaseName: "admin" projectRef: name: my-project username: theuser passwordSecretRef: name: the-user-password scopes: - type: CLUSTER name: gcp-cluster
After you update this custom resource, Atlas Kubernetes Operator removes theuser from
the aws-cluster. It also removes the p1-aws-cluster-theuser
secret from the Kubernetes cluster.
Database User with X.509 Authentication
The following example shows an AtlasDatabaseUser custom resource
specification with X.509 authentication.
apiVersion: atlas.mongodb.com/v1 kind: AtlasDatabaseUser metadata: name: my-database-user spec: username: CN=my-x509-authenticated-user,OU=organizationalunit,O=organization databaseName: "\$external" x509Type: "CUSTOMER" roles: - roleName: "readWriteAnyDatabase" databaseName: "admin" projectRef: name: my-project
Database User with OIDC Authentication
The following example shows an AtlasDatabaseUser custom resource
specification with OIDC.
apiVersion: atlas.mongodb.com/v1 kind: AtlasDatabaseUser metadata: name: my-database-user spec: roles: - roleName: "readWriteAnyDatabase" databaseName: "admin" projectRef: name: my-project username: my-oidc-group-id/my-idp-group-name oidcAuthType: IDP_GROUP
Database User with AWS IAM Authentication
The following example shows an AtlasDatabaseUser custom resource
specification with AWS IAM.
apiVersion: atlas.mongodb.com/v1 kind: AtlasDatabaseUser metadata: name: my-database-user spec: username: arn:aws:iam::123456789012:user/johndoe databaseName: "$external" roles: - roleName: "readWriteAnyDatabase" databaseName: "admin" projectRef: name: my-project awsIamType: USER
Parameters
AtlasDatabaseUser
AtlasDatabaseUser is the Schema for the Atlas Database User API
Name | Type | Description | Required |
|---|---|---|---|
| string | atlas.mongodb.com/v1 | true |
| string |
| true |
| object | Refer to the Kubernetes | true |
| object |
| false |
| object |
| false |
AtlasDatabaseUser.spec
AtlasDatabaseUserSpec defines the target state of Database User in Atlas
Name | Type | Description | Required |
|---|---|---|---|
| []object | Roles is an array of this user's | true |
| string | Username is a | true |
| enum | Human-readable label that indicates whether the new database user authenticates with Amazon Web Services ( | false |
| object | Name of the secret containing Atlas | false |
| string |
| false |
| string |
| false |
| string | Description of this database user. Maximum 100 characters. | false |
| object |
| false |
| []object | Labels is an array containing key-value pairs that tag and categorize the database user. Each key and value has a maximum length of 255 characters. | false |
| enum | Human-readable label that indicates whether the new database Username with | false |
| object |
| false |
| object |
| false |
| []object | Scopes is an array of clusters and Atlas Data Lakes that this user has access to. | false |
| enum | X509Type is X.509 method by which the database authenticates the provided username.
Enum: | false |
AtlasDatabaseUser.spec.roles
RoleSpec allows the user to perform particular actions on the specified database. A role on the admin database can include privileges that apply to the other databases as well.
Name | Type | Description | Required |
|---|---|---|---|
| string |
| true |
| string |
| true |
| string |
| false |
AtlasDatabaseUser.spec.connectionSecret
Name of the secret containing Atlas API private and public keys.
Name | Type | Description | Required |
|---|---|---|---|
| string | Name of the resource being referred to More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names | true |
AtlasDatabaseUser.spec.externalProjectRef
externalProjectRef holds the parent Atlas project ID. Mutually exclusive with the "projectRef" field.
Name | Type | Description | Required |
|---|---|---|---|
| string |
| true |
AtlasDatabaseUser.spec.labels
LabelSpec contains key-value pairs that tag and categorize the Cluster/DBUser
Name | Type | Description | Required |
|---|---|---|---|
| string | Key applied to tag and categorize this component. | true |
| string | Value set to the Key applied to tag and categorize this component. | true |
AtlasDatabaseUser.spec.passwordSecretRef
PasswordSecret is a reference to the Secret keeping the user password.
Name | Type | Description | Required |
|---|---|---|---|
| string | Name is the | true |
AtlasDatabaseUser.spec.projectRef
projectRef is a reference to the parent AtlasProject resource. Mutually exclusive with the "externalProjectRef" field.
Name | Type | Description | Required |
|---|---|---|---|
| string | Name of the Kubernetes Resource | true |
| string | Namespace of the Kubernetes Resource | false |
AtlasDatabaseUser.spec.scopes
ScopeSpec if present a database user only have access to the indicated resource (Cluster or Atlas Data Lake) if none is given then it has access to all. It's highly recommended to restrict the access of the database users only to a limited set of resources.
Name | Type | Description | Required |
|---|---|---|---|
| string | Name is a | true |
| enum | Type is a | true |
AtlasDatabaseUser.status
AtlasDatabaseUserStatus defines the observed state of AtlasProject
Name | Type | Description | Required |
|---|---|---|---|
| []object | Conditions is the list of statuses showing the current state of the Atlas Custom Resource | true |
| string |
| false |
| integer |
| false |
| string |
| false |
AtlasDatabaseUser.status.conditions
Condition describes the state of an Atlas Custom Resource at a certain point.
Name | Type | Description | Required |
|---|---|---|---|
| string | Status of the condition; one of True, False, Unknown. | true |
| string | Type of Atlas Custom Resource condition. | true |
| string | Last time the condition transitioned from one status to another.
Represented in | false |
| string | A | false |
| string | The | false |