Q1
GCP Data Engineering · Chapter 09
User and Project Management in GCP
Building a pipeline is easy. Deciding who may touch it, and how projects are organised, is what separates a development solution from a production one. This chapter is about governance: IAM, project structure, data access, and infrastructure as code.
0 of – checks answered
01
IAM: who can do what
Identity and Access Management is the central authorisation service for all of GCP. The idea is simple: grant roles to accounts.
Who is asking
Either a user account (a person, for example a work email) or a service account (a program or VM). Composer, Dataflow, Dataproc and Cloud SQL all run as service accounts. Every new project also gets a default service account.
- Human
- User account
- Automation
- Service account
- Check yours
- IAM & Admin, then Service Accounts
The smallest unit of access
A single allowed operation on a service, such as bigquery.jobs.create (run a job) or bigquery.tables.getData (read table data). You cannot grant a permission directly; permissions only come inside roles.
- Example
- bigquery.tables.getData
- Find them
- Each service’s access-control docs
- Granted as
- Part of a role
A bundle of permissions you grant
Roles are what you give an account. Querying a table needs at least two: one to read the data (data viewer) and one to run query jobs (job user). Note that being allowed to run a job does not by itself give access to any data.
- Query a table needs
- Data viewer plus job user
- Categories
- Basic, predefined, custom
- Grant at
- Organization, folder, project, or resource
The rule behind all of it
Give each person or process only the permissions essential to its purpose, and nothing more. It is the foundation of IAM, project structure and BigQuery access control alike.
- Bad habit
- Making everyone Editor
- Good habit
- Predefined roles at the narrowest sensible level
Which kind of role?
-
01 Your own owner role in a throwaway practice project.
-
02 A data engineer who needs to build BigQuery pipelines, and nothing else.
-
03 No predefined role has quite the permission set your organisation needs.
02
Organization, folder, project: inheritance
Resources sit in projects, projects in folders, folders in a single organization. A grant flows down: whoever holds a role on a parent holds it on every child. Try it.
Click a node to give the selected person the role there (click again to remove it). Goal: Adam should see everything under the dev folder; Agnes only the marketing project.
- Adam can read
- Agnes can read
A tall folder tree that grants everything at project level gives you no benefit from folders, only operational overhead. Plan from the bottom up: if some users or service accounts always need the same set of projects, that set deserves a parent folder. There is normally one organization per company.
03
How many projects should you have?
There is no single right answer, and every company differs. Small companies start with one project and grow. The decision comes down to three benefits, weighed against the overhead of splitting.
| Reason to split | Because |
|---|---|
| Different IAM and service needs | Teams that use different services and need different roles should not share one project. Splitting one team’s services (BigQuery, Composer, GCS) across projects helps no one. |
| Limits and quotas | Quotas apply per project. A heavily used service may need several projects, for example to avoid a 100 concurrent interactive query cap. |
| Cost tracking | The billing dashboard shows cost per project. Splitting gives clear attribution, though the bill still goes to one billing account. |
-
01 A start-up with a small team building an MVP and no one to run operations.
-
02 A company where the app, data and ML teams use different services and need different roles.
-
03 More than 1,000 active BigQuery users, and a per-project limit of 100 concurrent interactive queries.
-
04 Finance wants to see cost per team on the billing dashboard.
Resources in different projects are not isolated: a Composer environment in a data project can read a Cloud SQL database in an application project, as long as the permissions allow it.
04
Controlling access to the warehouse
An access control list is simply IAM applied to data. BigQuery has two kinds of permission: job permissions (may you run a query) and access permissions (may you read this data).
| Level | What one grant covers |
|---|---|
| Project | Every dataset, table, column and row inside it |
| Dataset | Every table in that dataset, present and future |
| Table | That table only. This is the minimum needed to query it |
| Column / row | Fine-grained rules inside a table (policy tags, row filters) |
Where should the grant go?
-
01 Data engineers must create and view every table in the warehouse, including tables that do not exist yet.
-
02 Sales needs the checkout and cart tables. Group those two tables into one dataset and grant on it.
-
03 One analyst needs to read a single table and nothing else.
-
04 Marketing may read the user profile table but never its credit card number column.
The e-commerce example in the book: with six tables and four groups, mapping each group to its tables shows which tables cluster together. Create datasets from those clusters and grant roles per dataset. It scales, because a new table dropped into a dataset inherits the access.
Column-level security in three steps
Define your classifications
A taxonomy is your organisation’s classification scheme, for example PII with children such as credit card number. It is planned once, ideally by data engineers, data governors and legal together.
- Contains
- One or many policy tags
- Reusable
- Tags apply to any number of columns
Turn on enforcement
Create the tags (parent PII, child credit card number) and switch on the enforce-access-control toggle. Without enforcement the tags are only labels.
- Key toggle
- Enforce access control
- Grant access to
- The tag, not the column
Apply it in the table schema
Edit the table schema and add the policy tag to each sensitive column. Users without access to that tag get an error selecting the column, though they can still query the rest with an EXCEPT clause.
- Result
- Column blocked unless you hold the tag
- Benefit
- No copy tables or extra views needed
05
Infrastructure as code with Terraform
Clicking through a console does not scale, and it leaves no record. With infrastructure as code you declare the resources you want in files, and a tool makes reality match. Terraform is the common open-source choice. Try its cycle.
Terraform compares what you declare with what exists. Toggle the dataset declaration, then run the commands in order and watch what each one does.
- In main.tf
- Actually exists in GCP
| File / command | Purpose |
|---|---|
| backend.tf | Where Terraform keeps its state (a Cloud Storage bucket and prefix) |
| main.tf | The provider and your resources |
| variables.tf + terraform.tfvars | Declare a variable, then set its value in a file |
| terraform init | Download the provider libraries into a hidden .terraform folder |
| terraform plan | Preview what would be added, changed or destroyed |
| terraform apply | Do it, after you type yes |
Almost every GCP resource can be managed this way. DevOps or infrastructure teams usually own it, but data engineers often contribute the data-related resources, and knowing IaC changes how you design them.
06
Hands-on: govern and codify
This chapter is mostly design. Do the planning steps first, then the Terraform ones.
-
IAM & Admin, then Service Accounts. Find the default compute service account and any Composer, Dataproc or Cloud SQL ones you created.
-
Read the BigQuery access-control documentation and note which role gives table read access and which lets you run jobs.
-
Take four groups (data engineers, marketing, sales, head of analysts) and six tables. Write down who needs what, then design datasets so each grant covers a whole dataset.
-
Create a taxonomy with a parent tag such as PII and a child tag for credit card numbers, turn on access control enforcement, tag the column in the table schema, and test that an unprivileged user gets an error selecting it.
-
Download a current release from Terraform’s site, unzip it and move the binary onto your path. Then check the version.
terraform --version -
The backend stores state in a Cloud Storage bucket, the provider names Google and a project variable, and the tfvars file sets that variable.
terraform { backend "gcs" { bucket = "YOUR_BUCKET" prefix = "terraform-backend-basic" } } -
Expect "no changes". You have proven the plumbing works.
terraform init terraform plan terraform apply -
Read the plan output before typing yes, then check the console.
resource "google_bigquery_dataset" "new_dataset" { project = var.project_id dataset_id = "dataset_from_terraform" } -
A new project, the BigQuery API enabled, three datasets (staging, warehouse, mart) and a service account for BigQuery workloads.
-
Remove what you created, so nothing lingers.
terraform destroy
07
Key terms
- IAM
- GCP’s central authorisation service.
- Role
- A set of permissions you grant to an account.
- Basic / predefined / custom
- Broad legacy roles; per-service curated roles; roles you define yourself.
- Least privilege
- Grant only what is needed for the task.
- Organization / folder / project
- The resource hierarchy. Permissions inherit downward.
- ACL
- Access control list: IAM applied to data.
- Taxonomy / policy tag
- A classification scheme and its labels for column-level security.
- PII
- Personally identifiable information.
- IaC
- Managing infrastructure through code.
- Terraform
- Open-source IaC tool using init, plan and apply.
08
Check yourself
Pick an answer to see the reasoning straight away.
Q2
Why is granting roles/editor to a data engineer for BigQuery work risky?
Q3
What is the best reason to create a parent folder?
Q4
How many organizations does a company typically have in GCP?
Q5
To hide a credit card column, whose permission do you manage?
Q6
You run terraform plan. What does it do?
Study notes in my own words, following the structure of Adi Widjaja's Data Engineering with Google Cloud Platform (Packt, 2022). GCP changes quickly, so check each service's current documentation before relying on names, prices or console steps.