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

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair cloud sql and databricks ml to train machine learning models on operational database rows. Cloud SQL stores live app transactions, while Databricks ML runs model training and scoring jobs. This setup lets data scientists pull fresh records without waiting for slow batch exports. Yet direct database links from compute clusters often create security and load problems. How cloud sql and databricks ml share data and permissions In a standard setup, a Databricks cluster opens a network

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.

Teams pair cloud sql and databricks ml to train machine learning models on operational database rows. Cloud SQL stores live app transactions, while Databricks ML runs model training and scoring jobs.

This setup lets data scientists pull fresh records without waiting for slow batch exports. Yet direct database links from compute clusters often create security and load problems.

How cloud sql and databricks ml share data and permissions

In a standard setup, a Databricks cluster opens a network path to the database instance. The cluster uses a database user account to log in and read tables.

Cloud SQL for PostgreSQL is a managed service with strict role rules. 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 modify these built-in system roles or users.

The default admin user named postgres belongs to the cloudsqlsuperuser role. This default user is created without a password, so you must set one before logging in.

The postgres user can create roles, create databases, and log in. Still, it does not have the superuser or replication attributes.

The cloudsqlsuperuser role grants some high-level privileges for admin tasks. It lets users create extensions, event triggers, replication users, and replication publications and subscriptions.

Databricks ML jobs do not need the postgres account or the cloudsqlsuperuser role. You should create a separate database user with read-only permissions on specific feature tables.

Common failure modes and how to scope roles

Many teams put a single admin password into a shared notebook secret store. Every notebook user and scheduled job then logs in with that same database account.

When a bad query locks a table, database logs only show the shared account name. You cannot tell which data scientist or model training run caused the problem.

End-to-End Encryption + SQL Query Filtering: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Broad accounts also risk exposing raw personal data during feature engineering. Training tables often contain sensitive columns like emails, phone numbers, card numbers, or national IDs.

Masking rules can rewrite matched fields in results before the notebook processes the rows. This keeps raw emails and card numbers out of model artifacts and cluster logs.

To fix role creep, give each workload a dedicated database user with narrow table grants. Revoke write permissions so a broken script cannot change or drop live app records.

Managing network paths and database load

Machine learning clusters read large batches of rows at once. Heavy parallel reads from worker nodes can max out CPU and memory on a transactional database.

When possible, point training clusters at a read replica instead of the primary database instance. A replica isolates heavy analytical scans from customer-facing app writes.

Keep network paths between the compute workspace and the database on private IP ranges. Avoid opening public database endpoints to broad internet IP blocks.

Rotate database keys on a regular schedule and remove unused accounts right away. Clear ownership of every database login keeps audits simple and protects production data.

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 beside the service as an open-source proxy, a sidecar for your database or API.

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 review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Should Databricks ML jobs use the cloudsqlsuperuser role?

No, machine learning workloads only need to read specific feature tables or write back predictions. Create a dedicated PostgreSQL role with select privileges on just the required tables.

How can we stop model training queries from slowing down live apps?

Route heavy read queries from your compute clusters to a Cloud SQL read replica. This keeps large table scans off the primary database that serves live app traffic.

How do we handle sensitive fields like emails or card numbers in training data?

Limit column grants or apply data masking so queries rewrite matched fields in results. This prevents raw phone numbers, national IDs, and card numbers from landing in notebooks.

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.