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.
What Changes Automatically
Section titled “What Changes Automatically”| Area | Behavior |
|---|---|
| Application role | The 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. |
| Monitoring | air-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 TLS | A 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 logging | log_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.
Choose Your Scenario
Section titled “Choose Your Scenario”| Deployment | What you need to do |
|---|---|
| Existing single-tier | Update as usual. No extra steps. |
| Existing 2-tier | Update as usual, then add a few lines to the compose files to enable TLS and IP restriction. |
| New single-tier | Install as usual. No extra steps. |
| New 2-tier | Pass two optional variables to db.sh, then copy the database certificate to the Console Server. |
Existing Single-Tier Deployment
Section titled “Existing Single-Tier Deployment”The Console and the database run on the same machine and communicate over the internal Docker network, so no configuration change is needed.
-
Update the system as described in Single-Tier Systems. The update itself comes down to:
Terminal window cd /opt/binalyze-airdocker compose pulldocker compose up -d -
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
Existing 2-Tier Deployment
Section titled “Existing 2-Tier Deployment”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”-
Update the database containers:
Terminal window cd /opt/binalyze-air-dbdocker compose pulldocker compose up -dThe role change and server TLS are now active.
-
Open
docker-compose.yml, find thedata-masterservice, and add the following three lines under itsenvironment:list:- AIR_POSTGRESQL_ALLOWED_CIDRS- AIR_POSTGRESQL_REQUIRE_SSL- AIR_POSTGRESQL_TLS_SANSKeep the indentation consistent with the existing entries, such as
- AIR_POSTGRESQL_PASSWORD. -
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" >> .envecho "AIR_POSTGRESQL_ALLOWED_CIDRS=$CONSOLE_IP/32" >> .env -
Apply the changes:
Terminal window docker compose up -dThe certificate is regenerated so that it contains the Database Server IP address.
-
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.crtFor example, copy it to
/tmpon the Console Server withscp:Terminal window sudo cat /opt/binalyze-air-db/volumes/data-master/binalyze-air/data/tls/server.crt > /tmp/air-db-ca.crtscp /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”-
Update the Console containers:
Terminal window cd /opt/binalyze-airdocker compose pulldocker compose up -d -
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.crtsudo chmod 644 /opt/binalyze-air/volumes/app/binalyze-air/config/air-db-ca.crt -
Open
/opt/binalyze-air/.envand append the following to the end of theAIR_POSTGRESQL_URIvalue:?sslmode=verify-full&sslrootcert=/binalyze-air/config/air-db-ca.crtThe 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.crtThe application, background jobs, and the AIR CLI (including backup and restore) all read these parameters from the URI.
-
Apply the changes:
Terminal window docker compose up -d -
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”-
Reject connections that do not use TLS:
Terminal window cd /opt/binalyze-air-dbecho "AIR_POSTGRESQL_REQUIRE_SSL=true" >> .envdocker compose up -d -
Log in to the AIR Console again and confirm that it works normally.
Optionally, also restrict port 5432 at the host firewall.
New Single-Tier Deployment
Section titled “New Single-Tier Deployment”Install AIR as described in the Installation Guide. The hardening is applied automatically and no extra steps are needed.
New 2-Tier Deployment
Section titled “New 2-Tier Deployment”-
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 bashThe script writes
AIR_POSTGRESQL_ALLOWED_CIDRSandAIR_POSTGRESQL_TLS_SANSto/opt/binalyze-air-db/.env, so the database accepts connections only from the Console Server and the certificate contains the Database Server IP address. -
On the Console Server: Install the Console as described in the Installation Guide, using the commands that
db.shprints. -
Enable TLS for the Console connection: Follow these steps from the existing 2-tier procedure:
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:
iptables -I DOCKER-USER -p tcp -m conntrack --ctorigdstport 5432 --ctdir ORIGINAL ! -s <Console Server IP> -j DROPRules added this way do not survive a reboot. Use your distribution’s mechanism for persisting iptables rules if you want to keep it.
Verifying the Hardening
Section titled “Verifying the Hardening”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.
Things to Know
Section titled “Things to Know”- Custom scripts: Because
air-datais no longer a superuser, custom scripts that connect asair-datato perform superuser tasks, such aspg_dumpall, no longer work. AIR backups and the AIR CLI are not affected. - In-container access with IP restriction: When
AIR_POSTGRESQL_ALLOWED_CIDRSis set, thedata-mastercontainer’s own addresses are added to the allowed list automatically. Commands run inside the container, such asdocker 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.crtandserver.keyin thevolumes/data-master/binalyze-air/data/tls/directory, delete thetls/.generated-sansfile, and restartdata-master. Certificates you provide are never overwritten. Copy the issuing CA certificate to the Console Server asair-db-ca.crt. - Changing the certificate addresses: Changing
AIR_POSTGRESQL_TLS_SANSregenerates the self-signed certificate. Copy the newserver.crtto the Console Server and restart the Console containers. - PostgreSQL upgrades: The PostgreSQL 15 → 18 upgrade and its rollback work on a hardened database.
Configuration Reference
Section titled “Configuration Reference”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.
| Variable | Default | Effect |
|---|---|---|
AIR_POSTGRESQL_ALLOWED_CIDRS | Any address | Comma-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_SSL | false | true rejects remote connections that do not use TLS. Enable it only after the Console connects over TLS. |
AIR_POSTGRESQL_TLS_SANS | Not set | Extra subject alternative names for the generated certificate, for example IP:10.0.0.5,DNS:db.example.com. |