How to write a PF firewall rule […]
Are you asking about methodology or giving you an example of such a rule? Either way, I'd say it shouldn't be hard to accomplish that task on your own:
Since Pf has notion of such filtering criteria as user
(and group
) you should be able to enforce needed policy.
man pf.conf
: "…
user
user — This rule only applies to packets of sockets owned by the specified user. For outgoing connections initiated from the firewall, this is the user that opened the connection. For incoming connections to the firewall itself, this is the user that listens on the destination port.
…"
Start with logging all traffic on loopback interface — since loopback would be used for such kind of communications. Some tutorials has set skip on lo0
rule there for granted, but obviously you'd need the opposite, throw this one out. You might make use of (self)
keyword as well — to restrict ruleset to addresses belonging to the host for sure, but this might not be strictly needed OTOH.
Keep in mind that Pf can differ significantly between its various ports-n-versions. For e. g., the one that is shipped with MacOS is vastly outdated and some features won't work contrary to what the man page says.