Getting Started with Google Cloud Platform: A Beginner’s Guide to Cloud Excellence

5.63K 0 0 0 0

📘 Chapter 4: Managing Access, IAM, and Billing in GCP

🔍 Overview

Effective access control and billing management are essential components of working with Google Cloud Platform (GCP). Without proper IAM configuration, your resources are vulnerable to misuse or compromise. Similarly, poor billing practices can lead to unexpected costs.

This chapter covers:

  • The fundamentals of Identity and Access Management (IAM)
  • Setting up users, roles, and permissions
  • Creating service accounts for automation
  • Configuring budgets, billing accounts, and alerts
  • Best practices to ensure security and cost-efficiency

🧠 1. Understanding IAM in GCP

IAM lets you define who (identity) has what access (roles) to which resources.

🔹 Key Terms

Term

Description

Principal

An entity (user, group, service account) making a request

Role

A collection of permissions

Policy

Mapping of principals to roles for a resource

🔑 Types of Principals

  • Google account (user:someone@gmail.com)
  • Service accounts (serviceAccount:my-sa@project.iam.gserviceaccount.com)
  • Google Groups (group:devs@company.com)
  • G Suite domains
  • All users (allUsers) or all authenticated users (allAuthenticatedUsers)

📘 Common Roles in GCP

Role

Permission Level

Best For

Viewer

Read-only access

Auditors, reviewers

Editor

Read and write access

Developers

Owner

Full access + billing

Admins

Custom Role

Custom-defined scopes

Specific needs (e.g., read-only BigQuery)


🛠️ 2. Assigning IAM Roles

Console Steps:

  1. Go to IAM & Admin → IAM
  2. Click "Add"
  3. Enter email and select role(s)
  4. Click "Save"

CLI Command:

bash

 

gcloud projects add-iam-policy-binding my-project-id \

  --member="user:john@example.com" \

  --role="roles/editor"


🤖 3. Service Accounts

Service accounts are non-human accounts used by apps, VMs, or APIs to access GCP resources securely.

🔹 When to Use

  • VM instances needing storage access
  • CI/CD pipelines deploying resources
  • Cloud Functions accessing APIs

Create a Service Account:

bash

 

gcloud iam service-accounts create my-app \

  --description="App-level service account" \

  --display-name="My App"

Assign Roles:

bash

 

gcloud projects add-iam-policy-binding my-project-id \

  --member="serviceAccount:my-app@my-project.iam.gserviceaccount.com" \

  --role="roles/storage.objectViewer"

Generate Key for External Use:

bash

 

gcloud iam service-accounts keys create key.json \

  --iam-account=my-app@my-project.iam.gserviceaccount.com

️ Tip: Never hardcode keys into public repositories.


🔐 4. IAM Best Practices

  • Follow Principle of Least Privilege: Grant only the minimum required access
  • Use Predefined Roles Over Owner: Avoid using overly broad roles
  • Enable MFA for Admins
  • Use Custom Roles for specific access needs
  • Audit IAM Changes using Cloud Audit Logs

💳 5. Understanding GCP Billing Structure

GCP uses a centralized billing model tied to your Google account.

🔹 Billing Hierarchy

Element

Description

Billing Account

A payment profile (credit card, invoice, etc.)

Project

Resources consuming usage

Budgets

Set cost thresholds and get alerts

🔹 Account Types

Account Type

Linked Projects

Payment Options

Individual

1 or many

Credit/Debit card

Organization

Many

Invoicing, card, PO


📈 6. Creating Budgets and Alerts

Stay within budget using Budgets & Alerts.

Console Steps:

  1. Go to Billing → Budgets & alerts
  2. Click "Create Budget"
  3. Set monthly limit (e.g., $20)
  4. Set alert thresholds (50%, 90%, 100%)
  5. Add email recipients

Use CLI:

bash

 

gcloud billing budgets create --billing-account=XXXX \

  --display-name="Budget Alert" \

  --budget-amount=20USD \

  --threshold-rules="percent=0.5,percent=0.9,percent=1"


📄 7. Viewing Billing Reports

GCP provides detailed usage and cost reports.

Tool

Use For

Billing Dashboard

Overview of monthly spend

Cost Table Report

Usage per project/service/resource

Cost Breakdown

Charts, filters, and export to CSV

Billing Export to BigQuery

For custom analysis and dashboards


🧪 8. Export Billing Data to BigQuery

Step 1: Go to Billing → Settings → Export
Step 2: Choose BigQuery Dataset
Step 3: Query data like:

sql

 

SELECT

  service.description,

  SUM(cost) as total_cost

FROM

  `billing_dataset.gcp_billing_export`

GROUP BY

  service.description

ORDER BY

  total_cost DESC


🧩 Summary Table – IAM and Billing Essentials


Task

Best Practice / Tool

Assign user access

IAM roles (Viewer, Editor, Custom)

Programmatic access

Use Service Accounts with key rotation

Prevent overcharges

Set Budgets and Alerts

Monitor usage

Use Billing Reports and BigQuery Exports

Secure Admin roles

Use MFA and Audit Logs

Back

FAQs


❓1. What is Google Cloud Platform (GCP)?

Answer:
GCP is Google’s suite of cloud computing services that provides infrastructure, platform, and serverless environments to build, deploy, and scale applications using the same technology that powers Google Search, YouTube, and Gmail.

❓2. Is Google Cloud free to use?

Answer:
Yes. GCP offers a $300 free credit for 90 days for new users and an Always Free Tier for services like Cloud Storage, BigQuery, and Compute Engine (1 f1-micro instance in select regions).

❓3. How do I start using GCP?

Answer:
To get started, create a Google Cloud account at cloud.google.com, set up your first project, enable billing, and explore the Console or use the gcloud CLI for resource management.

❓4. What’s the difference between Compute Engine and App Engine?

Answer:

  • Compute Engine gives you full control over virtual machines (IaaS).
  • App Engine is a fully managed PaaS that handles infrastructure, scaling, and deployments automatically.

❓5. What is a GCP project?

Answer:
A GCP project is a container for resources like VMs, buckets, APIs, and billing. It isolates services and permissions and helps organize workloads across environments.

❓6. Which programming languages are supported by GCP?

Answer:
GCP supports many languages including Python, Java, Go, Node.js, Ruby, PHP, C#, and .NET, depending on the service used (App Engine, Cloud Functions, Cloud Run, etc.).

❓7. What tools are used to manage GCP?

Answer:
You can manage GCP via:

  • Google Cloud Console (UI)
  • Cloud Shell (browser-based CLI)
  • gcloud CLI
  • REST APIs
  • Terraform and Deployment Manager for infrastructure as code

❓8. What is BigQuery used for?

Answer:
BigQuery is a serverless data warehouse that allows you to store and analyze large datasets using SQL. It’s ideal for data analytics, reporting, and business intelligence.

❓9. Is GCP good for hosting websites?

Answer:
Yes. GCP offers multiple options to host websites:

  • Static websites via Cloud Storage + CDN (Cloud CDN)
  • Dynamic web apps using App Engine or Cloud Run
  • Custom VMs via Compute Engine

❓10. Does GCP offer certifications?

Answer:
Yes. Google Cloud offers certifications like:

  • Cloud Digital Leader (beginner)
  • Associate Cloud Engineer
  • Professional Cloud Architect
  • Data Engineer, DevOps Engineer, and more, to validate your cloud skills.