Skip to content

PostgreSQL Hardening

The database container (data-master) that ships with self-hosted AIR hardens PostgreSQL every time it starts. Some protections are applied automatically; others, such as encrypting the Console-to-database connection in a 2-tier deployment and restricting which addresses can reach port 5432, require a few manual steps.

This article applies to single-tier and 2-tier self-hosted deployments that use the bundled data-master container. SaaS deployments and Consoles connected to an external database (for example, a managed cloud database) are not affected.

AreaBehavior
Application roleThe air-data user that AIR connects with is no longer a PostgreSQL superuser. The bootstrap superuser is renamed to air-admin and only accepts connections from inside the data-master container. air-data keeps its password and still owns the AIR database, so AIR_POSTGRESQL_URI, .env files, compose files, and backups need no changes.
Monitoringair-data is a member of the built-in pg_monitor role, so diagnostic queries keep working. Database disk usage and PostgreSQL log reading go through two helper functions in a dedicated pg_air_admin schema. This schema is never included in AIR backups, so backup and restore do not touch it.
Server TLSA self-signed certificate is generated at volumes/data-master/binalyze-air/data/tls/server.crt and TLS is enabled on the database server. Clients that do not request TLS continue to connect as before.
Connection logginglog_connections is enabled, so every connection to the database is recorded in the PostgreSQL log.

The behavior is the same on PostgreSQL 15 and PostgreSQL 18, including PostgreSQL 15 databases whose upgrade to PostgreSQL 18 has not been performed yet.

The role change itself runs once, on the first start of an updated data-master container. It takes a few seconds and safely resumes on the next start if it is interrupted. After that, every start checks the roles and helper functions, and transfers any objects in the AIR database that are owned by air-admin back to air-data.

Rolling back to an earlier AIR version keeps working, because the older Console connects with the same credentials.

DeploymentWhat you need to do
Existing single-tierUpdate as usual. No extra steps.
Existing 2-tierUpdate as usual, then add a few lines to the compose files to enable TLS and IP restriction.
New single-tierInstall as usual. No extra steps.
New 2-tierPass two optional variables to db.sh, then copy the database certificate to the Console Server.

The Console and the database run on the same machine and communicate over the internal Docker network, so no configuration change is needed.

  1. Update the system as described in Single-Tier Systems. The update itself comes down to:

    Terminal window
    cd /opt/binalyze-air
    docker compose pull
    docker compose up -d
  2. Confirm that the role change was applied:

    Terminal window
    docker compose logs data-master | grep "Role hardening"

    The output includes the following line:

    [Run-Postgres] Role hardening: "air-data" is no longer a superuser

Follow the steps below in order. You switch between the Database Server (/opt/binalyze-air-db) and the Console Server (/opt/binalyze-air) several times. You need the IP address of each server.

Step 1: Update the Database Server and Enable the New Settings

Section titled “Step 1: Update the Database Server and Enable the New Settings”
  1. Update the database containers:

    Terminal window
    cd /opt/binalyze-air-db
    docker compose pull
    docker compose up -d

    The role change and server TLS are now active.

  2. Open docker-compose.yml, find the data-master service, and add the following three lines under its environment: list:

    - AIR_POSTGRESQL_ALLOWED_CIDRS
    - AIR_POSTGRESQL_REQUIRE_SSL
    - AIR_POSTGRESQL_TLS_SANS

    Keep the indentation consistent with the existing entries, such as - AIR_POSTGRESQL_PASSWORD.

  3. Add the Database Server address to the certificate and allow connections only from the Console Server. Replace the placeholders with your IP addresses:

    Terminal window
    DB_SERVER_IP=<Database Server IP>
    CONSOLE_IP=<Console Server IP>
    echo "AIR_POSTGRESQL_TLS_SANS=IP:$DB_SERVER_IP" >> .env
    echo "AIR_POSTGRESQL_ALLOWED_CIDRS=$CONSOLE_IP/32" >> .env
  4. Apply the changes:

    Terminal window
    docker compose up -d

    The certificate is regenerated so that it contains the Database Server IP address.

  5. Copy the certificate to the Console Server using your preferred method. The certificate is located at:

    /opt/binalyze-air-db/volumes/data-master/binalyze-air/data/tls/server.crt

    For example, copy it to /tmp on the Console Server with scp:

    Terminal window
    sudo cat /opt/binalyze-air-db/volumes/data-master/binalyze-air/data/tls/server.crt > /tmp/air-db-ca.crt
    scp /tmp/air-db-ca.crt <user>@<Console Server IP>:/tmp/air-db-ca.crt

Step 2: Update the Console Server and Connect Over TLS

Section titled “Step 2: Update the Console Server and Connect Over TLS”
  1. Update the Console containers:

    Terminal window
    cd /opt/binalyze-air
    docker compose pull
    docker compose up -d
  2. Place the certificate in the Console configuration folder and make it readable:

    Terminal window
    sudo cp /tmp/air-db-ca.crt /opt/binalyze-air/volumes/app/binalyze-air/config/air-db-ca.crt
    sudo chmod 644 /opt/binalyze-air/volumes/app/binalyze-air/config/air-db-ca.crt
  3. Open /opt/binalyze-air/.env and append the following to the end of the AIR_POSTGRESQL_URI value:

    ?sslmode=verify-full&sslrootcert=/binalyze-air/config/air-db-ca.crt

    The line then looks like this:

    AIR_POSTGRESQL_URI=postgresql://air-data:<password>@<Database Server IP>:5432/airdb?sslmode=verify-full&sslrootcert=/binalyze-air/config/air-db-ca.crt

    The application, background jobs, and the AIR CLI (including backup and restore) all read these parameters from the URI.

  4. Apply the changes:

    Terminal window
    docker compose up -d
  5. Log in to the AIR Console and confirm that the main pages, such as Assets and Cases, load normally.

