This tutorial describes how to use Binary Authorization in a multi-project configuration. For a simpler single-project configuration, see Get started using the Google Cloud CLI (GKE).
To establish separation of duties, you can setup Binary Authorization in a multiple-project configuration. The purpose of each project is discussed later in this tutorial.
Objectives
In this tutorial, you perform the following tasks:Set up a different project for deployment (GKE), attestor, and attestation management, to support separation of duties.
Configure the default rule of your Binary Authorization policy to require attestations.
Create Public-Key Infrastructure (X.509) (PKIX) key pair to sign, and later verify, the attestation.
Create an attestor that the Binary Authorization enforcer uses to verify the attestation.
Sign an example image, creating an attestation.
Test the policy by deploying the example image.
You must configure each project's appropriate access control through Identity and Access Management (IAM).
For additional security, you can use VPC Service Controls to help protect the resources you create in this tutorial. For more information, see Securing with VPC Service Controls.
Costs
In this document, you use the following billable components of Google Cloud:
To generate a cost estimate based on your projected usage,
use the pricing calculator.
Before you begin
- 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.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init - Install
kubectlfor interacting with GKE.
Set up the deployer project
The deployer project manages the Google Kubernetes Engine (GKE) clusters, where you deploy images, and the Binary Authorization policy that Binary Authorization enforces at deploy time. You can have more than one deployer project, depending on the size, complexity, and other requirements of your environment.
To set up the deployer project:
Create the project and enable billing in Google Cloud console if you have not already done so.
Identity and Access Management note: The deployer project contains your GKE cluster. The Identity and Access Management configuration for this project should reflect that.
Set environment variables to store the Google Cloud project and number:
DEPLOYER_PROJECT_ID=DEPLOYER_PROJECT_ID
Replace DEPLOYER_PROJECT_ID with the Google Cloud project ID.
DEPLOYER_PROJECT_NUMBER=$(gcloud projects describe "${DEPLOYER_PROJECT_ID}" \ --format="value(projectNumber)")Enable APIs:
Artifact Registry
gcloud --project=${DEPLOYER_PROJECT_ID} \ services enable\ container.googleapis.com\ artifactregistry.googleapis.com\ binaryauthorization.googleapis.comGet the deployer project service account name:
DEPLOYER_SERVICE_ACCOUNT="service-${DEPLOYER_PROJECT_NUMBER}@gcp-sa-binaryauthorization.iam.gserviceaccount.com"You use the service account name in a later step when you configure permissions on the Artifact Analysis note associated with your attestor.
Set up the attestor project
An attestor project stores the attestors that can verify that an image is ready for deployment. Often, you have a single attestor project that acts as a centralized store for information about trusted parties in the authorization process. This allows you to centrally manage security keys required to verify the identity of attestors and to restrict access to only those parties who administer them.
To set up the attestor project:
Create the project and enable billing in Google Cloud console if you have not already done so.
Identity and Access Management note: Because the this project contains your attestors, only security personnel should have write access.
Set environment variables to store the project ID and number:
ATTESTOR_PROJECT_ID=ATTESTOR_PROJECT_ID
Replace ATTESTOR_PROJECT_ID with the attestor project ID.
ATTESTOR_PROJECT_NUMBER=$(gcloud projects describe "${ATTESTOR_PROJECT_ID}" \ --format="value(projectNumber)")Enable the Artifact Analysis and Binary Authorization APIs:
gcloud services --project=${ATTESTOR_PROJECT_ID} \ enable containeranalysis.googleapis.com \ binaryauthorization.googleapis.comGet the attestor project service account name:
ATTESTOR_SERVICE_ACCOUNT="service-${ATTESTOR_PROJECT_NUMBER}@gcp-sa-binaryauthorization.iam.gserviceaccount.com"You use the service account name in a later step when you configure permissions on the Artifact Analysis note associated with your attestor.
Set up the attestations project
An attestation project is one that stores attestations that attestors make when they verify an image. A separate attestation project allows you to organize and inspect statements about software readiness more easily.
Create the project and enable billing in Google Cloud console if you have not already done so.
Identity and Access Management note: All roles involved in binary authorization should have read access to the Artifact Analysis Notes and Occurrences in this project, however only attestation managers need to have write access.
Set an environment variable to store the project name:
ATTESTATION_PROJECT_ID=ATTESTATION_PROJECT_ID
Replace ATTESTATION_PROJECT_ID with the attestation project ID.
Enable the Artifact Analysis and Binary Authorization APIs:
gcloud services --project=${ATTESTATION_PROJECT_ID} \ enable containeranalysis.googleapis.com \ binaryauthorization.googleapis.com
Create a cluster
Now you can create a GKE cluster in the deployer project.
This is the cluster where you want your deployed container images to run. When
you create the cluster, you pass the --binauthz-evaluation-mode=PROJECT_SINGLETON_POLICY_ENFORCE flag to the
gcloud container clusters create command.
To create the cluster: