The Simplest Way to Make Gitlab and dbt Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

You pair gitlab and dbt to test and deploy SQL data models through version control. When a developer opens a merge request, a pipeline runs model builds and data tests. This workflow stops broken SQL from reaching your main analytics tables. Teams review code changes and check test results in one place before they merge. How gitlab and dbt share keys and run data jobs A pipeline runner starts a job whenever someone pushes code to a branch. The runner pulls your project code and starts a cont

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 gitlab and dbt to test and deploy SQL data models through version control. When a developer opens a merge request, a pipeline runs model builds and data tests.

This workflow stops broken SQL from reaching your main analytics tables. Teams review code changes and check test results in one place before they merge.

How gitlab and dbt share keys and run data jobs

A pipeline runner starts a job whenever someone pushes code to a branch. The runner pulls your project code and starts a container with the build tool installed.

To run SQL models, the runner must log in to your data warehouse. Most teams store database keys or tokens as protected variables inside the code platform.

When the job starts, the runner reads those variables and passes them to the build tool. The tool then sends compiled SQL queries to the warehouse and reads back the status.

Data rows stay inside the warehouse during the whole build process. The runner only sends SQL text and gets pass or fail logs back from the database.

Branch rules decide which keys a job can read during a run. Merge request jobs use staging keys, while main branch jobs use production keys.

Common failure modes and how to scope roles

Many teams share one strong database account across all pipeline jobs and local laptops. If that single key leaks in a build log, anyone can read or drop tables.

Broad tokens also cause trouble when a developer edits the pipeline file in a feature branch. A bad script can print secret variables or run destructive queries against production tables.

GitLab CI Security + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Unlogged queries create another blind spot for data and security teams. When every job uses the same user name, database logs cannot show who triggered a query.

You can fix this by creating separate warehouse roles for each pipeline stage. Give the pull request role permission to write only to temporary scratch schemas.

Give the main branch role permission to update production tables, and restrict keys to protected branches. Never let an unreviewed branch read production keys or write to live schemas.

You should also lock down network paths between your runners and your data warehouse. Use private runners inside your cloud network instead of shared public runners for production builds.

Set up database query tags so every SQL run records the job ID and git user. Also mask sensitive fields like emails, phone numbers, card numbers, and national IDs in staging results.

Managing local developer runs and schema cleanup

Analytics engineers also run models from their laptops while they write new SQL logic. Giving laptops static database keys creates the same risks as shared pipeline keys.

Instead, require engineers to log in with their own identity before running local builds. Map each person to a personal development schema with read access to safe source tables.

Pull request jobs also leave behind temporary tables after a branch merges. Add a cleanup job to your merge workflow to drop scratch schemas and save storage costs.

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 pipeline runners store raw data from the warehouse?

No, the runner only compiles SQL files and sends queries to the database engine. All data movement and table builds happen inside the warehouse itself.

How do we stop feature branches from changing production tables?

Mark your production database variables as protected in your project settings. Then only protected branches like main can read those keys during a pipeline run.

How do we test only changed models during a merge request?

Save the state file from your last main branch run as a job artifact. Pass that artifact to the merge request job so it builds only modified models.

The query runs. The emails stay hidden.