Create the cai bucket
Create the two cai files
Securing Google Cloud with CFT Scorecard
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.
- Setting up CFT Scorecard
- Running a CFT Scorecard assessment
- Adding new CFT Scorecard policy
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 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 Console. 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 from the Lab Details panel and paste it into the Sign in dialog. Click Next.
Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.
Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost 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 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. The output contains a line that declares the PROJECT_ID for this session:
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:
Your output should now look like this:
(Optional) You can list the project ID with this command:
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
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:
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:
- Ensure CAI has finished data collection. Look at the output from the previous command and use the provided
gcloud asset operations describefrom the output of the above commands to verify these operations have finished.
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:
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/ownerrole aside from your allowlisted user:
Rerun CFT scorecard:
Ok, it all looks clean, but let's look at
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:
You should now see an editor who is not in your organization. Time to talk to Alice and Bob.
You have learned how to download, set up, and use the CFT scorecard to analyze a Google Cloud project.
Finish your quest
This self-paced lab is part of the Security & Identity Fundamentals quest. A quest is a series of related labs that form a learning path. Completing this quest earns you a badge to recognize your achievement. You can make your badge or badges public and link to them in your online resume or social media account. Enroll in this quest or any quest that contains this lab and get immediate completion credit. See the Google Cloud Skills Boost catalog to see all available quests.
Take your next lab
Continue your quest with VPC Network Peering, or try these other Google Cloud Skills Boost labs:
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 August 22, 2022
Lab Last Tested June 8, 2022
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.