Mengonfigurasi akses lintas project di GKE

Halaman ini menunjukkan cara memberi Binary Authorization akses ke kebijakan dan image penampung yang ada di project Google Cloud yang berbeda dengan project Anda saat ini. Misalnya, jika Anda men-deploy image di cluster Google Kubernetes Engine (GKE) dari repositori Artifact Registry atau Container Registry (Tidak digunakan lagi) yang dimiliki oleh project lain, Anda harus memberikan akses layanan Otorisasi Biner di project Anda ke metadata image di repositori sumber.

Terminologi

Dokumen ini menggunakan istilah berikut:

  • Agen layanan: Akun layanan yang dikelola Google Cloud. Otorisasi Biner menggunakan agen layanan untuk berinteraksi dengan resource Google Cloud, seperti cluster GKE.
  • Project kebijakan: Project Google Cloud yang berisi kebijakan Otorisasi Biner Anda.
  • Project cluster: Project Google Cloud yang berisi cluster GKE Anda.
  • Project artefak: Project Google Cloud yang berisi repositori Artifact Registry atau Container Registry (Tidak digunakan lagi) Anda.

Skenario yang memerlukan akses lintas project

Anda harus memberikan izin lintas project dalam situasi seperti berikut:

  • Project kebijakan Anda berbeda dengan project cluster.
  • Project cluster Anda berbeda dengan project artefak.

Sebelum memulai

  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. To initialize the gcloud CLI, run the following command:

    gcloud init
  4. 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.

  5. Make sure that billing is enabled for your Google Cloud project.

  6. Enable the Binary Authorization API:

    gcloud services enable binaryauthorization.googleapis.com
  7. Install the Google Cloud CLI.
  8. To initialize the gcloud CLI, run the following command:

    gcloud init
  9. 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.

  10. Make sure that billing is enabled for your Google Cloud project.

  11. Enable the Binary Authorization API:

    gcloud services enable binaryauthorization.googleapis.com

Project cluster berbeda dengan project kebijakan

Berikan peran Binary Authorization Policy Evaluator (roles/binaryauthorization.policyEvaluator) kepada agen layanan Binary Authorization di project cluster pada project kebijakan.

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

Ganti kode berikut:

  • POLICY_PROJECT_ID: ID project yang berisi kebijakan Anda.
  • CLUSTER_PROJECT_ID: project ID cluster.

Project cluster berbeda dengan project artefak

Berikan peran Artifact Registry Reader (roles/artifactregistry.reader) kepada agen layanan Otorisasi Biner di project cluster pada project artefak.

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

Ganti kode berikut:

  • ARTIFACT_PROJECT_ID: ID project yang berisi repositori Artifact Registry Anda.
  • CLUSTER_PROJECT_ID: project ID yang menjalankan cluster GKE Anda.