The Simplest Way to Make Cloud SQL and SAML Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

You pair cloud sql and saml by linking your corporate identity provider to Google Cloud. This setup lets engineers log in to databases using single sign-on instead of static passwords. Your identity provider checks the user and sends a signed SAML assertion to Google. Google then maps that user to an account that can open a database session. Teams use this workflow to manage database permissions from one central directory. When someone leaves the company, disabling their directory profile stops

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You pair cloud sql and saml by linking your corporate identity provider to Google Cloud. This setup lets engineers log in to databases using single sign-on instead of static passwords. Your identity provider checks the user and sends a signed SAML assertion to Google. Google then maps that user to an account that can open a database session. Teams use this workflow to manage database permissions from one central directory. When someone leaves the company, disabling their directory profile stops their database logins right away.

How cloud sql and saml handle logins and roles

SAML works through a trust link between your identity provider and your cloud account. A user starts a login flow and proves their identity with multi-factor checks. The identity provider builds an XML assertion that holds the user email and group names. Google reads this assertion and grants a temporary cloud session to the engineer. From there, the database checks whether that cloud identity matches a valid database user.

Inside Cloud SQL for PostgreSQL, role permissions work differently than on a self-hosted server. Because it is a managed service, customers cannot create users with true superuser attributes. Google reserves full superuser privileges for its own system account named cloudsqladmin. Customers cannot delete or modify these built-in system roles or users. Instead, you grant admins the cloudsqlsuperuser role, which holds specific high-level privileges. This role lets admins create extensions, event triggers, replication users, publications, and subscriptions. The default postgres admin user belongs to cloudsqlsuperuser and can create roles and databases. Still, that default user is created without a password, so you must set one first. It also lacks the raw superuser and replication attributes.

Common failure modes in federated database setups

Many teams connect SAML to their cloud console but still share one database password. Engineers log in with SAML to view the cloud project, then grab the postgres password. When everyone shares one admin account, your logs cannot show who ran a bad query. Another common mistake is mapping a large SAML group to the cloudsqlsuperuser role. That gives every developer the power to drop tables or alter replication rules.

Static tokens and broad network rules also create big security gaps for data teams. If a database sits on an open network path, stolen credentials work from anywhere. Even with federated logins, long-lived sessions let people run queries long after an incident ends. Moreover, database logs often miss the link between a SAML assertion and a SQL statement. Without clear query logs, security reviewers spend hours matching cloud events to database rows. Sensitive fields like emails, phone numbers, card numbers, and national IDs need extra care. Data masking rewrites matched fields in results so support staff only read safe values.

Scoping database roles and network paths

Start by breaking your SAML directory groups into small, clear job functions. Map analysts to read-only database roles that only select from specific schema views. Reserve the cloudsqlsuperuser role for a tiny group of senior database engineers. Never let apps or human users share the default postgres login in daily work.

SAML 2.0 + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Next, lock down the network path between your client machines and the database instance. Use private IP routing inside your virtual network instead of exposing public endpoints. Require every engineer to pass a fresh SAML check before starting a database session. Keep session lifetimes short so old tokens expire before an attacker can reuse them. Finally, turn on detailed query auditing so every command links back to one person.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

Can SAML give a user true PostgreSQL superuser rights in Cloud SQL?

No, customers cannot create or use accounts with true superuser attributes in Cloud SQL. The highest role you can assign is cloudsqlsuperuser, while Google owns the cloudsqladmin superuser.

Why does the default postgres user fail to log in right after setup?

Cloud SQL creates the default postgres admin user without a password at first. You must set a password for it before anyone can log in with that account.

How should we map SAML groups to database permissions?

Create separate SAML groups for readers, writers, and admins in your identity provider. Map most users to restricted roles, and keep cloudsqlsuperuser for top database admins only.

Short role checks help teams work fast. Simple rules make each review clear. Good logs keep every team safe. Scoped keys stop bad changes early.

Teams test new role rules in staging first. Clear owner lists speed up each audit. Small role scopes cut down on risk. Regular log checks catch drift right away.

The query runs. The emails stay hidden.