Connectivity and access in a Google Cloud database portfolio is a layered problem.
Identity and Access Management answers the question of who can perform an administrative action against an instance, who can route a connection request through the front door, and which workloads can request a short-lived authentication token.
Inside the engine, a second set of grants decides what each authenticated principal can read, write, or execute against schemas and rows.
Conflating the two layers is the single most common operational mistake when a team moves from self-managed databases into Cloud SQL or AlloyDB, and it remains the source of many exam distractors.
The right operational posture treats IAM and engine grants as two separate but linked planes, with provisioning automation responsible for keeping them aligned.
Comparison
Cloud SQL, AlloyDB, Spanner, Bigtable, and Firestore each expose a slightly different blend of these two planes.
- Spanner sits at one extreme: all data-plane access flows through IAM, with no separate database user list.
- Bigtable and Firestore are nearly the same shape, with all access bound to Google identities and IAM roles like
roles/bigtable.userandroles/datastore.user. - Cloud SQL and AlloyDB sit at the other end, where engine-level Postgres or MySQL roles remain authoritative for in-database privileges, while IAM still controls who can connect and (optionally) who can authenticate using a Google identity.
- Memorystore uses an AUTH string for engine access on top of IAM-controlled instance-level operations.
A connectivity diagram therefore has to call out which engine accepts IAM authentication, which still requires a password, and which uses a mix. The connection path itself is also under IAM control.
The Cloud SQL Auth Proxy and the AlloyDB Auth Proxy both require the principal running the proxy to hold a connector role, typically roles/cloudsql.client and roles/cloudsql.instanceUser for Cloud SQL, or roles/alloydb.client and roles/alloydb.databaseUser for AlloyDB.
Private Service Connect endpoints further constrain the network path, so an effective grant for an application requires three concurrent things to line up:
- IAM permission to connect
- network reachability to the endpoint
- either a valid database user with a password or a Google identity recognized as a database principal
When one of those three pieces is missing the engineer reads permission denied, dial tcp: i/o timeout, or password authentication failed respectively, and the troubleshooting starts from whichever message appears.
Determining IAM policies for database connectivity and access control
The first decision is the scope of the IAM binding.
Project-level grants make every database in the project reachable by the principal, which is appropriate for platform automation but rarely appropriate for application service accounts.
Instance-level grants on Cloud SQL and AlloyDB constrain access to one database server, while Spanner allows per-database and per-table fine-grained access control, and Bigtable supports per-table and per-column-family conditional bindings.
The pattern an exam answer is looking for is least privilege bound as close to the resource as the engine allows, paired with workload identity for the runtime so no JSON keys live on disk.
# Cloud SQL: bind a workload service account to a single instance
gcloud sql instances add-iam-policy-binding orders-primary \
--member="serviceAccount:orders-api@finops-prod.iam.gserviceaccount.com" \
--role="roles/cloudsql.client" \
--project=finops-prod
# AlloyDB: grant the connector + database user roles at cluster scope
gcloud alloydb clusters add-iam-policy-binding ledger-cluster \
--region=europe-west4 \
--member="serviceAccount:ledger-writer@finops-prod.iam.gserviceaccount.com" \
--role="roles/alloydb.client"
gcloud alloydb clusters add-iam-policy-binding ledger-cluster \
--region=europe-west4 \
--member="serviceAccount:ledger-writer@finops-prod.iam.gserviceaccount.com" \
--role="roles/alloydb.databaseUser"
For Spanner the picture changes because the entire access path is IAM. The right role for an application principal that reads and writes user data is roles/spanner.databaseUser, while roles/spanner.databaseReader covers analytics consumers that should never write. Fine-grained access control on Spanner extends this with role-based grants inside the database schema itself.
-- Spanner fine-grained access control
CREATE ROLE analyst_readonly;
GRANT SELECT ON TABLE Orders, OrderItems TO ROLE analyst_readonly;
GRANT SELECT(customer_id, order_id, total_amount) ON TABLE Orders TO ROLE analyst_readonly;
Binding a Google principal to the Spanner role happens through IAM with a condition that maps the principal to the database role, so the same identity can carry different in-database powers across databases without provisioning a new service account.
💡 Exam Trap: A scenario that grants
roles/cloudsql.adminto a workload "so the app can connect" is wrong twice. That role permits instance deletion and configuration changes, far beyond a connect request. The correct pair isroles/cloudsql.clientfor proxy use and either a Postgres or MySQL password user orroles/cloudsql.instanceUserfor IAM database authentication.
⚠️ Anti-Pattern: Distributing a JSON key file for the application's service account so the Auth Proxy can authenticate. Workload Identity Federation for external workloads and attached service accounts for Cloud Run, GKE, and Compute Engine remove the key file from the equation. JSON keys are a finding on every reasonable audit standard and should be retired in favor of attached identities.
Managing database users, including authentication and access
How it works
User management splits along engine lines.
Cloud SQL Postgres and Cloud SQL MySQL keep their native CREATE USER and CREATE ROLE statements for password-based logins, while IAM database authentication offers a parallel path where a Google identity authenticates against the engine using a short-lived OAuth token.
Both paths can coexist on the same instance, which is useful during a migration from a password-only baseline into an IAM-first posture.
AlloyDB follows the same dual model, with the added wrinkle that the AlloyDB built-in connection pooler must also recognize the IAM user.
-- Cloud SQL Postgres: native role for application connections
CREATE ROLE orders_app WITH LOGIN PASSWORD :'pwd' INHERIT;
GRANT CONNECT ON DATABASE orders TO orders_app;
GRANT USAGE ON SCHEMA shop TO orders_app;
GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA shop TO orders_app;
ALTER DEFAULT PRIVILEGES IN SCHEMA shop
GRANT SELECT, INSERT, UPDATE ON TABLES TO orders_app;
For IAM database authentication on Cloud SQL Postgres the engineer enables the flag at the instance level, then adds the Google principal as a database user. The login token is requested through the gcloud CLI or the client library, so the application never holds a static password.
gcloud sql instances patch orders-primary \
--database-flags=cloudsql.iam_authentication=on
gcloud sql users create orders-api@finops-prod.iam.gserviceaccount.com \
--instance=orders-primary --type=cloud_iam_service_account
# the client obtains a short-lived token from the metadata server
PGPASSWORD="$(gcloud sql generate-login-token)" \
psql "host=127.0.0.1 port=5432 sslmode=disable \
user=orders-api@finops-prod.iam dbname=orders"
Bigtable and Firestore replace the database-user concept with predefined IAM roles like roles/bigtable.user, roles/bigtable.reader, roles/datastore.user, and roles/datastore.viewer.
There is no equivalent of a CREATE USER statement; provisioning a principal happens entirely through IAM bindings, and engine-level grants do not exist.
Spanner expands on this with database roles created in SQL, but the role itself still binds to a Google identity through IAM.
Memorystore for Redis uses an AUTH password (or no password) for engine login, supplemented by IAM roles like roles/redis.admin for instance management.
📊 Limit: A Cloud SQL Postgres instance accepts up to 100 IAM database users in addition to its native Postgres users, and each IAM user login token has a one-hour lifetime. Plan rotation cadences around that window so a long-running batch job either refreshes the token in-process or uses the Cloud SQL Connector library, which refreshes transparently.
🎯 Scenario: A platform team is rotating away from password authentication on a Cloud SQL Postgres instance that backs a payments service. The application runs on GKE under a Kubernetes service account bound to a Google service account through Workload Identity. The engineer enables
cloudsql.iam_authentication=on, creates a Cloud SQL user keyed to the Google service account, grants the new user the same in-database GRANTs the old role held, and switches the connection string to omit the password. The deploy rolls forward without changing application code beyond the password retrieval call, and the password user is left in place for one release for fallback before being dropped.
Network reachability and the connection topology
IAM alone cannot deliver bytes to the engine.
A Private Service Connect endpoint or Private Service Access range still has to route the connection.
In a portfolio that mixes Cloud SQL, AlloyDB, and Spanner, the engineer often consolidates on Private Service Connect because it places a unique endpoint inside each consumer VPC and so removes the cross-VPC peering exposure that Private Service Access carries.
- Cloud SQL Auth Proxy can run as a sidecar in a pod or as a Cloud Run service.
- AlloyDB exposes a similar Auth Proxy that integrates with the same connector libraries.
- For Spanner, Bigtable, and Firestore the connection runs over Google APIs and requires either public Google API access, Private Google Access on the subnet, or a Private Service Connect endpoint for Google APIs.
Cross-region and cross-project topology adds organizational policy considerations.
A grant of roles/cloudsql.client at folder level can be combined with a deny policy that refuses bindings to public IP instances, so the platform team has a guardrail that no production application can ever connect to an instance lacking a Private Service Connect endpoint.
That posture matters more than any single IAM binding because it survives drift in individual project policies.
💡 Exam Trap: Granting
roles/cloudsql.clientwithout also enabling network reachability does not let the application connect. The proxy can authenticate the principal but it still needs a path to the instance. A scenario that adds the role and then asks why the connection fails is testing whether the candidate remembers that IAM is necessary but not sufficient; verify the Private Service Connect endpoint, the firewall rules, and the proxy configuration before assuming an IAM gap.
Choose roles/cloudsql.client + roles/cloudsql.instanceUser for any workload that connects through the Cloud SQL Auth Proxy with IAM database authentication.
Choose roles/cloudsql.client paired with a Postgres or MySQL password user when the application still relies on a native password.
Choose Spanner database roles plus IAM conditions when the same identity needs different powers across databases inside one instance.
Avoid project-wide grants for anything other than platform automation that genuinely needs the breadth. ---
