> This page location: /docs.md > /docs/management.md > /docs/atlas/operator/current.md > /docs/atlas/operator/current/configure-ak8so-access-to-atlas.md

> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

<!--
Tab options on this page. Append to the .md URL to filter:
  ?tabs=<id,...>   select specific tabs (e.g. ?tabs=nodejs,shell)
  ?allTabs=true    include every tab
  (no param)       default: one tab per tabset

Available tabs:
  other tabs: external-secrets-setup, secrets-store-setup
-->

# Configure Secret Storage

Atlas Kubernetes Operator doesn't support Atlas Infinite Database clusters in public preview. To learn which features Atlas Infinite Database supports in public preview, see [Atlas Infinite Database Edition](https://www.mongodb.com/docs/atlas/infinite/atlas-infinite-landing/). To learn more about preview features, see [Preview Features](https://www.mongodb.com/docs/preview-features/).

You can choose where you store sensitive information for the components that Atlas Kubernetes Operator manages, but Atlas Kubernetes Operator must find the Kubernetes [secrets](https://kubernetes.io/docs/concepts/configuration/secret/) it expects. You can store secrets for Atlas Kubernetes Operator in many ways, including the following methods:

- Put sensitive information directly into Kubernetes [secrets](https://kubernetes.io/docs/concepts/configuration/secret/). All tutorials in the Atlas Kubernetes Operator documentation use Kubernetes [secrets](https://kubernetes.io/docs/concepts/configuration/secret/) by default. To use Kubernetes [secrets](https://kubernetes.io/docs/concepts/configuration/secret/), follow the steps in the tutorials.

- Put sensitive information in a Github repository following a GitOps flow. To store sensitive data in git securely you can use tools, such as [Sealed Secrets](https://github.com/bitnami-labs/sealed-secrets), which encrypts secrets for the intended target cluster.

- Put sensitive information in an external secret storage tool, such as [HashiCorp Vault](https://www.vaultproject.io/) or Hyperscalers native secret management solutions. An intermediary secret provisioning tool fetches sensitive info from the external secret storage tool and creates Kubernetes [secrets](https://kubernetes.io/docs/concepts/configuration/secret/) from the sensitive information. To learn more about the secret provisioning tool, see [Considerations.](https://www.mongodb.com/docs/atlas/operator/current/ak8so-secret-storage.md#std-label-ak8so-secret-considerations)

This tutorial sets up an external secret storage tool for use with Atlas Kubernetes Operator. This tutorial focuses on "secret-less" setups that don't require Atlas Kubernetes Operator to create and store a secret to provision secrets to their Kubernetes cluster.

## Considerations

The following tutorial installs or configures the following tools and options:

- **A secret provisioning tool**. The secret provisioning tool uses one or more authentication mechanisms to retrieve the credentials from the secret management service and create [secrets](https://kubernetes.io/docs/concepts/configuration/secret/) that Atlas Kubernetes Operator can use. This tutorial installs one of the following open-source secret provisioning tools:

  - [External Secrets Operator](https://external-secrets.io/latest/)

  - [Secrets Store CSI Driver](https://secrets-store-csi-driver.sigs.k8s.io/)

- **Authentication to access secrets**. You can use different methods to authenticate the service accounts and namespaces that can access secrets in [HashiCorp Vault:](https://www.vaultproject.io/)

  - For [External Secrets Operator](https://external-secrets.io/latest/), this tutorial uses OIDC (OpenID Connect) JWT (JSON Web Token) authentication. To learn more, see [JWT/OIDC authentication.](https://external-secrets.io/latest/provider/hashicorp-vault/#jwtoidc-authentication)

  - For [Secrets Store CSI Driver](https://secrets-store-csi-driver.sigs.k8s.io/), this tutorial uses Kubernetes authentication.

  Alternatively, your cloud provider's KMS (Key Management Service) can use native IAM (Identity and Access Management) systems to provide this authentication, which isn't covered in this tutorial. To learn how to configure your cloud provider's KMS (Key Management Service) for authentication, see the following resources in the External Secrets Operator documentation:

  - [AWS Secrets Manager](https://external-secrets.io/latest/provider/aws-secrets-manager/)

  - [Azure Key Vault](https://external-secrets.io/latest/provider/azure-key-vault/#workload-identity)

  - [Google Cloud Secret Manager](https://external-secrets.io/latest/provider/google-secrets-manager/)

## Prerequisites

Before you complete this tutorial, you need the following tools and configurations:

- **Running service accounts for Kubernetes, Atlas Kubernetes Operator,
  and Atlas** and sufficient privileges to configure them.

  You need a running Kubernetes cluster with nodes running processors with the x86-64, AMD64, or ARM64 architecture. For this tutorial, the Kubernetes cluster is `https://kube01.internal.io` listening on the default port (443).

  You can access the Atlas Kubernetes Operator project on GitHub:

  - [https://github.com/mongodb/mongodb-atlas-kubernetes](https://github.com/mongodb/mongodb-atlas-kubernetes)

  To install the Atlas Kubernetes operator using the Atlas CLI, run the following command:

  ```sh

  atlas kubernetes operator install [options]

  ```

  To learn more about the command syntax and parameters, see the Atlas CLI documentation for [atlas kubernetes operator install.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-kubernetes-operator-install/)

  **See also: Related Links**

  - [Install the Atlas CLI](https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli/)

  - [Connect to the Atlas CLI](https://www.mongodb.com/docs/atlas/cli/current/connect-atlas-cli/)

  To deploy the Atlas Kubernetes Operator, run the following command. Replace `<version>` with the latest [release number.](https://www.mongodb.com/docs/atlas/operator/current/ak8so-changelog.md#std-label-ak8so-changelog)

  ```sh
  kubectl apply -f https://raw.githubusercontent.com/mongodb/mongodb-atlas-kubernetes/<version>/deploy/all-in-one.yaml
  ```

  To register for an Atlas account, see [Create an Atlas Account.](https://www.mongodb.com/docs/atlas/tutorial/create-atlas-account.md#std-label-create-atlas-account)

- **API keys**. You must [create an API key](https://www.mongodb.com/docs/atlas/configure-api-access.md#std-label-create-org-api-key) and configure the API Access List.

  You need the following public API key, private API key, and the organization ID information to configure Atlas Kubernetes Operator access to Atlas.

  - If you want Atlas Kubernetes Operator to create a new Atlas project, [Grant Programmatic Access to an Organization](https://www.mongodb.com/docs/atlas/configure-api-access.md#std-label-create-org-api-key). If your organization requires an IP access list for the Atlas Administration API, you must also [configure the API access list.](https://www.mongodb.com/docs/atlas/configure-api-access-project.md#std-label-edit-project-api-key-access-list)

    **Important:**

    You must assign the API key the Organization Project Creator organization role or higher.

  - If you want to work with an existing Atlas project, [Add Project Access from a Project](https://www.mongodb.com/docs/atlas/configure-api-access.md#std-label-create-project-api-key). If your organization requires an IP access list for the Atlas Administration API, you must also [configure the API access list.](https://www.mongodb.com/docs/atlas/configure-api-access-project.md#std-label-edit-project-api-key-access-list)

    **Important:**

    You must assign the API key the Project Owner project role.

- **A secret storage vault**. This tutorial uses [HashiCorp Vault](https://www.vaultproject.io/), which is a third-party service for secret storage, running at `https://vault.internal.io`.

  You can use other secret storage vaults with Atlas Kubernetes Operator as needed, including Cloud KMS from AWS, Azure, and Google.

- **Internal access only**. To prevent exposing sensitive information over the public Internet, the following components of the secret storage solution allow internal access only:

  - The [HashiCorp Vault](https://www.vaultproject.io/) or KMS service.

  - The Kubernetes Cluster APIs service.

  - The internal network. This tutorial uses `internal.io`.

  While the previous components allow internal access only, they allow access to each other and allow access to anyone within your team or organization. This is a best practice for security.

- **Public Certificate Authorities (CAs)**. You can use public CAs to avoid managing and distributing custom CA root certificates.

  You can automate CA cert management and renewal by using any of the following tools:

  - [ACME](https://en.wikipedia.org/wiki/Automatic_Certificate_Management_Environment)

  - [Lets Encrypt](https://letsencrypt.org/)

  - [ZeroSSL](https://zerossl.com/)

  - [DNS Challenges](https://letsencrypt.org/docs/challenge-types/#dns-01-challenge)

  - [cert-manager](https://cert-manager.io/)

  In this tutorial:

  - All `internal.io` HTTPs services are internal addresses, but their HTTPS sites hold automatically renewed certificates signed by a public CA.

  - No mutual TLS (mTLS) is required for this integration because it performs only server-side HTTPS validation.

  - Clients can trust these service certificates without extra certificate provisioning.

## Procedure

Follow these steps to configure secret storage for Atlas Kubernetes Operator.

1. Install the secret provisioning tool in the target cluster.

   Select a secret provisioning tool to install it.

   ### External Secrets Operator

   To use [External Secrets Operator](https://external-secrets.io/latest/) as the secret provisioning tool:

   Run the following commands to install External Secrets Operator with Helm Charts and start the service:

   ```sh
   helm repo add external-secrets https://charts.external-secrets.io
   ```

   ```sh
   helm upgrade -i --atomic \
   -n external-secrets --create-namespace --set extraArgs.loglevel=debug \
   external-secrets external-secrets/external-secrets`
   ```

   Ensure External Secrets runs successfully:

   ```text
   kubectl get pod -n external-secrets -l app.kubernetes.io/name=external-secrets
   ```

   **Output:**

   ```text
   NAME                                READY   STATUS    RESTARTS   AGE
   external-secrets-5779d5d6f6-2lhgd   1/1     Running   0          70s
   ```

2. Set up authentication to access secrets.

   ### External Secrets Operator

   To set up OIDC (OpenID Connect) JWT (JSON Web Token) and Kubernetes authentication:

   Run the following command to enable OIDC (OpenID Connect) JWT (JSON Web Token) authentication for the mount path. If you set up several Kubernetes clusters, you must enable OIDC (OpenID Connect) JWT (JSON Web Token) authentication for each cluster's mount path.

   ```text
   vault auth enable -path=jwt-kube01 jwt
   ```

   Run the following command to allow unauthenticated access to the OIDC (OpenID Connect) discovery URLs on the `kube01.internal.io` cluster:

   ```text
   $ kubectl create clusterrolebinding oidc-reviewer  \
     --clusterrole=system:service-account-issuer-discovery \
     --group=system:unauthenticated
   ```

   Run the following command to direct [HashiCorp Vault](https://www.vaultproject.io/) to trust the cluster. The issuer for the cluster at `https://kube01.internal.io/` must match the URL in the OIDC (OpenID Connect) discovery document at `.well-known/openid-configuration`.

   ```text
   curl https://kube01.internal.io/.well-known/openid-configuration | jq .issuer
   https://kube01.internal.io/
   vault write auth/jwt-kube01/config jwks_url="https://kube01.internal.io/openid/v1/jwks"
   ```

   Create the policies that allow access to the secrets you want to expose to the cluster.

   The following example creates the `external-secrets` policy that you specify in later steps.

   ```text
   echo external-secrets-policy.hcl
   path "secret/data/kube01/external-secrets/*" {
     capabilities = ["read"]
   }
   ```

   Run the command to create a [HashiCorp Vault](https://www.vaultproject.io/) role and bind a Kubernetes service account to the role, which restricts the access of the service account within the [HashiCorp Vault.](https://www.vaultproject.io/)

   The following command creates the `jwt-kube01-system` role of the JWT (JSON Web Token) (OIDC (OpenID Connect)) type for the `vault` audience. The command specifies the `sub` user claim, and the `default` Kubernetes service account in the `mongodb-atlas-system` namespace as the bound subject. This command ties the role to the `external-secrets` policy set of permissions within [HashiCorp Vault.](https://www.vaultproject.io/)

   ```text
   vault write auth/jwt-kube01/role/jwt-kube01-system role_type="jwt" bound_audiences=vault \
     user_claim="sub" bound_subject="system:serviceaccount:mongodb-atlas-system:default" \
     policies="external-secrets"
   ```

   Run the command to create another role for External Secrets Operator to access the `default` namespace.

   The following command creates the `jwt-kube01-default` role of the JWT (JSON Web Token) (OIDC (OpenID Connect)) type for the `vault` audience. This command specifies the `sub` user claim, and the `default` Kubernetes service account in the `default` namespace as the bound subject . This command ties the role to the `external-secrets` policy set of permissions within [HashiCorp Vault.](https://www.vaultproject.io/)

   ```text
   vault write auth/jwt-kube01/role/jwt-kube01-default role_type="jwt" bound_audiences=vault \
     user_claim="sub" bound_subject="system:serviceaccount:default:default" \
     policies="external-secrets"
   ```

   Ensure OIDC (OpenID Connect) authentication runs successfully for the system service account:

   ```text
   export TEST_JWT_TOKEN=$(kubectl -n mongodb-atlas-system create token default --audience "vault")
   vault write auth/jwt-kube01/login role=jwt-kube01-system jwt=$(TEST_JWT_TOKEN)
   ```

   Atlas Kubernetes Operator returns your OIDC (OpenID Connect) JWT (JSON Web Token) credentials for the system service account.

   Ensure OIDC (OpenID Connect) authentication runs successfully for the default service account:

   ```text
   export TEST_JWT_TOKEN=$(kubectl -n default create token default --audience "vault")
   vault write auth/jwt-kube01/login role=jwt-kube01-default jwt=$(TEST_JWT_TOKEN)
   ```

   Atlas Kubernetes Operator returns your OIDC (OpenID Connect) JWT (JSON Web Token) credentials for the default service account.

3. Set up automatic secret provisioning.

   ### External Secrets Operator

   To provision secrets with External Secrets Operator:

   **Tip:**

   The following example shows API Key properties (`publicApiKey`, `privateApiKey`). If you use Service Accounts, replace these with `clientId` and `clientSecret`. To learn more, see [Configure Access to Atlas Using Service Accounts.](https://www.mongodb.com/docs/atlas/operator/current/ak8so-service-accounts.md#std-label-ak8so-service-accounts-ref)

   Deploy the `SecretStore` custom resource for the `default` service account in the `mongodb-atlas-system` namespace:

   ```text
   $ cat external-secrets/vault-system.yaml
   apiVersion: external-secrets.io/v1beta1
   kind: SecretStore
   metadata:
     name: vault-store
     namespace: mongodb-atlas-system
   spec:
     provider:
       vault:
         server: "https://vault.internal.io"
         path: "secret"
         version: "v2"
         auth:
           jwt:
             path: "jwt-kube01"
             role: "jwt-kube01-system"
             kubernetesServiceAccountToken:
               expirationSeconds: 600
               serviceAccountRef:
                 name: "default"
                 audiences:
                 - vault
   $ kubectl apply -f external-secrets/vault-system.yaml
   ```

   Deploy the `SecretStore` custom resource for the `default` service account in the `default` namespace:

   ```text
   $ cat external-secrets/vault-default.yaml
   apiVersion: external-secrets.io/v1beta1
   kind: SecretStore
   metadata:
     name: vault-store
     namespace: default
   spec:
     provider:
       vault:
         server: "https://vault.internal.io"
         path: "secret"
         version: "v2"
         auth:
           jwt:
             path: "jwt-kube01"
             role: "jwt-role"
             kubernetesServiceAccountToken:
               expirationSeconds: 600
               serviceAccountRef:
                 name: "default"
                 audiences:
                 - vault
   $ kubectl apply -f external-secrets/vault-default.yaml
   ```

   Deploy the `ExternalSecret` custom resource that references the secret that contains the API key. You must set `spec.target.template.metadata.labels` to `atlas.mongodb.com/type` with the value `credentials` for Atlas Kubernetes Operator to find the secret that External Secrets Operator creates.

   Before you run the following command, ensure that [HashiCorp Vault](https://www.vaultproject.io/) has the secret populated at the Kv V2 path `secret/data/kube01/external-secrets/atlas-account` with the following properties:

   - `orgId`

   - `publicApiKey`

   - `privateApiKey`

   ```text
   $ cat external-secrets/atlas.yaml
   apiVersion: external-secrets.io/v1beta1
   kind: ExternalSecret
   metadata:
     name: atlas
     namespace: mongodb-atlas-system
   spec:
       refreshInterval: "15s"
       secretStoreRef:
         name: vault-store
         kind: SecretStore
       target:
         name: mongodb-atlas-operator-api-key
         template:
           metadata:
             labels:
               atlas.mongodb.com/type: credentials
       data:
       - secretKey: orgId
         remoteRef:
           key: secret/data/kube01/external-secrets/atlas-account
           property: orgId
       - secretKey: publicApiKey
         remoteRef:
           key: secret/data/kube01/external-secrets/atlas-account
           property: publicApiKey
       - secretKey: privateApiKey
         remoteRef:
           key: secret/data/kube01/external-secrets/atlas-account
           property: privateApiKey
     $ kubectl apply -f external-secrets/atlas.yaml
   ```

   This command creates the Kubernetes [secret](https://kubernetes.io/docs/concepts/configuration/secret/) `mongodb-atlas-operator-api-key` in the `mongodb-atlas-system` namespace.

   Deploy the `ExternalSecret` custom resource that references the secret that contains database user credentials. You must set `spec.target.template.metadata.labels` to `atlas.mongodb.com/type` with the value `credentials` for Atlas Kubernetes Operator to find the secret that External Secrets Operator creates.

   Before you run the following command, ensure that [HashiCorp Vault](https://www.vaultproject.io/) has the secret populated at the Kv V2 path `secret/data/kube01/external-secrets/db-user` with the `password` property.

   ```text
   $ cat external-secrets/dbuser.yaml
   apiVersion: external-secrets.io/v1beta1
   kind: ExternalSecret
   metadata:
     name: dbuser
     namespace: default
   spec:
       refreshInterval: "15s"
       secretStoreRef:
         name: vault-store
         kind: SecretStore
       target:
         name: dbuser-password
         template:
           metadata:
             labels:
               atlas.mongodb.com/type: credentials
       data:
       - secretKey: password
         remoteRef:
           key: secret/data/kube01/external-secrets/db-user
           property: password
     $ kubectl apply -f external-secrets/atlas.yaml
   ```

   Ensure the secrets return as expected when you run the following commands:

   ```text
   $ kubectl get -n mongodb-atlas-system secrets/mongodb-atlas-operator-api-key
   ```

   ```text
   $ kubectl get -n default secrets/dbuser-password
   ```

4. Deploy Atlas Kubernetes Operator custom resources.

   You can now deploy Atlas Kubernetes Operator custom resources. Atlas Kubernetes Operator authenticates with the Kubernetes [secrets](https://kubernetes.io/docs/concepts/configuration/secret/) that reference your [HashiCorp Vault](https://www.vaultproject.io/). Adjust the `timeout` values as needed for your deployments.

   ```text
   kubectl apply -f ako/project.yaml
   kubectl apply -f ako/deployment.yaml
   kubectl apply -f ako/user.yaml
   kubectl wait --for=condition=ready atlasdeployment/serverless-deployment --timeout=10m
   kubectl wait --for=condition=ready atlasdatabaseuser/user --timeout=10m
   ```

   To learn more about these custom resources, see [Custom Resources.](https://www.mongodb.com/docs/atlas/operator/current/custom-resources.md#std-label-custom-resources)

5. Test your Atlas Kubernetes Operator deployment.

   To test your Atlas Kubernetes Operator deployment, run the following command:

   ```text
   export ATLAS_DEPLOYMENT_CONN_STR=$(kubectl get secrets/test-atlas-operator-project-test-serverless-deployment-dbuser -o jsonpath='{.data.connectionStringStandardSrv}' |base64 -d)
   mongosh $(ATLAS_DEPLOYMENT_CONN_STR) --apiVersion 1 --eval "show dbs"
   ```

   Atlas Kubernetes Operator returns a list of your database deployments.
