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.
$ 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:
$ jailops app allow db --from jail:web --db webThat 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:
$ 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:
$ jailops app access db $ jailops app access forge
The policy and the set, with their comments, as a reviewer reads them:
$ 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 NEWandremovethe old address. Every policy that namesset:git-clientsfollows. - The web jail is replaced. The grant names it by name, so a new jail called
webis 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-roleremoves the rule and thepg_hba.conflines, and with--drop-rolethe 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
Jail updates without cron
Replace the nightly script that upgrades every jail: automatic jail upgrades per image, with a health check, a rollback and a record of every run, what they leave alone, and how a new FreeBSD release comes in.
Read the article: Jail updates without cronJail search and shell
Ctrl+K, a few letters, Shift+Enter: find a jail by name, label or app and open its shell. Labels that filter the jail list, bash in new jails, and the jailops command next to every step.
Read the article: Jail search and shellGetting started with the JailOps CLI
Root on the host, the command line and nothing else: install JailOps, build an image, create a network and a jail, reach it by name, snapshot it, open a port and install an app.
Read the article: Getting started with the JailOps CLIJailOps on a netcup server, with IPv6 that stays up
A /64, a router pair and a FreeBSD default that drops their probes. How every jail gets its own IPv6 address on netcup, and the one sysctl that ends the random unreachable alerts.
Read the article: JailOps on a netcup server, with IPv6 that stays upOne small cloud server, many services, solid IPv6
Run your database, web tier and workers on one low-cost server, each jail with its own IPv6 address, and fix the alerts a shared /64 causes with one sysctl.
Read the article: One small cloud server, many services, solid IPv6Write your own app: memcached, from package to catalog
Turn a small FreeBSD package into a JailOps app: the definition line by line, the offline check, a local install, the five traps, and the pull request that puts it in the catalog.
Read the article: Write your own app: memcached, from package to catalogFrom catalog to running service in one command
Install nginx from the app catalog with one command, see each of its steps, and find the data, the configuration, the logs and the snapshot afterwards.
Read the article: From catalog to running service in one commandA firewall you can read
Policies, address sets and jails by name (jail:web), each with a comment, so the firewall can be reviewed by someone who did not write it.
Read the article: A firewall you can readProjects are boundaries
A project is a boundary. Another project is an external host, so only addresses cross it, written out on both sides. Why that is simpler to review, and what a project does not isolate.
Read the article: Projects are boundariesThe life of a jail
A jail starts at boot only when you declared it with --autostart. Why JailOps does it this way, how the order is decided, and how to see it with jailops boot.
Read the article: The life of a jailTab completion for jailops
Press Tab and get the names of your jails, networks and firewall policies, even on another host. How to install and turn on completion in bash, zsh and fish.
Read the article: Tab completion for jailopsTest the firewall before you trust it
Ask the firewall whether a connection would pass, and why, before you try it. Read the answer, put it in a script, and know what it cannot tell you.
Read the article: Test the firewall before you trust itSee a connection before it happens
Pick a From and a To, a protocol and a port, press Run, and see the connection flow through the firewall: what passes, what stops it, and which rule decides.
Read the article: See a connection before it happensLimit what a jail can use
Give a jail a ceiling for memory, processes, CPU, disk, firewall states and bandwidth, one command each, and know what happens when it reaches it.
Read the article: Limit what a jail can useStop every jail cleanly when the host shuts down
A host that reboots should stop its databases before it stops the disks. How JailOps stops the jails in order, and how to start them in order again.
Read the article: Stop every jail cleanly when the host shuts downOne line in pf.conf
The host's firewall stays yours. JailOps asks for one line, and everything for the jails lives below it.
Read the article: One line in pf.confWhat the host tells you by itself
A pool that reports an error, an uplink that goes down, a jail that reaches a limit: they show up in the event stream by themselves.
Read the article: What the host tells you by itselfNetworks the host controls
No bridge, no DHCP. The host hands out the addresses, gives each jail a link of its own and is the router, so jails cannot see or impersonate each other.
Read the article: Networks the host controlsVolumes: data that outlives a jail
Keep the data in a volume and the jail disposable. One volume can be attached to several jails, has its own snapshots and its own backup.
Read the article: Volumes: data that outlives a jailBack up volumes once
One copy of a volume, however many jails use it. Leave volumes out when you want to, bring them back with the jail.
Read the article: Back up volumes onceA private Docker registry
A registry of your own with users in a file: one jail, docker-registry and docker-auth, htpasswd for the passwords, the images on a volume.
Read the article: A private Docker registryNames for jails
A jail is reached by its name inside its project: db.shop.internal, or just db. Create a jail and its name is there; delete it and the name is gone.
Read the article: Names for jails
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.