IAM is the authorisation layer, and the granularity has a specific shape. Roles exist at the project, instance and - importantly - table level: bigtable.user, bigtable.reader, bigtable.viewer, bigtable.admin. Granting bigtable.user on a single table gives read and write access to that table and nothing else, which is how you build a narrow application identity.
What IAM cannot do here is row-level or column-level access control. There is no equivalent of a row filter enforced by the platform. So multi-tenant isolation is either a table per tenant - which is viable, since tables are cheap and there is no per-table cost - or an application layer you trust, with the row key prefixed by tenant and the application responsible for never constructing a key outside its tenant. The first is strongly preferable, and saying which you chose is part of a security review.
Service accounts are how applications authenticate. The rules: one service account per application, the narrowest role on the narrowest resource, workload identity rather than a downloaded key file, and no bigtable.admin anywhere near an application. bigtable.admin can delete tables and backups, which makes it the role whose grant list you audit.
Encryption at rest is always on. The choice is Google-managed keys (default) or CMEK - a key in Cloud KMS that you control, giving you rotation, an audit trail of key use, and the ability to make the data unreadable by revoking the key. CMEK is set at cluster creation and cannot be added to an existing cluster, so it is a decision to make before loading data. Note that a CMEK key must be in the same region as the cluster.
Autoscaling adjusts node count between a minimum and a maximum based on CPU utilisation and storage. It works well and has specific limits to know: it responds over minutes, not seconds, so it does not absorb a sudden spike; it will not scale below the storage requirement; and - the important one - autoscaling cannot fix a hotspot, because the signal it reacts to is average CPU and a hotspot leaves the average low. An instance with a hotspotting key and autoscaling enabled will sit at its minimum node count while one node burns.
Monitoring. The set that matters, with the Bigtable-specific ones marked:
cpu_loadandcpu_load_hottest_nodetogether - specific, and the pair that distinguishes a hotspot from a capacity shortage. Alert on the gap between them, not just on the maximum.disk_load- storage utilisation per node, which has a hard ceiling.- Server latency p99 by method, and error rate by status code.
replication_latencyand the replicated-bytes rate, if replicating.- Key Visualizer, reviewed on a schedule rather than only during an incident - specific, and genuinely worth a calendar entry.
- Node count against the autoscaling bounds, so you know when you are pinned at the maximum.
Quotas that bound a design: nodes per zone per project, instances per project, tables per instance, column families per table (about 100), backups per table, and the API request quotas. Several are raisable; knowing them prevents a design that cannot be deployed.
Laboratory exercise 6 - make it defensible.
Define the instance, clusters and app profiles as infrastructure as code and deploy it.
Implement least privilege: a service account with bigtable.user on one table only; a reader service account; and a monitoring identity with metrics access and no data access. Test every denial.
Demonstrate the multi-tenant limitation: show that IAM cannot restrict a caller to a row key prefix, then implement the table-per-tenant alternative and show the isolation IAM does enforce.
Create a cluster with CMEK, demonstrate revoking the key making data unreadable, and record that it cannot be added to an existing cluster.
Configure autoscaling, then demonstrate its limit: run a hotspotting workload and show autoscaling staying at the minimum while the hottest node saturates. Then run a well-distributed workload and show it scaling correctly. Measure the response delay in both cases.
Configure monitoring with every metric above, and write the alert that specifically detects a hotspot - the gap between average and hottest-node CPU.
Then produce the quota review and a cost model from your measured node count.
Deliverable: the infrastructure as code, the IAM policies, a test script attempting every forbidden operation with its output, the multi-tenant demonstration both ways, the CMEK revocation evidence, the autoscaling limit demonstration with both workloads, the alert definitions including the hotspot alert, the quota review, and the cost model.
# ==================================================================
# IAM: roles at PROJECT, INSTANCE and *** TABLE *** level.
# ==================================================================
# bigtable.admin everything, including DELETE TABLE and DELETE
# BACKUP. Audit who has it.
# bigtable.user read AND write data
# bigtable.reader read data only
# bigtable.viewer metadata only - no data at all
#
# TABLE-LEVEL granting is how you build a narrow application
# identity:
# gcloud bigtable instances tables add-iam-policy-binding telemetry \
# --instance=telemetry \
# --member=serviceAccount:ingest@P.iam.gserviceaccount.com \
# --role=roles/bigtable.user
# -> read and write on THAT TABLE and nothing else.
#
# gcloud bigtable instances tables add-iam-policy-binding telemetry \
# --instance=telemetry \
# --member=serviceAccount:report@P.iam.gserviceaccount.com \
# --role=roles/bigtable.reader
#
# Monitoring: metrics, NO DATA:
# gcloud projects add-iam-policy-binding P \
# --member=serviceAccount:monitor@P.iam.gserviceaccount.com \
# --role=roles/monitoring.viewer
#
# VERIFY THE DENIALS - every one must fail:
# ingest@ deleting the table -> PermissionDenied
# ingest@ reading a DIFFERENT table -> PermissionDenied
# report@ writing -> PermissionDenied
# monitor@ reading any row -> PermissionDenied
# ==================================================================
# *** WHAT IAM CANNOT DO: ROW- OR COLUMN-LEVEL ACCESS CONTROL. ***
# ==================================================================
# There is NO platform-enforced row filter. So multi-tenant isolation
# is one of two things:
#
# (a) *** A TABLE PER TENANT. *** Viable, because tables are cheap
# and there is NO PER-TABLE COST - you pay for nodes and
# storage. IAM then enforces the isolation properly:
# tenant_acme -> bigtable.user for acme's service account
# tenant_globex -> bigtable.user for globex's
# STRONGLY PREFERABLE.
#
# (b) A TENANT PREFIX IN THE ROW KEY and an application layer you
# trust never to construct a key outside its tenant:
# tenant#acme#dev#d-0042#...
# Nothing in the platform enforces this. One missing check is a
# cross-tenant read, and there is no audit trail that
# distinguishes it from a legitimate one.
#
# SAYING WHICH YOU CHOSE, AND WHY, IS PART OF A SECURITY REVIEW.
# Demonstrate both in the lab, including the fact that (b) cannot be
# enforced.
# ==================================================================
# SERVICE ACCOUNTS
# ==================================================================
# * ONE per application
# * the NARROWEST role on the NARROWEST resource
# * *** WORKLOAD IDENTITY, NOT A DOWNLOADED KEY FILE *** - a key
# file is a credential that leaks
# * NO bigtable.admin anywhere near an application. It can delete
# tables AND BACKUPS, which makes it the role whose grant list
# you audit on every inherited project.
# gcloud projects get-iam-policy P \
# --flatten="bindings[].members" \
# --filter="bindings.role=roles/bigtable.admin"
# ==================================================================
# CMEK: a decision to make BEFORE loading data.
# ==================================================================
# gcloud bigtable instances create telemetry \
# --cluster-config=id=prod-c1,zone=europe-west2-a,nodes=3,\
#kms-key=projects/P/locations/europe-west2/keyRings/R/cryptoKeys/K
#
# Encryption at rest is ALWAYS ON. The choice is the KEY:
# Google-managed default, no visibility
# CMEK rotation, an audit trail of key use in
# CloudTrail-equivalent logs, and *** the
# ability to make the data UNREADABLE by
# revoking the key ***
#
# *** CMEK IS SET AT CLUSTER CREATION AND CANNOT BE ADDED TO AN
# *** EXISTING CLUSTER. *** So it is a decision before you load
# data, not after. And the key must be IN THE SAME REGION as the
# cluster.
#
# Demonstrate the revocation - it is the capability you are paying
# for, and seeing the data become unreadable is the point.
# ==================================================================
# AUTOSCALING - and *** ITS ONE IMPORTANT LIMIT. ***
# ==================================================================
# gcloud bigtable clusters update prod-c1 --instance=telemetry \
# --autoscaling-min-nodes=3 --autoscaling-max-nodes=30 \
# --autoscaling-cpu-target=60 \
# --autoscaling-storage-target=4096
#
# It works well. The limits to know:
# * it responds over MINUTES, not seconds, so it does NOT absorb
# a sudden spike
# * it will not scale BELOW the storage requirement
# * *** AUTOSCALING CANNOT FIX A HOTSPOT. ***
#
# WHY: the signal is AVERAGE CPU, and a hotspot leaves the average
# LOW. So an instance with a hotspotting key and autoscaling
# enabled WILL SIT AT ITS MINIMUM NODE COUNT WHILE ONE NODE BURNS.
#
# hotspotting workload:
# cpu_load 0.21 -> below the 60% target -> NO SCALING
# cpu_load_hottest_node 0.98 -> the actual problem
# nodes: 3, pinned at the minimum, forever
#
# Demonstrate both workloads in the lab, and measure the response
# delay for the one that does scale.
# ==================================================================
# MONITORING: the pair that matters most is a PAIR.
# ==================================================================
# bigtable.googleapis.com/cluster/cpu_load (average)
# bigtable.googleapis.com/cluster/cpu_load_hottest_node (max)
# bigtable.googleapis.com/cluster/disk_load (storage)
# bigtable.googleapis.com/server/latencies (p99 by method)
# bigtable.googleapis.com/server/error_count (by status)
# bigtable.googleapis.com/server/request_count
# bigtable.googleapis.com/cluster/replication_latencies
# bigtable.googleapis.com/table/bytes_used
# bigtable.googleapis.com/cluster/node_count (vs autoscaling max)
#
# *** THE HOTSPOT ALERT - write this one. It is the alert that
# *** distinguishes a hotspot from a capacity shortage, and neither
# *** metric alone can: ***
#
# cpu_load_hottest_node > 0.8 AND cpu_load < 0.5
# -> A HOTSPOT. Adding nodes will NOT help. Fix the key.
#
# cpu_load > 0.8 AND cpu_load_hottest_node > 0.8
# -> INSUFFICIENT CAPACITY. Add nodes (or let autoscaling).
#
# node_count == autoscaling_max for > 15 min
# -> pinned at the ceiling: raise it, or you are silently
# throttled
#
# disk_load > 0.7
# -> a HARD ceiling per node; this one does not degrade
# gracefully
#
# *** AND REVIEW KEY VISUALIZER ON A SCHEDULE, not only during an
# *** incident. *** A key pattern that is becoming skewed as your
# data grows is visible there weeks before it is visible in the
# latency. It is worth a calendar entry.
# ==================================================================
# QUOTAS that bound a design
# ==================================================================
# nodes per zone per project raisable
# instances per project raisable
# clusters per instance a small fixed number
# tables per instance a limit - matters for
# table-per-tenant designs
# COLUMN FAMILIES per table ~100, and fewer is better
# backups per table a limit
# row key 4 KB
# row size 256 MB (100 MB recommended)
# cell value 100 MB (10 MB recommended)
# API request quotas per minute, per project
#
# gcloud services quota list --service=bigtable.googleapis.com \
# --consumer=projects/P
#
# *** THE ONE TO CHECK IF YOU CHOSE TABLE-PER-TENANT: tables per
# *** instance. *** It is the limit that turns a good isolation
# design into one that cannot be deployed at your tenant count, and
# it is better discovered now.
Open this example in the editor and change it. Nothing you type is saved.
Discussion
No questions on this topic yet. Sign in to ask the first one.