本頁面說明如何授予 Binary Authorization 存取權,讓您能存取與目前專案位於不同 Google Cloud 專案中的政策和容器映像檔。舉例來說,如果您從其他專案擁有的 Artifact Registry 或 Container Registry (已淘汰) 存放區,在 Google Kubernetes Engine (GKE) 叢集中部署映像檔,則必須授予專案中的二進位授權服務存取權,才能取得來源存放區中的映像檔中繼資料。
術語
本文使用下列詞彙:
- 服務代理: Google Cloud代管的服務帳戶。 二進位授權會使用服務代理程式與 Google Cloud資源 (例如 GKE 叢集) 互動。
- 政策專案: 包含二進位授權政策的 Google Cloud 專案。
- 叢集專案: 含有 GKE 叢集的 Google Cloud 專案。
- 構件專案: 包含 Artifact Registry 或 Container Registry (已淘汰) 存放區的專案。 Google Cloud
需要跨專案存取權的情境
在下列情況中,您必須授予跨專案權限:
- 政策專案與叢集專案不同。
- 叢集專案與構件專案不同。
事前準備
- 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.
-
Install the Google Cloud CLI.
-
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
-
如要初始化 gcloud CLI,請執行下列指令:
gcloud init
-
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.
-
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Binary Authorization API:
gcloud services enable binaryauthorization.googleapis.com
-
Install the Google Cloud CLI.
-
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
-
如要初始化 gcloud CLI,請執行下列指令:
gcloud init
-
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.
-
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Binary Authorization API:
gcloud services enable binaryauthorization.googleapis.com
POLICY_PROJECT_ID
:包含政策的專案 ID。CLUSTER_PROJECT_ID
:叢集的專案 ID。ARTIFACT_PROJECT_ID
:包含 Artifact Registry 存放區的專案 ID。CLUSTER_PROJECT_ID
:執行 GKE 叢集的專案 ID。
叢集專案與政策專案不同
在政策專案中,將「二進位授權政策評估者」(roles/binaryauthorization.policyEvaluator
) 角色授予叢集專案中的二進位授權服務代理程式。
gcloud projects add-iam-policy-bindingPOLICY_PROJECT_ID
\ --member="serviceAccount:service-$(gcloud projects describeCLUSTER_PROJECT_ID
--format='value(projectNumber)')@gcp-sa-binaryauthorization.iam.gserviceaccount.com" \ --role=roles/binaryauthorization.policyEvaluator
取代下列項目:
叢集專案與構件專案不同
在叢集專案中,將構件專案的 Artifact Registry Reader (roles/artifactregistry.reader
) 角色授予 Binary Authorization 服務代理程式。
gcloud projects add-iam-policy-bindingARTIFACT_PROJECT_ID
\ --member="serviceAccount:service-$(gcloud projects describeCLUSTER_PROJECT_ID
--format='value(projectNumber)')@gcp-sa-binaryauthorization.iam.gserviceaccount.com" \ --role=roles/artifactregistry.reader
取代下列項目: