Articles

PostgreSQL and git, closed except for who needs them

A worked example of the JailOps firewall: a PostgreSQL jail that only the web jail may reach, a git server for the office and the build jail, with address sets, comments and jails by name, and how to check the result.

Closed to begin with

Nothing gets in.

The example: a project with a web jail called web, a PostgreSQL jail db and a git server forge, the last two installed from the catalog. An app from the catalog is closed after the installation: its policy app-JAIL denies every inbound connection, from the network, from other jails and from the host.

install the two apps
$ jailops app install postgresql db
$ jailops app install forgejo forge

Both jails run. Nothing but the jails themselves can connect to them yet. From catalog to running service shows what an installation does.

The web jail may reach PostgreSQL

One command, three effects.

The source of a grant is the web jail, by name:

let the web jail in
$ jailops app allow db --from jail:web --db web

That one command does three things. It adds a rule to the managed policy app-db that lets jail:web in on the PostgreSQL port. It makes a role and a database named web inside the jail. And it adds the lines for the web jail's addresses to a managed block of pg_hba.conf, with scram-sha-256. The password is shown once, as a connection string, and is not stored anywhere JailOps can show it again.

--dry-run shows the rule, the pg_hba.conf lines and the SQL without the password, and changes nothing.

The office and the build jail may reach git

An address set with reasons.

The git server is for the people in the office and for the jail that builds. A set holds both, and every entry says why it is there:

the set, and the grant
$ jailops firewall address-set create git-clients --comment "who may reach the git server"
$ jailops firewall address-set add git-clients 192.0.2.0/24 --comment "the office, IPv4"
$ jailops firewall address-set add git-clients 2001:db8:a::/48 --comment "the office, IPv6"
$ jailops firewall address-set add git-clients jail:build --comment "the jail that builds and pushes tags"
$ jailops app allow forge --from set:git-clients

The rule in app-forge says from set:git-clients, so it follows the set: add an entry to the set and the rule admits it at the next reconcile pass, within seconds, without touching the rule. The members that are jails are read at every render, so a rebuilt build jail with a new address is still let in.

Checking it

Read what is in force.

Who may connect to an app, with who made each grant and when:

who may connect
$ jailops app access db
$ jailops app access forge

The policy and the set, with their comments, as a reviewer reads them:

the policy and the set
$ jailops firewall policy show app-forge
$ jailops firewall address-set show git-clients

The same explanations are in the PF anchor on the host (pfctl -a jailops/PROJECT/forge -sr shows the rules).

Then try it: a connection from the web jail to the database port answers, one from the build jail to the database does not, and the other way round for git.

When something changes

Edit the list, not the rules.

  • The office moves. jailops firewall address-set add git-clients NEW and remove the old address. Every policy that names set:git-clients follows.
  • The web jail is replaced. The grant names it by name, so a new jail called web is let in. A jail that a rule names cannot be deleted or renamed while the rule exists, so the reference is never left pointing at nothing.
  • Someone should lose access. jailops app deny db --from jail:web --drop-role removes the rule and the pg_hba.conf lines, and with --drop-role the role.

A source in another project is an address or a prefix, or an address set that holds them: another project is treated like an external host, and its operators allow the app's addresses out in a policy of their own. Things that talk to each other as one system belong in the same project.

The fuller picture of the firewall is in A firewall you can read, and the access grants of apps in App access.

More articles

Try it on one server.

Try the console from the screenshots, install on a clean FreeBSD 15.1 machine, or add JailOps to a host you already run.