체크포인트
Create the cai bucket
/ 50
Create the two cai files
/ 50
Securing Google Cloud with CFT Scorecard
GSP698
Overview
CFT Scorecard is an open-sourced command line client of Forseti Config Validator and part of the broader Cloud Foundation Toolkit. It provides visibility into misconfigurations and violations of an established set of standards for Google Cloud resources, projects, folders, or even organizations.
There are over 86 distinct Google Cloud resource types, and they're growing. With the move to public cloud, it is easier than ever to federate cloud operations and resource deployment out to many individuals. Along with federation and agility in the deployment of infrastructure, resources, and policy, it has become increasingly difficult to keep policies and standards in order.
In this lab you will configure CFT Scorecard to improve visibility into a Google Cloud project and detect misconfigurations.
What will you do in this lab?
This lab highlights the challenges with using the cloud with multiple concurrent users. You will enable the CFT Scorecard and extend its resource configuration monitoring and violation detection capabilities through integration with Cloud Asset Inventory and the open-sourced Policy Library. You will set up the tooling for detecting misconfigurations and over-exposed resources while still allowing other individuals within your team, and ultimately the Google Cloud project, to be agile within established policies.
Topics covered
- Setting up CFT Scorecard.
- Running a CFT Scorecard assessment.
- Adding new CFT Scorecard policy.
Scenario
Imagine you are the Technical Lead of a 3 person team. Your remote teammates, Alice and Bob, are working very closely with you and deploying many resources into the same shared Google Cloud project as you. After a few weeks of working together, you start to notice a few red flags. You soon discover that both Alice and Bob have cut corners and introduced project configurations that you consider misconfiguration. One misconfiguration exposed a Cloud Storage bucket publicly. This is merely one misconfiguration that you have uncovered, but you fear that there could be many more.
After doing a quick Google search, you come across the Cloud Foundation Toolkit (CFT) Scorecard CLI utility. After a quick read, you decide this can help you administer policies into your Google Cloud environment and determine where misconfigurations are occurring. You decide to give it a try.
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).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
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 the Lab Details panel with the following:
- The Open Google Cloud console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}} You can also find the Username in the Lab Details panel.
-
Click Next.
-
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}} You can also find the Password in the Lab Details panel.
-
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra 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 Google 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.
- Click Activate Cloud Shell at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
- (Optional) You can list the active account name with this command:
- Click Authorize.
Output:
- (Optional) You can list the project ID with this command:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Set up the environment
- Open Cloud Shell and set a couple of environment variables to begin:
- After reading the docs, understand that CFT scorecard has two dependencies:
- Cloud Asset Inventory
- Policy Library
- Proceed to enable Cloud Asset API in your project:
- Run this command to create the default Cloud Asset service account:
- Grant the storage admin role to the cloud assets service account:
- Clone the Policy Library:
- You realize Policy Library enforces policies that are located in the policy-library/policies/constraints folder, in which case you can copy a sample policy from the samples directory into the constraints directory.
- Create the bucket that will hold the data that Cloud Asset Inventory (CAI) will export:
Click Check my progress to verify the objective.
Task 2. Collect data using Cloud Asset Inventory (CAI)
Now that you have set up your environment, start collecting the data for CFT Scorecard.
As mentioned earlier, input to CFT Scorecard is resource and IAM data, and the policy-library folder.
You'll need to use CAI to generate the resource and IAM policy information for the project.
- Use the command below to create the data:
Example output:
- Ensure CAI has finished data collection. Look at the output from the previous command and use the provided
gcloud asset operations describe
from the output of the above commands to verify these operations have finished. It might take some time to check the progress.
Click Check my progress to verify the objective.
Task 3. Analyze CAI data with CFT scorecard
- You need to download the CFT scorecard application and make it executable:
- Now that you have configured everything, go ahead and run the CFT scorecard application:
Example output:
This was the public bucket you identified earlier.
Task 4. Add more constraints to CFT scorecard
- You forgot about IAM! Add the following constraint to ensure you are entirely aware who has the
roles/owner
role aside from your allowlisted user:
- Rerun CFT scorecard:
Ok, it all looks clean, but let's look at roles/editor
, too.
- Set two extra variables to help with the new constraint creation:
- Create the following constraint that will allowlist all the valid accounts:
- Rerun CFT scorecard:
Example output:
You should now see an editor who is not in your organization. Time to talk to Alice and Bob.
Congratulations!
You have learned how to download, set up, and use the CFT scorecard to analyze a Google Cloud project.
Google Cloud training and certification
...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 April 12, 2024
Lab Last Tested April 12, 2024
Copyright 2024 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.