Quick tip: Review the prerequisites before you run the lab
Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
Sprawdź swoją wiedzę i podziel się nią ze społecznością.
done
Zyskaj dostęp do ponad 700 praktycznych modułów oraz odznak umiejętności i szkoleń
Gating Deployments with Binary Authorization
Moduł
1 godz. 30 godz.
universal_currency_alt
1 punkt
show_chart
Wprowadzające
info
Ten moduł może zawierać narzędzia AI, które ułatwią Ci naukę.
Sprawdź swoją wiedzę i podziel się nią ze społecznością.
done
Zyskaj dostęp do ponad 700 praktycznych modułów oraz odznak umiejętności i szkoleń
GSP1183
Overview
Binary Authorization is a deploy-time security control that ensures only trusted container images are deployed on Google Kubernetes Engine (GKE) or Cloud Run. With Binary Authorization, you can require images to be signed by trusted authorities during the development process and then enforce signature validation when deploying. By enforcing validation, you can gain tighter control over your container environment by ensuring only verified images are integrated into the build-and-release process.
The following diagram shows the components in a Binary Authorization/Cloud Build setup:
Cloud Build pipeline that creates a Binary Authorization attestation.
In this pipeline:
Code to build the container image is pushed to a source repository, such as Cloud Source Repositories.
A continuous integration (CI) tool, Cloud Build builds and tests the container.
The build pushes the container image to Container Registry or another registry that stores your built images.
At deploy time, the attestor verifies the attestation using the public key from the key pair. Binary Authorization enforces the policy by requiring signed attestations to deploy the container image.
In this lab you will learn about the tools and techniques to secure deployed artifacts. This lab focuses on artifacts (containers) after they have been created but not deployed to any particular environment.
What you'll learn
Image Signing
Admission Control Policies
Signing Scanned Images
Authorizing Signed Images
Blocked unsigned Images
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.
How to start your lab and sign in to the Google Cloud Console
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method.
On the left is a panel populated with the temporary credentials that you must use for this lab.
Copy the username, and then click Open Google Console.
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Open the tabs in separate windows, side-by-side.
In the Sign in page, paste the username that you copied from the left panel. Then copy and paste the password.
Important: You must use the credentials from the left panel. Do not use your Google Cloud Training credentials. If you have your own Google Cloud account, do not use it for this lab (avoids incurring charges).
Click through the subsequent pages:
Accept the terms and conditions.
Do not add recovery options or two-factor authentication (because this is a temporary account).
Do not sign up for free trials.
After a few moments, the Cloud Console opens in this tab.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
In the Cloud Console, in the top right toolbar, click the Activate Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
You can list the active account name with this command:
Click Check my progress to verify the objective.
Create Artifact Registry repository.
Task 2. Image Signing
What is an Attestor
This person/process is responsible for one link in the chain of trust of the system.
They hold a cryptographic key, and sign an image if it passes their approval process.
While the Policy Creator determines policy in a high-level, abstract way, the Attestor is responsible for concretely enforcing some aspect of the policy.
This can be a real person, like a QA tester or a manager, or a bot in a CI system.
The security of the system depends on their trustworthiness, so it's important that their private keys are kept secure.
Each of these roles can represent an individual person or a team of people in your organization. In a production environment, these roles would likely be managed by separate Google Cloud Platform projects, and access to resources would be shared between them in a limited fashion using Cloud IAM.
Attestors in Binary Authorization are implemented on top of the Cloud Container Analysis API, so it is important to describe how that works before going forward. The Container Analysis API was designed to allow you to associate metadata with specific container images.
As an example, a Note might be created to track the Heartbleed vulnerability. Security vendors would then create scanners to test container images for the vulnerability, and create an Occurrence associated with each compromised container.
Along with tracking vulnerabilities, Container Analysis was designed to be a generic metadata API. Binary Authorization utilizes Container Analysis to associate signatures with the container images they are verifying. A Container Analysis Note is used to represent a single attestor, and Occurrences are created and associated with each container that attestor has approved.
The Binary Authorization API uses the concepts of "attestors" and "attestations", but these are implemented using corresponding Notes and Occurrences in the Container Analysis API.
Create an Attestor Note
An Attestor Note is simply a small bit of data that acts as a label for the type of signature being applied. For example one note might indicate vulnerability scan, while another might be used for QA sign off. The note will be referred to during the signing process.
Your Note is now saved within the Container Analysis API.
Creating an Attestor
Attestors are used to perform the actual image signing process and will attach an occurrence of the note to the image for later verification. To make use of your attestor, you must also register the note with Binary Authorization:
The last line indicates NUM_PUBLIC_KEYS: 0 you will provide keys in a later step.
Cloud Build automatically creates the built-by-cloud-build attestor in your project when you run a build that generates images. So the above command returns two attestors, vulnz-attestor and built-by-cloud-build. After images are successfully built, Cloud Build automatically signs and creates attestations for them.
The Binary Authorization service account will need rights to view the attestation notes. Provide the access to the IAM Role with the following API call:
Click Check my progress to verify the objective.
Create an Attestor.
Task 3. Adding a KMS key
Before you can use this attestor, your authority needs to create a cryptographic key pair that can be used to sign container images. This can be done through Google Cloud Key Management Service (KMS).
First, add some environment variables to describe the new key:
If you print the list of authorities again, you should now see a key registered:
gcloud container binauthz attestors list
Click Check my progress to verify the objective.
Add a KMS key.
Task 4. Creating a signed attestation
At this point you have the features configured that enable you to sign images. Use the Attestor you created previously to sign the Container Image you've been working with.
An attestation must include a cryptographic signature to state that the attestor has verified a particular container image and is safe to run on your cluster.
To specify which container image to attest, run the following to determine its digest:
Now, you can use gcloud to create your attestation. The command takes in the details of the key you want to use for signing, and the specific container image you want to approve:
In Container Analysis terms, this will create a new occurrence, and attach it to your attestor's note.
To ensure everything worked as expected, run the following to list your attestations:
gcloud container binauthz attestations list \
--attestor=$ATTESTOR_ID --attestor-project=${PROJECT_ID}
Task 5. Admission control policies
Binary Authorization is a feature in GKE and Cloud Run that provides the ability to validate rules before a container image is allowed to run. The validation executes on any request to run an image be it from a trusted CI/CD pipeline or a user manually trying to deploy an image. This capability allows you to secure your runtime environments more effectively than CI/CD pipeline checks alone.
To understand this capability you will modify the default GKE policy to enforce a strict authorization rule.
Create the GKE cluster with binary authorization enabled:
This policy is relatively simple. The globalPolicyEvaluationMode line declares that this policy extends the global policy defined by Google. This allows all official GKE containers to run by default. Additionally, the policy declares a defaultAdmissionRule that states that all other pods will be rejected. The admission rule includes an enforcementMode line, which states that all pods that are not conformant to this rule should be blocked from running on the cluster.
kubectl run hello-server --image gcr.io/google-samples/hello-app:1.0 --port 8080
Deployment fails with the following message:
Error from server (VIOLATES_POLICY): admission webhook "imagepolicywebhook.image-policy.k8s.io" denied the request: Image gcr.io/google-samples/hello-app:1.0 denied by Binary Authorization default admission rule. Denied by always_deny admission rule
Revert the policy to allow all
Before moving on to the next section, revert the policy changes.
In a text editor, change the evaluationMode from ALWAYS_DENY to ALWAYS_ALLOW.
edit policy.yaml
The edited policy YAML file should appear as follows:
Click Check my progress to verify the objective.
Create a GKE cluster and update the policies.
Task 6. Automatically signing images
You've enabled image signing, and manually used the Attestor to sign your sample image. In practice you will want to apply attestations during automated processes such as CI/CD pipelines.
In this section you will configure Cloud Build to attest images automatically.
Roles needed
Add Binary Authorization Attestor Viewer role to Cloud Build Service Account:
You'll be using a Custom Build step in Cloud Build to simplify the attestation process. Google provides this Custom Build step which contains helper functions to streamline the process. Before use, the code for the custom build step must be built into a container and pushed to Cloud Build.
To do this, run the following commands:
git clone https://github.com/GoogleCloudPlatform/cloud-builders-community.git
cd cloud-builders-community/binauthz-attestation
gcloud builds submit . --config cloudbuild.yaml
cd ../..
rm -rf cloud-builders-community
Add a signing step to your cloudbuild.yaml
Add the attestation step into your Cloud Build pipeline.
Review the signing step below.
Review only. Do Not Copy
#Sign the image only if the previous severity check passes
- id: 'create-attestation'
name: 'gcr.io/${PROJECT_ID}/binauthz-attestation:latest'
args:
- '--artifact-url'
- '{{{ project_0.default_region | "REGION" }}}-docker.pkg.dev/${PROJECT_ID}/artifact-scanning-repo/sample-image'
- '--attestor'
- 'projects/${PROJECT_ID}/attestors/$ATTESTOR_ID'
- '--keyversion'
- 'projects/${PROJECT_ID}/locations/$KEY_LOCATION/keyRings/$KEYRING/cryptoKeys/$KEY_NAME/cryptoKeyVersions/$KEY_VERSION'
Write a cloudbuild.yaml file with the complete pipeline below:
In the Cloud console navigate to Cloud Build > Build history page and review that latest build and the successful execution of the build steps.
Click Check my progress to verify the objective.
Add a signing step.
Task 7. Authorizing signed images
Now you will update GKE to use Binary Authorization for validating the image has a signature from the Vulnerability scanning before allowing the image to run.
Update GKE Policy to Require Attestation
Require images are signed by your Attestor by adding clusterAdmissionRules to your GKE BinAuth Policy
Currently, your cluster is running a policy with one rule: allow containers from official repositories, and reject all others.
Overwrite the policy with the updated config using the command below:
You should now have a new file on disk, called updated_policy.yaml. Now, instead of the default rule rejecting all images, it first checks your attestor for verifications.
No attestations found that were valid and signed by a key trusted by the attestor
Click Check my progress to verify the objective.
Deploy an unsigned image.
Congratulations!
You've learned how to create an Attestor to sign images to validate rules before a container image is allowed to run. You learned how to write a policy to inform Cloud Build to allow or deny access to the GKE cluster, and you have used Binary Authorization with Google Cloud KMS to validate image signatures, and prevent unsigned images access to the Kubernetes cluster.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated July 11, 2024
Lab Last Tested July 11, 2024
Copyright 2023 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
Labs create a Google Cloud project and resources for a fixed time
Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
On the top left of your screen, click Start lab to begin
Use private browsing
Copy the provided Username and Password for the lab
Click Open console in private mode
Sign in to the Console
Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
Accept the terms, and skip the recovery resource page
Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project
Ta treść jest obecnie niedostępna
Kiedy dostępność się zmieni, wyślemy Ci e-maila z powiadomieniem
Świetnie
Kiedy dostępność się zmieni, skontaktujemy się z Tobą e-mailem
One lab at a time
Confirm to end all existing labs and start this one
Setup your console before you begin
Use an Incognito or private browser window to run this lab. This
prevents any conflicts between your personal account and the Student
account, which may cause extra charges incurred to your personal account.
In this lab you will learn about the tools and techniques to secure deployed artifacts.
Czas trwania:
Konfiguracja: 0 min
·
Dostęp na 90 min
·
Ukończono w 60 min