Mengonfigurasi akses lintas project di GKE

Halaman ini menunjukkan cara memberikan akses Binary Authorization ke kebijakan dan image penampung yang ada di project Google Cloud lain daripada 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 A Google Cloud. Otorisasi Biner menggunakan agen layanan untuk berinteraksi dengan resource Google Cloud Anda, 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 Anda.
  • Project cluster Anda berbeda dengan project artefak Anda.

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. Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

  4. Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:

    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. Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

  10. Untuk melakukan inisialisasi gcloud CLI, jalankan perintah berikut:

    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
  14. Project cluster berbeda dengan project kebijakan

    Beri agen layanan Otorisasi Biner di project cluster peran Binary Authorization Policy Evaluator (roles/binaryauthorization.policyEvaluator) di 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

    Beri agen layanan Otorisasi Biner di project cluster peran Artifact Registry Reader (roles/artifactregistry.reader) di 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.