The Simplest Way to Make Buildkite and Cloud SQL Work Like They Should
Running buildkite and cloud sql together lets your team run schema updates and tests from self-hosted runners. Your build agents log in to your database to run SQL scripts during deployments. Teams use this setup to keep code changes and database changes in sync. A clear login flow prevents stolen keys and accidental data loss. It also helps your team track every single query back to a specific build job. How buildkite and cloud sql share roles and data Buildkite runs jobs on agents that liv
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.
Running buildkite and cloud sql together lets your team run schema updates and tests from self-hosted runners. Your build agents log in to your database to run SQL scripts during deployments.
Teams use this setup to keep code changes and database changes in sync. A clear login flow prevents stolen keys and accidental data loss. It also helps your team track every single query back to a specific build job.
How buildkite and cloud sql share roles and data
Buildkite runs jobs on agents that live inside your own cloud network. Those agents need a network route and a valid login to reach your database. When a pipeline starts, the agent pulls code and runs migration scripts against the database.
Cloud SQL for PostgreSQL is a managed service with strict role limits. Customers cannot create or use database accounts with full superuser attributes. A Google-managed system user named cloudsqladmin holds the actual superuser privileges on the database. Customers cannot delete or change these system roles or users.
Instead, you create users with the cloudsqlsuperuser role for admin tasks. This role has some high-level rights, like creating extensions that need superuser permissions. It can also create event triggers, replication users, and replication publications and subscriptions. The default admin user is named postgres and belongs to this cloudsqlsuperuser group.
That default postgres user has rights to create roles, create databases, and log in. It does not have full superuser or replication attributes. Google creates the postgres user without a password, so you must set one before logging in. Your build agents should use a narrower custom role unless they add extensions or triggers.
Common failure modes and how to scope permissions
Many teams store the default postgres password in a shared pipeline secret. Every build agent then uses that same admin account for all database work. If a bad script runs in a test job, it can drop tables across databases. You also lose track of which pipeline or developer ran a harmful query.
End-to-End Encryption + SQL Query Filtering: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Broad network rules create another big risk for your database instances. Some teams open database ports to wide IP ranges so dynamic agents can reach them. This exposes your database login screen to machines that do not run database jobs. You should limit network paths so only specific build agent subnets can reach the database.
A safer setup gives each pipeline its own database user with small permissions. Schema migration jobs get rights to change tables in one target database only. Test jobs get read and write rights on temporary data without schema change powers. Reporting or check jobs get read-only roles so they cannot alter any records.
Auditing pipeline queries and protecting sensitive fields
Unlogged queries make it hard to pass security checks or fix broken deployments. When five pipelines share one login, the database log shows one user for everything. Giving each workflow a distinct role makes your audit logs clear and useful. You can see which build ran a slow command or changed a table.
Test and staging pipelines often read from databases that hold real customer records. If a build log prints query results, sensitive details might leak into your CI screen. Data masking rewrites matched fields like emails, phone numbers, card numbers, or national IDs in results. This keeps raw personal data out of build logs while scripts still run.
Check database and API queries on the wire
Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.
Frequently asked questions
Can a Buildkite agent use a full PostgreSQL superuser on Cloud SQL?
No, customers cannot create or use accounts with full superuser attributes on Cloud SQL. For admin tasks like adding extensions, give the agent user the cloudsqlsuperuser role instead.
Should we use the default postgres user for our build pipelines?
Avoid using the default postgres user for normal build jobs. Create separate database users with limited table rights for each pipeline to reduce risk.
How do we stop build logs from leaking customer data during tests?
Scope test roles to least privilege and apply data masking to your query results. Masking rewrites emails, phone numbers, and card numbers before the agent prints the output.
Related guides
In this post