Ensuring data protection · Topic 2 of 5

Restricting Data Services, Secret Manager and Instance Metadata

Restrict access to BigQuery, Cloud Storage and Cloud SQL, store and rotate secrets in Secret Manager, and protect Compute Engine instance metadata.

  • 6 min
In a nutshell
  • BigQuery: dataset IAM, authorized views, row policies, policy tags and dynamic masking.
  • Cloud Storage: uniform access, public access prevention, signed URLs for outsiders.
  • Cloud SQL: private IP, no open authorized networks, TLS, IAM database authentication.

What it is

Data loss often happens through ordinary access paths: a bucket made public, a table shared too widely, a database open to the internet, or a password in a startup script. This page covers the controls on each data service, Secret Manager for credentials, and the metadata server every VM can query.

PrincipalIAM on dataset, bucket, instanceFine grained controlsrows, columns, prefixesNetwork controlsprivate IP, perimeterData

How it works

BigQuery

ControlGranularityUse
IAM rolesProject, dataset, table or viewData Viewer on a dataset, not the project
Authorized views and authorized datasetsA view that reads tables the user cannot readShare a filtered or aggregated subset
Row-level access policiesRows matching a filterEach region sees only its own customers
Column-level security with policy tagsColumns tagged in a taxonomyOnly holders of Fine-Grained Reader see the column
Dynamic data maskingColumns, per user groupShow masked values, such as a hash or nulls, to most users
CREATE ROW ACCESS POLICY emea_only
ON sales.orders
GRANT TO ('group:emea-analysts@example.com')
FILTER USING (region = 'EMEA');

Cloud Storage

  • Uniform bucket-level access so only IAM applies, with IAM conditions on object name prefixes when needed.
  • Public access prevention on buckets, or enforced with the storage.publicAccessPrevention organization policy.
  • Signed URLs for time-limited access by someone without a Google identity.
  • Retention policies, object holds and soft delete to protect against deletion.

Cloud SQL

RiskControl
Database reachable from the internetPrivate IP only; organization policy sql.restrictPublicIp
Wide authorized networksNever 0.0.0.0/0; organization policy sql.restrictAuthorizedNetworks
Unencrypted client connectionsRequire SSL/TLS connections; connect through the Cloud SQL Auth Proxy or language connectors
Shared database passwordsIAM database authentication, with users mapped to Google identities
Who can administer instancesCloud SQL Admin for the platform team; Cloud SQL Client for apps that connect

For every data service, a VPC Service Controls perimeter stops data being copied out even by users with valid credentials.

Secret Manager

Secret Manager stores API keys, passwords and certificates as secrets, each with numbered versions.

FeatureDetail
Access controlIAM per secret: Secret Manager Secret Accessor (roles/secretmanager.secretAccessor) reads values
ReplicationAutomatic, or user-managed to chosen regions for residency
EncryptionGoogle default, or CMEK with Cloud KMS
VersionsPin a version number, or read latest; disable or destroy old versions
RotationA rotation schedule sends Pub/Sub notifications; your function creates the new version
AuditingData Access audit logs record each access when enabled
gcloud secrets create db-password \
  --replication-policy=user-managed --locations=europe-west1,europe-west4

printf 's3cr3t-value' | gcloud secrets versions add db-password --data-file=-

gcloud secrets add-iam-policy-binding db-password \
  --member="serviceAccount:app-backend@prod-app.iam.gserviceaccount.com" \
  --role="roles/secretmanager.secretAccessor"

Grant Secret Accessor on the individual secret to the workload's service account. Cloud Run and GKE can mount secrets directly, so code never stores them.

Protecting compute instance metadata

Every VM can query the metadata server at metadata.google.internal (169.254.169.254) with the header Metadata-Flavor: Google. It returns instance details, startup scripts, custom metadata and access tokens for the attached service account.

RiskControl
Secrets in metadata or startup scriptsAnyone with view access to the instance can read them; use Secret Manager
Server-side request forgery reaching the metadata serverHarden the app; give the service account minimal roles
Project-wide SSH keys in metadataUse OS Login (enable-oslogin=TRUE, enforced by compute.requireOsLogin); block project-wide keys
Who can change metadatacompute.instances.setMetadata lets someone add SSH keys or startup scripts; grant it narrowly
Serial console accessOrganization policy compute.disableSerialPortAccess
GKE pods reading node metadataWorkload Identity Federation for GKE, which hides the node's metadata from pods

OS Login ties SSH access to IAM roles (OS Login and OS Admin Login) and supports 2-Step Verification, so leavers lose access when their account is suspended.

A worked example

A review finds a database password in a VM startup script, project-wide SSH keys, and a Cloud SQL instance with a public IP. The engineer moves the password into Secret Manager with Secret Accessor for the VM's service account only, and the startup script reads it at boot.

OS Login is enforced by organization policy, and project-wide SSH keys are removed. The Cloud SQL instance moves to private IP, and sql.restrictPublicIp prevents a repeat.

Password in startup scriptSecret Manageraccessor for one accountOS Loginenforced by policyCloud SQLprivate IP only

How the exam asks about this

  • "Analysts in each country may see only rows for their country in one shared table." BigQuery row-level access policies.
  • "Only the HR group may see salary values; others may query the table but see the column masked." Policy tags with dynamic data masking.
  • "Developers must not be able to add their own SSH keys to production VMs." Enforce OS Login and control access with IAM roles instead of metadata keys.

What to remember for the exam

  • BigQuery: dataset IAM, authorized views, row policies, policy tags and dynamic masking.
  • Cloud Storage: uniform access, public access prevention, signed URLs for outsiders.
  • Cloud SQL: private IP, no open authorized networks, TLS, IAM database authentication.
  • Secret Manager: Secret Accessor per secret, versions, user-managed replication, CMEK.
  • Never put secrets in metadata; use OS Login and restrict who can set metadata.
Watch out

Anyone with read access to an instance's configuration can read its metadata and startup scripts. Secrets stored there are effectively shared with every project viewer.

Common mistakes

Granting Secret Accessor on the project. The workload can then read every secret in the project. Grant it on the one secret it needs.

Copying a table to hide columns. Copies drift and multiply the data to protect. Use policy tags, masking or authorized views on the original.

Leaving metadata SSH keys in place after enabling OS Login on some VMs. Keys in project metadata still apply to VMs without OS Login. Enforce OS Login organization-wide and remove the keys.

Check yourself

  • Which BigQuery feature limits a user to certain rows of a table?

    A row-level access policy with a filter granted to that user or group.

  • How should an application on Cloud Run get a database password?

    Store it in Secret Manager, grant Secret Accessor on that secret to the service's account, and mount or read it at run time.

  • Which organization policy forces SSH access to be controlled by IAM?

    compute.requireOsLogin, which enforces OS Login on VMs.

Topic 2 of 5 in Ensuring data protection

Test yourself on Ensuring data protection

The full Google Cloud Professional Cloud Security Engineer question bank has 749 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.