AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

サービス アカウントを使用した Atlas へのアクセスの構成

Atlas API Service Accounts provide a secure, token-based alternative to Programmatic API Keys for authenticating Atlas Kubernetes Operator with the Atlas Administration API. Service Accounts use short-lived access tokens derived from a clientId and clientSecret pair, reducing the risk of long-lived credential exposure.

MongoDB は、新しい配置にはプログラムによる API キーよりもサービスアカウントを推奨します。サービスアカウントには、次のような利点があります。

  • 演算子によってマネージドされる自動トークン更新を伴うトークンベース認証。

  • 組織レベルとプロジェクトレベルの両方のスコープのサポート。

  • Atlas Kubernetes Operator ワークロードの監査可能な個別の身元。

重要

サービス アカウント シークレットの有効期限

APIキーと違い、サービス アカウントのシークレットには有効期限があります。最大 1 年間の TTL を設定できます。アクセスが中断されないようにするには、有効期限が切れる前にサービス アカウントのシークレットをローテーションする必要があります。 Atlas は、有効期限が近づくと、「 サービス アカウント シークレットは有効期限が近づいています」アラートを自動的に発生させます。これに応じてローテーション スケジュールを計画します。

これは組織レベルとプロジェクトレベルの両方のサービスアカウントに適用されます。

開始する前に、次のものをお持ちであることを確認してください。

  • 組織レベルのサービスアカウントの場合は Organization Owner ロール、プロジェクトレベルのサービスアカウントの場合は Project Owner ロールを持つ Atlas アカウント。

  • Atlas Kubernetes Operator がインストールされた実行中の Kubernetes クラスター。

  • kubectl Atlas Kubernetes Operator が実行されている Kubernetes クラスターへのアクセス。

1

Create a Service Account in Atlas using the Atlas UI or the Atlas Administration API. To learn how to create an organization-level Service Account, see Create a Service Account in an Organization. To learn how to create a project-level Service Account, see Create a Service Account in a Project.

clientIdとclientSecretをコピーします。clientSecretは作成後に再度検索できないため、安全に保存してください。

2

orgId、clientId、clientSecretを含む Kubernetes secretを作成します。

  • global Atlas Kubernetes Operator シークレット については、次のコマンドを実行します。

    注意

    global Atlas Kubernetes Operator シークレットの名前は、事前定義された形式に準拠している必要があります。Atlas Kubernetes Operator 配置のデフォルト名は mongodb-atlas-operator です。したがって、シークレット の名前は mongodb-atlas-operator-service-account にする必要があります。

    kubectl create secret generic mongodb-atlas-operator-service-account \
    --from-literal="orgId=<the_atlas_organization_id>" \
    --from-literal="clientId=<the_service_account_client_id>" \
    --from-literal="clientSecret=<the_service_account_client_secret>" \
    -n <operator_namespace>
    kubectl label secret mongodb-atlas-operator-service-account \
    atlas.mongodb.com/type=credentials \
    -n mongodb-atlas-system
  • project Atlas Kubernetes Operator シークレット については、次のコマンドを実行します。

    kubectl create secret generic my-project-connection \
    --from-literal="orgId=<the_atlas_organization_id>" \
    --from-literal="clientId=<the_service_account_client_id>" \
    --from-literal="clientSecret=<the_service_account_client_secret>" \
    -n <atlas_project_namespace>
    kubectl label secret my-project-connection \
    atlas.mongodb.com/type=credentials \
    -n <atlas_project_namespace>
3

AtlasProjectspec.connectionSecretRef.name を使用して、 カスタム リソースから シークレット を参照します。

global シークレットを作成した場合、すべてのプロジェクトでデフォルトで使用されるため、追加の構成は必要ありません。

project シークレットを作成した場合は、connectionSecretRef を AtlasProject カスタム リソースに追加します。

apiVersion: atlas.mongodb.com/v1
kind: AtlasProject
metadata:
name: my-project
spec:
name: "My Project"
connectionSecretRef:
name: my-project-connection
4

シークレットを構成した後、Atlas Kubernetes Operator が正常に認証されることを確認します。

kubectl get atlasproject my-project -o jsonpath='{.status.conditions}'

Ready 条件が True であることを確認します。Atlas Kubernetes Operator がサービス アカウントの認証情報で認証できない場合、条件には問題を説明するエラーが表示されます。

次の例は、サービスアカウントに構成された接続シークレットを示しています。

apiVersion: v1
kind: Secret
metadata:
name: my-project-connection
namespace: atlas-operator
labels:
atlas.mongodb.com/type: credentials
type: Opaque
stringData:
orgId: "5d39f0719ccf646554345678"
clientId: "mdb_sa_id_67890abcdef1234567890abc"
clientSecret: "mdb_sa_sk_abcdef1234567890abcdef12"

Atlas Kubernetes Operatorはアクセス トークンを自動的にマネージします。Atlas Kubernetes Operatorがサービスアカウント接続シークレットを検出すると、Atlas Administration APIからアクセストークンを取得し、別のkubernetes secretに保存します。アクセス トークン シークレットを手動で編集または削除しないでください。Atlas Kubernetes Operatorは必要に応じてトークンを更新します。

Atlas でサービスアカウントのシークレットをローテートする場合:

  1. Kubernetes 接続シークレットを新しい clientSecret で更新します。

  2. Atlas Kubernetes Operator は変更を検出し、次の調整サイクルで新しいアクセス トークンを取得します。再起動は必要ありません。

重要

サービス アカウントのシークレットの TTL は最大 1 年です。 Atlas で「サービス アカウント シークレットの有効期限が迫っている」アラートを監視し、有効期限が切れる前にシークレットをローテーションして認証失敗を回避します。これは、組織レベルとプロジェクトレベルの両方のサービスアカウントに適用されます。

The Service Account's API access list must include the egress IP address or CIDR block used by the Atlas Kubernetes Operator pod, the same as for Programmatic API Keys. If the operator pod's egress IP is not on the Service Account access list, API requests fail.