Step 3: Require TLS on the Database Server

Section titled “Step 3: Require TLS on the Database Server”
  1. Reject connections that do not use TLS:

    Terminal window
    cd /opt/binalyze-air-db
    echo "AIR_POSTGRESQL_REQUIRE_SSL=true" >> .env
    docker compose up -d
  2. Log in to the AIR Console again and confirm that it works normally.

Optionally, also restrict port 5432 at the host firewall.

Install AIR as described in the Installation Guide. The hardening is applied automatically and no extra steps are needed.

  1. On the Database Server: Set the Console Server and Database Server IP addresses, then run the database installation script:

    Terminal window
    export AIR_CONSOLE_IP=<Console Server IP>
    export AIR_DB_SERVER_IP=<Database Server IP>
    curl -fsSL https://cdn.binalyze.com/air-deploy/db.sh | sudo -E bash

    The script writes AIR_POSTGRESQL_ALLOWED_CIDRS and AIR_POSTGRESQL_TLS_SANS to /opt/binalyze-air-db/.env, so the database accepts connections only from the Console Server and the certificate contains the Database Server IP address.

  2. On the Console Server: Install the Console as described in the Installation Guide, using the commands that db.sh prints.

  3. Enable TLS for the Console connection: Follow these steps from the existing 2-tier procedure:

    1. Step 1, item 5: copy the certificate to the Console Server.
    2. Step 2, items 2 to 5: place the certificate, update AIR_POSTGRESQL_URI, apply the changes, and confirm that the Console works.
    3. Step 3: require TLS on the Database Server.

Optional: Restrict Port 5432 at the Host Firewall

Section titled “Optional: Restrict Port 5432 at the Host Firewall”

AIR_POSTGRESQL_ALLOWED_CIDRS filters connections inside PostgreSQL. Docker publishes port 5432 through its own iptables rules, which bypass ufw and firewalld, so those tools do not protect the port. To filter it at the host firewall as well, add a rule to the DOCKER-USER chain on the Database Server:

Terminal window
iptables -I DOCKER-USER -p tcp -m conntrack --ctorigdstport 5432 --ctdir ORIGINAL ! -s <Console Server IP> -j DROP

Rules added this way do not survive a reboot. Use your distribution’s mechanism for persisting iptables rules if you want to keep it.

Run docker compose logs data-master on the server that runs the database and look for these lines:

[Run-Postgres] Server TLS enabled (certificate: /binalyze-air/data/tls/server.crt)
[Run-Postgres] Role hardening: checking roles and helpers
[Run-Postgres] Role hardening: "air-data" is no longer a superuser
[Run-Postgres] Role hardening complete
[Run-Postgres] Client access: networks=..., remote TLS required=...

The Role hardening: "air-data" is no longer a superuser line appears only on the first start after the update. The Client access line appears only when AIR_POSTGRESQL_ALLOWED_CIDRS or AIR_POSTGRESQL_REQUIRE_SSL is set.

A WARNING: Role hardening ... line means the role change was skipped and the database started unchanged. It is retried on the next start. Details are written to volumes/data-master/binalyze-air/log/postgresql/role-hardening.log.

  • Custom scripts: Because air-data is no longer a superuser, custom scripts that connect as air-data to perform superuser tasks, such as pg_dumpall, no longer work. AIR backups and the AIR CLI are not affected.
  • In-container access with IP restriction: When AIR_POSTGRESQL_ALLOWED_CIDRS is set, the data-master container’s own addresses are added to the allowed list automatically. Commands run inside the container, such as docker compose exec data-master psql "$AIR_POSTGRESQL_URI", keep working.
  • IP restriction on single-tier: Single-tier deployments do not need AIR_POSTGRESQL_ALLOWED_CIDRS. If you set it anyway, include the Docker network that the Console container uses; otherwise the Console cannot reach the database.
  • Using your own certificate: To use a certificate issued by your organization instead of the self-signed one, place server.crt and server.key in the volumes/data-master/binalyze-air/data/tls/ directory, delete the tls/.generated-sans file, and restart data-master. Certificates you provide are never overwritten. Copy the issuing CA certificate to the Console Server as air-db-ca.crt.
  • Changing the certificate addresses: Changing AIR_POSTGRESQL_TLS_SANS regenerates the self-signed certificate. Copy the new server.crt to the Console Server and restart the Console containers.
  • PostgreSQL upgrades: The PostgreSQL 15 → 18 upgrade and its rollback work on a hardened database.

These variables are read from the .env file of the server that runs the database (/opt/binalyze-air-db/.env for 2-tier, /opt/binalyze-air/.env for single-tier). Each variable must also be listed under data-master → environment: in docker-compose.yml. Run docker compose up -d after changing them.

VariableDefaultEffect
AIR_POSTGRESQL_ALLOWED_CIDRSAny addressComma-separated networks allowed to connect over TCP, for example 10.0.0.7/32. Invalid entries are skipped with a warning; if no entry is valid, the default is kept.
AIR_POSTGRESQL_REQUIRE_SSLfalsetrue rejects remote connections that do not use TLS. Enable it only after the Console connects over TLS.
AIR_POSTGRESQL_TLS_SANSNot setExtra subject alternative names for the generated certificate, for example IP:10.0.0.5,DNS:db.example.com.