Rolling Back OpenBSD PF Changes reddit / BSD ---------------------------------------------------------------------- moviuro · 2021-06-29 13:00 I have a cronjob that runs every 15 minutes that just loads rules from a known-good `/etc/pf.conf.good` file. Even if I shoot myself in the foot, or I forget to **not use** `pfctl`, it still triggers reliably. But to each their own, if your script works for you, then it's cool! ---------------------------------------------------------------------- SaturnFive · 2021-06-29 13:37 I think it could be a good idea. I wouldn't fallback to pfctl -d and turn off the firewall, though. I would script it to copy pf.conf to a backup, edit, load the new rules, then wait for the user to end the script or \^c it. After a timeout, load the backup. I would also probably just use ksh and alias it to "pfedit" or something. A nice feature of pf is it doesn't kill existing SSH sessions that would otherwise be incompatible with the new rule set. So if you mess up but catch your error, you can revert it without being kicked off and locked out. ---------------------------------------------------------------------- techsnapp · 2021-06-29 13:49 How do you implement new changes? ---------------------------------------------------------------------- moviuro · 2021-06-29 13:52 When needed: root in tmux@remote# $EDITOR /etc/pf.conf --- root in tmux@remote# pfctl -vvvf /etc/pf.conf && do some tests When everything's done and tested, copy `/etc/pf.conf` over to `/etc/pf.conf.good` ---------------------------------------------------------------------- techsnapp · 2021-06-29 13:56 Then your cronjob would copy /etc/pf.conf.good to /etc/pf.conf every quarter hour? Does it also load the rule set with `pfctl`? ---------------------------------------------------------------------- moviuro · 2021-06-29 14:27 The cronjob is simply: `*/15 * * * * pfctl -f /etc/pf.conf.good` ---------------------------------------------------------------------- skoef · 2021-06-29 15:55 I wrote a [shell script](https://github.com/skoef/vipf) that wraps this behaviour years ago and is used in production at my employer for years. It is based on a script that did the same thing for ipfw. ---------------------------------------------------------------------- duck1024 · 2021-06-30 09:29 Have you kids never heard of [at(1)](https://man.netbsd.org/at.1)? ---------------------------------------------------------------------- quote-only-eeee · 2021-07-04 11:49 > They aren't very flexible. If you want to send the whole rollback process to the background so you can do other tasks, like testing your config, you can't really do this nicely or cleanly in a one liner, though it is possible. Couldn't you do something like this? (pfctl -f /etc/pf.conf && sleep 60 && pfctl -f /etc/pf.conf.backup) & That said, I always enjoy a good Perl script. ---------------------------------------------------------------------- Fairly_Suspect · 2021-07-11 21:02 pfctl -nf /etc/pf.conf The -n switch doesn’t actually load it and it will still give you error messages. Does nobody read the man pages anymore?