How to Integrate Airflow and Cloud SQL Safely
Data teams run Airflow and Cloud SQL together to schedule and track database jobs. In this setup, workflow tasks read, transform, and write relational records on a timer. When you connect these two systems, you must control credentials, permissions, and network paths. A safe design keeps database passwords out of task code and limits every role. How Airflow and Cloud SQL share identities and data Airflow runs scheduled workflows that need to talk to your relational database. Each task opens a
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.
Data teams run Airflow and Cloud SQL together to schedule and track database jobs. In this setup, workflow tasks read, transform, and write relational records on a timer. When you connect these two systems, you must control credentials, permissions, and network paths. A safe design keeps database passwords out of task code and limits every role.
How Airflow and Cloud SQL share identities and data
Airflow runs scheduled workflows that need to talk to your relational database. Each task opens a network session, logs in, and runs a set of queries. Often, teams store database login details inside the scheduler metadata database or a secret store. When a task starts, the worker fetches those details and opens a database session.
In Cloud SQL for PostgreSQL, you must understand how built-in admin roles work. Because it is a managed service, customers cannot create users with true superuser attributes. A Google-managed system user holds the actual superuser privileges on the database instance. Customers cannot delete or modify these built-in system roles or users.
Instead, the default postgres admin user belongs to a special cloudsqlsuperuser role. That default user is created without a password, so you must set one first. It can create roles, create databases, and log in, plus create certain extensions. Still, it does not hold true superuser or replication attributes on the server. You should never pass this default admin account to your workflow workers.
Common failure modes in workflow database connections
The biggest risk in workflow automation is using one shared admin account everywhere. If every DAG uses the same login, any task can drop or alter tables. A bug in a simple reporting script could wipe out core customer records. Also, shared logins make database logs much harder to read during an incident. Every query looks like it came from the same generic workflow user.
Long-lived passwords stored in workflow variables create another major security gap. Engineers who can view the workflow UI or logs might see raw secrets. If an attacker steals that static password, they gain broad database reach. Also, rotating a shared password breaks multiple running pipelines at the exact same time.
End-to-End Encryption + SQL Query Filtering: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Unfiltered query results also expose sensitive fields to your workflow workers and logs. If a task pulls full customer rows, worker logs might store raw emails. A failing task often prints the row data right into the error trace. Phone numbers, card numbers, and national IDs can leak into central log storage.
Scoping database roles and network paths
Start by creating separate database users for each workflow domain or pipeline group. Grant a reporting role read access only to the specific tables it needs. Give an ingestion role write permissions only on its target staging tables. Keep the default admin role strictly for initial database setup and schema migrations.
Next, lock down the network path between your workflow workers and the database. Place both systems inside private network spaces so traffic stays off the public internet. Allow inbound traffic to the database port only from the worker subnet. Finally, make sure your tasks mask emails and card numbers in query outputs.
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
Should Airflow tasks use the default postgres user in Cloud SQL?
No, tasks should never use the default admin user or the cloudsqlsuperuser role. Create dedicated database users with permissions limited to the exact tables each task needs.
How can we tell which DAG ran a specific database query?
Assign distinct database roles to different pipelines so logs show which role ran each query. You can also tag queries with task metadata before sending them to the database.
What happens if a failed task logs raw customer records?
Failed tasks can dump sensitive fields like phone numbers or national IDs into worker logs. Applying data masking to rewrite matched fields in results prevents raw data from leaking.
Related guides
In this post