启用 Binary Authorization

如需为 GKE 关联集群启用 Binary Authorization,请执行以下步骤:

  1. 在您的项目中启用 Binary Authorization API:

    gcloud services enable binaryauthorization.googleapis.com \
     
    --project=PROJECT_ID

    PROJECT_ID 替换为您的 Google Cloud 项目的 ID。

  2. binaryauthorization.policyEvaluator 角色授予与 Binary Authorization 代理关联的 Kubernetes 服务账号:

    gcloud projects add-iam-policy-binding PROJECT_ID \
     
    --member=serviceAccount:PROJECT_ID.svc.id.goog[gke-system/binauthz-agent] \
     
    --role="roles/binaryauthorization.policyEvaluator"
  3. 在注册或更新集群时启用 Binary Authorization。

    如需在注册集群时启用 Binary Authorization,请使用 gcloud container attached clusters register 命令。按照关联 AKS 集群中的说明操作,并添加可选参数 --binauthz-evaluation-mode=PROJECT_SINGLETON_POLICY_ENFORCE

    gcloud container attached clusters register CLUSTER_NAME \
     
    ...
     
    --binauthz-evaluation-mode=PROJECT_SINGLETON_POLICY_ENFORCE

    CLUSTER_NAME 替换为您的集群名称。

    如需在更新集群时启用 Binary Authorization,请使用 gcloud container attached clusters update 命令。按照更新 AKS 集群中的说明操作,并添加可选参数 --binauthz-evaluation-mode=PROJECT_SINGLETON_POLICY_ENFORCE

    gcloud container attached clusters update CLUSTER_NAME \
     
    ...
     
    --binauthz-evaluation-mode=PROJECT_SINGLETON_POLICY_ENFORCE

    CLUSTER_NAME 替换为您的集群名称。

按照以下步骤操作,可确保仅使用可信和经过验证的映像在 GKE 集群中创建 Kubernetes 容器。这有助于为您的应用维护安全的环境。