GKE でプロジェクト間のアクセスを構成する

このページでは、現在のプロジェクトとは異なる Google Cloud プロジェクトに存在するポリシーとコンテナ イメージに対するアクセス権を Binary Authorization に付与する方法について説明します。たとえば、別のプロジェクトが所有する Artifact Registry リポジトリまたは Container Registry(非推奨)から Google Kubernetes Engine(GKE)クラスタにイメージをデプロイする場合は、ソース リポジトリのイメージ メタデータに対するアクセス権をプロジェクトの Binary Authorization サービスに付与する必要があります。

用語

このドキュメントでは、次の用語を使用しています。

  • サービス エージェント: Google Cloud が管理するサービス アカウント。Binary Authorization は、サービス エージェントを使用して GKE クラスタなどの Google Cloud リソースを操作します。
  • ポリシー プロジェクト: Binary Authorization ポリシーを含む Google Cloud プロジェクト。
  • クラスタ プロジェクト: GKE クラスタを含む Google Cloud プロジェクト。
  • Artifact プロジェクト: Artifact Registry または Container Registry(非推奨)リポジトリを含む Google Cloud プロジェクト。

プロジェクト間のアクセスが必要なシナリオ

次のような場合は、プロジェクト間の権限を付与する必要があります。

  • ポリシー プロジェクトがクラスタ プロジェクトと異なる。
  • クラスタ プロジェクトがアーティファクト プロジェクトと異なる。

始める前に

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. Install the Google Cloud CLI.

  3. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  4. To initialize the gcloud CLI, run the following command:

    gcloud init
  5. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Binary Authorization API:

    gcloud services enable binaryauthorization.googleapis.com
  8. Install the Google Cloud CLI.

  9. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  10. To initialize the gcloud CLI, run the following command:

    gcloud init
  11. Create or select a Google Cloud project.

    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  12. Verify that billing is enabled for your Google Cloud project.

  13. Enable the Binary Authorization API:

    gcloud services enable binaryauthorization.googleapis.com

クラスタ プロジェクトがポリシー プロジェクトと異なる場合

クラスタ プロジェクトの Binary Authorization サービス エージェントに、ポリシー プロジェクトに対する Binary Authorization ポリシー評価者roles/binaryauthorization.policyEvaluator)ロールを付与します。

gcloud projects add-iam-policy-binding POLICY_PROJECT_ID \
  --member="serviceAccount:service-$(gcloud projects describe CLUSTER_PROJECT_ID --format='value(projectNumber)')@gcp-sa-binaryauthorization.iam.gserviceaccount.com" \
  --role=roles/binaryauthorization.policyEvaluator

次のように置き換えます。

  • POLICY_PROJECT_ID: ポリシーを含むプロジェクトの ID。
  • CLUSTER_PROJECT_ID: クラスタのプロジェクト ID。

アーティファクト プロジェクトがクラスタ プロジェクトと異なる場合

クラスタ プロジェクトの Binary Authorization サービス エージェントに、アーティファクト プロジェクトに対する Artifact Registry 読み取りroles/artifactregistry.reader)ロールを付与します。

gcloud projects add-iam-policy-binding ARTIFACT_PROJECT_ID \
    --member="serviceAccount:service-$(gcloud projects describe CLUSTER_PROJECT_ID --format='value(projectNumber)')@gcp-sa-binaryauthorization.iam.gserviceaccount.com" \
    --role=roles/artifactregistry.reader

次のように置き換えます。

  • ARTIFACT_PROJECT_ID: Artifact Registry リポジトリを含むプロジェクトの ID。
  • CLUSTER_PROJECT_ID: GKE クラスタを実行するプロジェクト ID。