Designing data processing systems · Topic 1 of 5

IAM, Encryption Keys and PII Protection

Data engineer security design on Google Cloud: IAM roles and organization policies, CMEK with Cloud KMS, AEAD crypto shredding and Cloud DLP for PII.

  • 5 min
In a nutshell
  • Querying needs Job User on a project plus Data Viewer on the data.
  • Grant roles to groups and dedicated service accounts at the narrowest level.
  • Organization policies enforce locations, domains and CMEK across many projects.

What it is

Security design for a data platform answers three questions. Who may run jobs and read data (IAM and organization policies), how data is protected at rest and in transit (encryption and key management), and what happens to personal data such as names, emails and card numbers (privacy controls).

Identityusers, groups, service accountsIAM rolesleast privilegeOrganization policiesguardrailsEncryptiondefault or CMEKPII controlsmask, tokenize, delete

How it works

IAM for data services

Grant roles to groups and service accounts, never to individuals one by one. Grant at the narrowest level that works: table or dataset before project.

NeedBigQuery roleGranted on
Run queries and pay for themBigQuery Job User (roles/bigquery.jobUser)The project that runs the jobs
Read table dataBigQuery Data Viewer (roles/bigquery.dataViewer)Dataset or table
Create and change tablesBigQuery Data Editor (roles/bigquery.dataEditor)Dataset
See schemas but not dataBigQuery Metadata ViewerDataset or project
Full control including sharingBigQuery Data Owner or BigQuery AdminDataset or project

Querying needs two things: permission to create jobs in a project, and permission to read the data. An analyst with Data Viewer alone gets "does not have bigquery.jobs.create permission".

Pipelines run as service accounts. A Dataflow job uses a worker service account; give it only the roles its sources and sinks need, such as Dataflow Worker, Pub/Sub Subscriber and BigQuery Data Editor on one dataset.

Organization policies

Organization policies are guardrails set on the organization, a folder or a project. They apply whatever IAM says.

ConstraintEffect
gcp.resourceLocationsResources can be created only in allowed locations
iam.allowedPolicyMemberDomainsDomain restricted sharing: IAM grants only to your own domains
gcp.restrictNonCmekServicesListed services must use customer managed keys

Encryption and key management

All data is encrypted at rest and in transit by default. The design choice is who controls the keys.

OptionKey holderChoose it when
Google default encryptionGoogleNo key requirement in the stem
CMEK in Cloud KMSYou, in Cloud KMSYou must rotate, disable or audit key use
Cloud HSMYou, with keys in Google-operated hardware security modulesKeys must be protected by hardware
Cloud EKMYou, in an external key managerKeys must stay outside Google

BigQuery, Cloud Storage, Pub/Sub, Dataflow, Dataproc and Cloud SQL all support CMEK. Each service's service agent needs the Cloud KMS CryptoKey Encrypter/Decrypter role on the key. The key ring must be in a location compatible with the data.

Exam tip

Customer supplied encryption keys (CSEK) work only with Cloud Storage and Compute Engine. A question that needs your own keys for BigQuery means CMEK.

Privacy and PII strategies

StrategyTool
Find PII across tables and bucketsCloud DLP (now Sensitive Data Protection) discovery and inspection
Replace values before storageCloud DLP de-identification: masking, redaction, bucketing, date shifting
Keep values joinable but hiddenDeterministic encryption or format preserving encryption tokens
Hide columns from most readersBigQuery policy tags and data masking
Delete one person's data everywhereCrypto shredding: destroy that person's key

Tokenization lets analysts count and join on a customer without seeing the real value. Only holders of the key can re-identify.

A worked example

A retailer must let analysts study purchase history but honour erasure requests. The engineer encrypts the email column in BigQuery with a separate keyset per customer, stored in a protected key table.

-- one keyset per customer, kept in a restricted dataset
CREATE TABLE secure.customer_keys AS
SELECT customer_id, KEYS.NEW_KEYSET('AEAD_AES_GCM_256') AS keyset
FROM raw.customers;

-- store encrypted email in the analytics table
SELECT c.customer_id,
       AEAD.ENCRYPT(k.keyset, c.email, CAST(c.customer_id AS STRING)) AS email_enc
FROM raw.customers AS c
JOIN secure.customer_keys AS k USING (customer_id);

To erase a customer, delete their row from secure.customer_keys. Once the key table's time travel and fail-safe periods pass, the ciphertext in every table and copy is unreadable, which is far easier than finding every copy.

How the exam asks about this

  • "Analysts can see the dataset but every query fails with a jobs.create error." Grant BigQuery Job User on the project they query from.
  • "No IAM grant may ever be made to accounts outside the company." Domain restricted sharing organization policy.
  • "The security team must be able to revoke access to BigQuery data by disabling a key." CMEK with Cloud KMS.

What to remember for the exam

  • Querying needs Job User on a project plus Data Viewer on the data.
  • Grant roles to groups and dedicated service accounts at the narrowest level.
  • Organization policies enforce locations, domains and CMEK across many projects.
  • CMEK for control, Cloud HSM for hardware, Cloud EKM for keys outside Google.
  • Cloud DLP finds and de-identifies PII; crypto shredding handles erasure.
Watch out

Basic (formerly primitive) roles such as Owner, Editor and Viewer on a project are almost never the right answer. They grant far more than any data task needs.

Common mistakes

Granting dataViewer on the whole project. Every dataset in it becomes readable, including ones added later.

Choosing CSEK for BigQuery. BigQuery supports CMEK, not customer supplied keys.

Masking PII by copying tables. Copies drift and multiply the data you must protect; mask in place with policy tags or de-identify once at ingestion.

Check yourself

  • Which two permissions does an analyst need to query a BigQuery table?

    Permission to create jobs in a project (BigQuery Job User) and permission to read the table (BigQuery Data Viewer on the dataset or table).

  • Which key option keeps encryption keys outside Google's infrastructure?

    Cloud EKM, used as CMEK for the services that store the data.

  • How does crypto shredding satisfy an erasure request?

    Each person's data is encrypted with their own key, so destroying that key makes every copy of their data unreadable.

Topic 1 of 5 in Designing data processing systems

Test yourself on Designing data processing systems

The full Google Cloud Professional Data Engineer question bank has 733 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Google Cloud. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.