Skip to content
$ lynuxpro
← Google Cloud (GCP)

LESSON 2 OF 23 · BEGINNER · 13 MIN

Projects, billing and IAM

Free previewLesson 2 of the 2 free lessons in this Pro course.Unlock all 23

HOW IT WORKSWho may do what, and who pays

Principalgroup:devs@example.comRoleroles/run.developerIAM bindingProjectshop-dev-123Billing accountpays the billEnabled APIsrun.googleapis.com
1/5

A principal is who: a person, a group or a service account.

In simple words

  • Project: the basic container for GCP resources, settings and billing.
  • Billing account: pays for one or more projects.
  • IAM role: a set of permissions, such as Viewer or a narrow predefined role, given to someone on a resource.
  • Service account: an identity for apps and pipelines, not people.
  • API enablement: each service's API must be switched on in a project before you can use it.

Big picture

A project is a folder with a wall around it. Inside it you create resources, set permissions and get a bill. IAM (Identity and Access Management) decides who may do what inside. Think of an office building: each project is a locked floor, and IAM is the list of badges that open doors.

Projects

Every project has three names. Learn the difference once:

NameCan it change?Example
Project nameYesShop Dev
Project IDNo, unique worldwideshop-dev-123
Project numberNo, made by Google482910334455
gcloud projects create shop-dev-123 --name="Shop Dev"gcloud config set project shop-dev-123gcloud projects list
SHELLbashutf-8 · 3L
Create in progress for [https://cloudresourcemanager.googleapis.com/v1/projects/shop-dev-123].Waiting for [operations/cp.8023] to finish...done.Updated property [core/project].PROJECT_ID     NAME      PROJECT_NUMBERshop-dev-123   Shop Dev  482910334455
OUTPUTterminalutf-8 · 5L

Most teams use one project per environment (dev, test, prod) and sometimes one per team or app. Deleting a project stops everything in it, and it can be restored for about 30 days.

Billing

A project can create paid resources only when it is linked to a billing account. The billing account holds the payment method. One billing account can pay for many projects.

gcloud billing accounts listgcloud billing projects link shop-dev-123 --billing-account=0123AB-4567CD-89EF01
SHELLbashutf-8 · 2L
ACCOUNT_ID            NAME             OPEN  MASTER_ACCOUNT_ID0123AB-4567CD-89EF01  Example Billing  TruebillingAccountName: billingAccounts/0123AB-4567CD-89EF01billingEnabled: truename: projects/shop-dev-123/billingInfoprojectId: shop-dev-123
OUTPUTterminalutf-8 · 6L

APIs must be turned on

Each service has an API that is off by default in a new project. If you call a service that is off, you get an error.

gcloud services enable compute.googleapis.com run.googleapis.comgcloud services list --enabled --format="value(config.name)" | head -3
SHELLbashutf-8 · 2L
Operation "operations/acat.p2-482910334455-5f0d" finished successfully.bigquery.googleapis.comcompute.googleapis.comrun.googleapis.com
OUTPUTterminalutf-8 · 4L

IAM: who, what, where

An IAM rule answers three questions:

PartQuestionExample
PrincipalWho?user:ana@example.com, group:devs@example.com, a service account
RoleWhat can they do?roles/storage.objectViewer
ResourceWhere?an organization, folder, project or a single bucket

The rule is called a binding. A set of bindings on a resource is its IAM policy.

Three kinds of role

KindWhat it isUse it?
BasicOwner, Editor, Viewer. Very wideAvoid in real projects
PredefinedMade by Google for one service, such as roles/compute.instanceAdmin.v1Yes, first choice
CustomYou pick exact permissionsWhen no predefined role fits
gcloud projects add-iam-policy-binding shop-dev-123 \  --member="group:devs@example.com" \  --role="roles/run.developer" gcloud projects get-iam-policy shop-dev-123 --format=json | head -12
SHELLbashutf-8 · 5L
Updated IAM policy for project [shop-dev-123].bindings:- members:  - group:devs@example.com  role: roles/run.developer- members:  - user:ana@example.com  role: roles/owneretag: BwYhX2b9ZkU=version: 1
OUTPUTterminalutf-8 · 10L

Inheritance

Policies flow down. A role given on a folder applies to every project in it. You cannot take away at a lower level what was granted above (use deny policies for that). So grant roles as low as possible.

Service accounts

A service account is an identity for a program, not a person. Your VM or app uses it to call other services. Lesson 17 goes deep. For now remember: give each app its own service account with only the roles it needs.

gcloud iam service-accounts create shop-api --display-name="Shop API"
SHELLbashutf-8 · 1L
Created service account [shop-api].
OUTPUTterminalutf-8 · 1L

Good habits

  • Give roles to groups, not to single people.
  • Use predefined roles, never Owner or Editor for daily work.
  • Turn on 2-step verification for every human.
  • Review who has access, now and then. gcloud asset search-all-iam-policies can help.

Common mistakes

  • Giving roles/editor because "it just works". It can change almost everything.
  • Mixing up project name and project ID in commands.
  • Forgetting to enable the API, then reading a confusing "permission denied" or "API not enabled" error.
  • Creating service account keys and emailing them. Lesson 17 shows better ways.

Summary

  • A project holds resources, permissions and the bill.
  • Billing is a separate account that you link to projects.
  • APIs must be enabled per project.
  • IAM = principal + role + resource. Policies are inherited from above.
  • Prefer groups, predefined roles and service accounts per app.

CHECK YOUR UNDERSTANDING

3 quick questions

  1. 1. Which project name can never be changed after creation?

  2. 2. An IAM binding connects which three things?

  3. 3. You give a group a role on a folder. What happens to projects inside the folder?

You've finished the free preview of Google Cloud (GCP)

Upgrade to Pro to unlock the remaining 21 lessons, every practice lab and a certificate when you finish.

See plans