How to Integrate GitLab CI and Azure Postgres Safely

Published
Length
3 min read

Luis Felipe Dias

All posts

Integrating gitlab ci and azure postgres lets your team automate database changes during app builds. Your build jobs log in to the database to run schema updates and tests. This workflow keeps database changes in sync with your code. Still, automated runners need strict limits so a bad script cannot drop production tables. You must control how runners log in and what actions they can perform. How gitlab ci and azure postgres handle logins and data flow Data flows from your code runner to you

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.

Integrating gitlab ci and azure postgres lets your team automate database changes during app builds. Your build jobs log in to the database to run schema updates and tests.

This workflow keeps database changes in sync with your code. Still, automated runners need strict limits so a bad script cannot drop production tables. You must control how runners log in and what actions they can perform.

How gitlab ci and azure postgres handle logins and data flow

Data flows from your code runner to your cloud database over a secure network link. When a pipeline starts, the runner pulls credentials or tokens from its job variables. The runner then opens a session to the database server over the network.

Once inside, the database checks the role tied to that login. In PostgreSQL, you can set up group roles to manage rights for many users. You then grant individual runner accounts membership in the right group role.

Different jobs need different rights. A test job might only need to read data from a few tables. In PostgreSQL, the SELECT right lets a role read from whole tables or specific columns. This right also allows COPY TO exports, so you must grant it with care.

A schema update job needs higher rights to change tables, views, or functions. You should split these duties into separate roles for read jobs and write jobs. That way, a simple status check never holds the keys to alter your schema.

Common failure modes and how to scope database roles

Many teams make the mistake of sharing one admin login across all build pipelines. If a runner leaks that password in a build log, anyone can read it. Another common issue is leaving default database rights open to every account.

GitLab CI Security + Azure RBAC: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

In PostgreSQL, the special role name PUBLIC grants rights to every role on the system. By default, PUBLIC gets CONNECT and TEMPORARY rights on databases. It also gets EXECUTE rights on functions and procedures. The object owner can revoke these default rights to lock down the system.

Older database setups carry another hidden risk in the default schema. In PostgreSQL 15 and later, regular users cannot create objects in the public schema. In earlier versions or upgraded databases, an admin must revoke CREATE on public from PUBLIC. Doing this stops a test runner from creating rogue tables during a build.

Unlogged queries are another huge blind spot for engineering teams. When five pipelines share one database user, the server logs show one account name. You cannot tell which code commit or developer triggered a slow or broken query. Giving each pipeline stage its own scoped role fixes this tracking gap.

Protecting sensitive data during automated pipeline runs

Build jobs and migration checks often touch tables that hold private user data. You do not want raw emails, phone numbers, or card numbers in build logs. You can limit risk by granting SELECT rights only on safe columns. The runner can check table row counts without reading private national IDs.

Network rules also play a big part in keeping your database safe. Public cloud runners use wide IP ranges that change all the time. Opening your database firewall to the whole internet invites brute-force attacks. Instead, run your jobs on private runners inside your own cloud network. This setup keeps all database traffic off the public internet and inside private subnets.

Run guardrails and masking on the Postgres connection

Role grants and firewall rules are needed setup. Setup alone cannot check single SQL statements or mask sensitive rows in a response. By design, hoop.dev is an open-source proxy that sits beside Postgres, RDS, or Aurora as a sidecar for your Postgres. Clients and agent tools keep their credentials and point their connection string at the listener.

On each query, hoop.dev guardrails refuse disallowed drops, deletes, or table reads before they run. Next, hoop.dev data masking rewrites sensitive fields in returned rows that match your rules. Furthermore, hoop.dev holds SOC 2 Type II and logs every statement and verdict per resource. Check out the project on GitHub.

Frequently asked questions

Why should we avoid using one database account for all GitLab CI jobs?

A single shared account makes it impossible to track which pipeline ran a bad query. It also gives simple read jobs the power to delete data if a script fails.

How do we stop a CI runner from creating tables in the public schema?

PostgreSQL 15 and newer versions block this by default. On older or upgraded databases, an admin must revoke the CREATE right on the public schema from PUBLIC.

Can we limit a pipeline role to read only certain columns in a table?

Yes, PostgreSQL lets you grant the SELECT right on specific columns of a table or view. This keeps the runner from reading columns with emails or card numbers.

The query runs. The emails stay hidden.