How to Configure Cloud SQL Column Level Security
You set up cloud sql column level security by revoking table rights and granting role rights on specific columns. You can also create views that expose only safe columns to each database role. Most engineering teams start by giving developers broad read roles across whole tables. When roles are too broad, a simple query can return emails, phone numbers, card numbers, or national IDs. How cloud sql column level security works In Cloud SQL for PostgreSQL, the database engine checks permissions
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 set up cloud sql column level security by revoking table rights and granting role rights on specific columns. You can also create views that expose only safe columns to each database role. Most engineering teams start by giving developers broad read roles across whole tables. When roles are too broad, a simple query can return emails, phone numbers, card numbers, or national IDs.
How cloud sql column level security works
In Cloud SQL for PostgreSQL, the database engine checks permissions at the table and column level. Customers cannot create or use accounts with full superuser attributes in this managed service. Instead, a Google system account holds the top privileges, and admins use a custom admin role. This built-in admin role can create new roles, databases, extensions, and event triggers.
To lock down columns, an admin first removes the default read grant from the target table. Next, the admin grants read or write rights on safe columns to a restricted role. If a user runs a query that asks for a blocked column, the database rejects the whole statement. The user must list only the allowed columns in every query they run.
Teams also use restricted views to avoid breaking queries that select all columns. An admin creates a view that leaves out emails, phone numbers, or national IDs. Then the admin grants read rights on that view to analysts or support staff. The base table stays locked down, while the view serves safe rows to the team.
Why native roles are hard to maintain
Native column grants work well when your schema stays small and static. Still, they create heavy toil as your app grows and schemas change each week. Every new migration requires an admin to update grants or rebuild views across many roles. If an engineer adds a column and forgets a grant rule, apps or reports break right away.
Also, native column grants force an all-or-nothing choice on each query in flight. If an engineer runs a quick select-all query to debug a row, the database blocks the whole query. To avoid these constant errors, teams often fall back to shared admin roles during incidents. Once someone logs in with a broad role, native rules no longer filter sensitive fields in results.
Column-Level Encryption + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Where native column grants fall short in practice
Database roles decide who can log in and which objects they can touch at rest. They do not inspect or adapt what individual queries do in flight during a live session. If a user has read rights on a column for one task, they keep that right for every query.
A role cannot rewrite matched fields in results to hide card numbers while still returning the rest of the row. Teams need a way to let engineers run standard queries while keeping sensitive fields safe. They also need clear logs of every query and a way to approve risky statements before they run.
Add runtime guardrails and masking beside your databases and APIs
Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits inline in the protocol beside the service as an open-source proxy, a sidecar for your database or API. On every production query an agent or human runs, hoop.dev decides whether to pass, mask, block, or escalate it for review.
Before a query runs, hoop.dev guardrails check the statement against your rules, an AI Analyzer you configure can score intent or hold risky calls for human approval, and hoop.dev data masking rewrites sensitive fields in responses in memory. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Can I use a full Postgres superuser to set up column rules in Cloud SQL?
No, Cloud SQL for PostgreSQL is a managed service and does not give customers full superuser accounts. You use the default admin account or a role with Cloud SQL admin privileges to manage roles and grants.
What happens when a user queries a table with restricted columns?
If the user selects a restricted column or runs a select-all query, Postgres returns a permission error. The user must specify only the exact columns their role is allowed to read.
Do database views replace the need for column grants?
Views help users run queries without hitting permission errors on hidden columns, but they require extra upkeep. You must update your views every time you add or change columns on the base table.
Related guides
In this post