Repository navigation
Allow rules to match TCP and UDP ports - #211
JohnCampionJr wants to merge 1 commit into
Conversation
A target may end in :PORT or :FIRST-LAST. Rules with ports take precedence over rules without them, so a single port of a host can be allowed through a block of its network. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
For context: I read through the syntax discussion in #184 before opening this. Ports came up there, with forms like If you'd rather go with the |
edi-oai
left a comment
There was a problem hiding this comment.
Is there a reason to separate the port-based rules from the regular ones?
Also, we should approach the rule syntax with more thought to accommodate different use-cases in the future. For example, one might want to:
- specify a range of ports
- a protocol
- differentiate between the source or destination port
See pf.conf(5)'s for a good example for such extensibility (proto, from and to actions). There are other packet filters that allow this flexibility as well.
It would be nice if was an issue in the first place, where we would be able to discuss the shape required to support both (1) your use-case and (2) possible future ones, and only then jump into the implementation.
Sorry, I've totally missed this message. Yes, I think we should prioritize extensibility from the outset to avoid ending up with overly complex syntax. Or worse: a syntax that cannot express certain rules at all. That would be particularly unfortunate given how how many existing packet-filter implementations we can draw inspiration from. My preference goes for |
|
Thanks, happy to go the pf.conf route. Proposed subset, so we can agree the shape before I rework the parser: Examples: If you'd prefer this as a separate issue, I'll open one. |
A rule's target can now end in
:PORTor:FIRST-LAST, for example--allow=192.168.0.10/32:8443or--block="out @host:22". It matches TCP and UDP traffic with that port on the target's side: the destination for outbound traffic, the source for inbound.The use case: a VM whose private ranges are blocked but which still needs to reach one service on another host. Today the only option is to allow the whole host, which also exposes SSH and anything else listening on it.
A rule with ports takes precedence over rules without them, so one port of a host can be opened through a block of its network. Among rules with ports, the longest prefix wins and blocking wins a tie, as with the existing rules. Only the first fragment of a packet carries ports, so later fragments never match a port rule.
The same syntax works through the control channel. This picks up the "ports" item from #184.