Securing Google Cloud with CFT Scorecard

Join Sign in

Securing Google Cloud with CFT Scorecard

40 minutes 1 Credit


Google Cloud self-paced labs logo


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

Topic infographic


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).
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

  1. 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
  2. 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.
  3. If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.

  4. 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.
  5. 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.

Note: You can view the menu with a list of Google Cloud Products and Services by clicking the Navigation menu at the top-left. Navigation menu icon

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.

  1. Click Activate Cloud Shell Activate Cloud Shell icon at the top of the Google Cloud console.

  2. 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. The output contains a line that declares the PROJECT_ID for this session:

Your Cloud Platform project in this session 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.

  1. (Optional) You can list the active account name with this command:

gcloud auth list


ACTIVE: * ACCOUNT: To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:

gcloud config list project


[core] project = <project_ID>

Example output:

[core] project = qwiklabs-gcp-44776a13dea667a6 Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Task 1. Set up the environment

  1. Open Cloud Shell and set a couple of environment variables to begin:

  1. After reading the docs, understand that CFT scorecard has two dependencies:

  • Cloud Asset Inventory

  • Policy Library

  1. Proceed to enable Cloud Asset API in your project:

gcloud services enable \ --project $GOOGLE_PROJECT
  1. Run this command to create the default Cloud Asset service account:

gcloud beta services identity create --project=$GOOGLE_PROJECT
  1. Grant the storage admin role to the cloud assets service account:

gcloud projects add-iam-policy-binding ${GOOGLE_PROJECT} \ --member=serviceAccount:service-$(gcloud projects list --filter="$GOOGLE_PROJECT" --format="value(PROJECT_NUMBER)") \ --role=roles/storage.admin
  1. Clone the Policy Library:

git clone
  1. 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.

cp policy-library/samples/storage_denylist_public.yaml policy-library/policies/constraints/
  1. Create the bucket that will hold the data that Cloud Asset Inventory (CAI) will export:

gsutil mb -l us-central1 -p $GOOGLE_PROJECT gs://$CAI_BUCKET_NAME Create the CAI bucket

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.

  1. Use the command below to create the data:

# Export resource data gcloud asset export \ --output-path=gs://$CAI_BUCKET_NAME/resource_inventory.json \ --content-type=resource \ --project=$GOOGLE_PROJECT # Export IAM data gcloud asset export \ --output-path=gs://$CAI_BUCKET_NAME/iam_inventory.json \ --content-type=iam-policy \ --project=$GOOGLE_PROJECT # Export org policy data gcloud asset export \ --output-path=gs://$CAI_BUCKET_NAME/org_policy_inventory.json \ --content-type=org-policy \ --project=$GOOGLE_PROJECT # Export access policy data gcloud asset export \ --output-path=gs://$CAI_BUCKET_NAME/access_policy_inventory.json \ --content-type=access-policy \ --project=$GOOGLE_PROJECT

Example output:

Export in progress for root asset [projects/qwiklabs-gcp-01-68169ed6dd00]. Use [gcloud asset operations describe projects/97186664469/operations/ExportAssets/RESOURCE/2295255602305764396] to check the status of the operation. Export in progress for root asset [projects/qwiklabs-gcp-01-68169ed6dd00]. Use [gcloud asset operations describe projects/97186664469/operations/ExportAssets/IAM_POLICY/11771734913762837428] to check the status of the operation.
  1. 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.
Create the CAI files have been created

Task 3. Analyze CAI data with CFT scorecard

  1. You need to download the CFT scorecard application and make it executable:

curl -o cft # make executable chmod +x cft
  1. Now that you have configured everything, go ahead and run the CFT scorecard application:

./cft scorecard --policy-path=policy-library/ --bucket=$CAI_BUCKET_NAME

Example output:

Generating CFT scorecard 1 total issues found Operational Efficiency: 0 issues found ---------- Security: 1 issues found ---------- denylist_public_users: 1 issues - // is publicly accessable Reliability: 0 issues found ---------- Other: 0 issues found ----------

This was the public bucket you identified earlier.

Task 4. Add more constraints to CFT scorecard

  1. 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:

# Add a new policy to blacklist the IAM Owner Role cat > policy-library/policies/constraints/iam_allowlist_owner.yaml << EOF apiVersion: kind: GCPIAMAllowedBindingsConstraintV3 metadata: name: allowlist_owner annotations: description: List any users granted Owner spec: severity: high match: target: ["organizations/**"] exclude: [] parameters: mode: allowlist assetType: role: roles/owner members: - "" EOF
  1. Rerun CFT scorecard:

./cft scorecard --policy-path=policy-library/ --bucket=$CAI_BUCKET_NAME

Ok, it all looks clean, but let's look at roles/editor, too.

  1. Set two extra variables to help with the new constraint creation:

export USER_ACCOUNT="$(gcloud config get-value core/account)" export PROJECT_NUMBER=$(gcloud projects describe $GOOGLE_PROJECT --format="get(projectNumber)")
  1. Create the following constraint that will allowlist all the valid accounts:

# Add a new policy to allowlist the IAM Editor Role cat > policy-library/policies/constraints/iam_identify_outside_editors.yaml << EOF apiVersion: kind: GCPIAMAllowedBindingsConstraintV3 metadata: name: identify_outside_editors annotations: description: list any users outside the organization granted Editor spec: severity: high match: target: ["organizations/**"] exclude: [] parameters: mode: allowlist assetType: role: roles/editor members: - "user:$USER_ACCOUNT" - "serviceAccount:**$PROJECT_NUMBER**" - "serviceAccount:$GOOGLE_PROJECT**" EOF
  1. Rerun CFT scorecard:

./cft scorecard --policy-path=policy-library/ --bucket=$CAI_BUCKET_NAME

Example output:

Generating CFT scorecard 3 total issues found Reliability: 0 issues found ---------- Other: 2 issues found ---------- identify_outside_editors: 1 issues - IAM policy for // grants roles/editor to Operational Efficiency: 0 issues found ---------- Security: 1 issues found ---------- denylist_public_users: 1 issues - // is publicly accessable

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 2022 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.