Overview
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 クラスター。
kubectlAtlas Kubernetes Operator が実行されている Kubernetes クラスターへのアクセス。
手順
Atlas でサービス アカウントを作成する
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は作成後に再度検索できないため、安全に保存してください。
Kubernetes 接続シークレットを作成する
orgId、clientId、clientSecretを含む Kubernetes secretを作成します。
globalAtlas Kubernetes Operator シークレット については、次のコマンドを実行します。注意
globalAtlas 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 projectAtlas 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>
シークレットの参照元 AtlasProject
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
演算子がサービス アカウントを使用していることを確認する
シークレットを構成した後、Atlas Kubernetes Operator が正常に認証されることを確認します。
kubectl get atlasproject my-project -o jsonpath='{.status.conditions}'
Ready 条件が True であることを確認します。Atlas Kubernetes Operator がサービス アカウントの認証情報で認証できない場合、条件には問題を説明するエラーが表示されます。
YAML 例
次の例は、サービスアカウントに構成された接続シークレットを示しています。
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"
Considerations
Token マネジメント
Atlas Kubernetes Operatorはアクセス トークンを自動的にマネージします。Atlas Kubernetes Operatorがサービスアカウント接続シークレットを検出すると、Atlas Administration APIからアクセストークンを取得し、別のkubernetes secretに保存します。アクセス トークン シークレットを手動で編集または削除しないでください。Atlas Kubernetes Operatorは必要に応じてトークンを更新します。
認証情報のローテーション
Atlas でサービスアカウントのシークレットをローテートする場合:
Kubernetes 接続シークレットを新しい
clientSecretで更新します。Atlas Kubernetes Operator は変更を検出し、次の調整サイクルで新しいアクセス トークンを取得します。再起動は必要ありません。
重要
サービス アカウントのシークレットの TTL は最大 1 年です。 Atlas で「サービス アカウント シークレットの有効期限が迫っている」アラートを監視し、有効期限が切れる前にシークレットをローテーションして認証失敗を回避します。これは、組織レベルとプロジェクトレベルの両方のサービスアカウントに適用されます。
IP アクセス リスト
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.