How to Integrate GitHub Actions and Azure Postgres Safely

Published
Length
3 min read

Luis Felipe Dias

All posts

Integrating github actions and azure postgres lets teams automate database migrations and data checks. A runner starts a job, logs in to the database, and runs SQL tasks. Teams use this setup to test schema changes and run regular maintenance jobs. Still, automated jobs need strict boundaries so one bad script cannot ruin production data. How github actions and azure postgres work together A workflow starts when a developer pushes code or a timer triggers a job. The runner picks up the task 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.

Integrating github actions and azure postgres lets teams automate database migrations and data checks. A runner starts a job, logs in to the database, and runs SQL tasks. Teams use this setup to test schema changes and run regular maintenance jobs. Still, automated jobs need strict boundaries so one bad script cannot ruin production data.

How github actions and azure postgres work together

A workflow starts when a developer pushes code or a timer triggers a job. The runner picks up the task and prepares to talk to the cloud database. First, the job must prove its identity to the cloud platform and the database. Many teams store a static database password inside the code platform's secret store. A better pattern uses short-lived cloud tokens tied to the specific code repo.

Once the runner logs in, the database checks the permissions for that database role. In PostgreSQL, you can set up group roles to manage rules for many users. You then grant your runner role membership in the right group role. This keeps permission management clean as you add more automated jobs over time.

Data then flows between the database and the temporary runner host. If a job only checks data quality, it only needs read rules. The SELECT rule allows reading from a whole table or just specific columns. It also allows copying data out of the table. Scoping SELECT to safe columns helps keep sensitive fields away from build logs.

Common failure modes in automated database workflows

The biggest risk in automated workflows is a shared service account with broad powers. Teams often use one admin login for every pipeline across all repos. If one test workflow leaks that secret, an attacker gains full database control. Also, shared accounts make it hard to see which job ran a bad query.

Default database settings can also give automated runners too much power by mistake. The special role name PUBLIC grants a privilege to every role on the system. By default, PUBLIC gets CONNECT and TEMPORARY on databases, plus EXECUTE on functions. The object owner can revoke these default permissions to lock down the database. In PostgreSQL 15 and later, users cannot create objects in the public schema by default. Older or upgraded databases still need an admin to revoke CREATE from PUBLIC.

GitHub Actions Security + Azure RBAC: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Network access creates another hard problem for cloud runners. Hosted runners use wide IP ranges that change often. Opening your database firewall to all cloud runners exposes the port to strangers. Instead, teams should use private runners inside a virtual network with strict firewall rules.

Scoping database roles and protecting sensitive fields

Every workflow should use a database role built only for its exact task. Schema migration jobs need rights to alter tables, while check jobs only need read access. Separating these roles stops a simple check script from dropping a table. You should also remove default PUBLIC access so new roles start with zero rights.

Even read-only jobs can leak private data into build logs if queries fail. When a runner prints query results, fields like emails or phone numbers might appear. Data masking rewrites matched fields like card numbers or national IDs in query results. This ensures automated checks run safely without writing raw personal data into job logs.

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

How should we scope PostgreSQL permissions for read-only CI jobs?

Grant the SELECT privilege only on the specific tables and columns the job needs. Also revoke default PUBLIC access on functions and databases that the job does not use.

Why are shared database service accounts risky in GitHub Actions?

Shared accounts give every workflow the same high level of database access. They also hide which specific repo or job trigger ran a harmful SQL command.

How can we stop older PostgreSQL databases from letting CI roles create tables?

Databases upgraded from before PostgreSQL 15 often allow anyone to use the public schema. An admin must revoke the CREATE privilege on the public schema from the PUBLIC role.

The query runs. The emails stay hidden.