Repository navigation
VPC ACL: match all ports for a tcp/udp rule given without ports - #14364
bhouse-nexthop wants to merge 3 commits into
Conversation
A VPC network ACL rule for tcp or udp without a port range reaches the VR as the range 0:0: TcpAclRule and UdpAclRule hold their ports as ints, so they are always sent. AclRule.init_vpc() only checked that first_port was present and rendered "-m tcp --dport 0", so the rule matched port 0 only: an allow admitted nothing, and a deny blocked nothing, letting the traffic through to the rules after it. The nftables paths (routed IPv4, IPv6) already treat 0 as no ports and match all of them. Treat 0:0 as no ports on the iptables path too. A range starting at 0, such as 0:1024, is still applied as given. Fixes: apache#14363 Signed-off-by: Brad House <bhouse@nexthop.ai>
|
@vladimirpetrov @sureshanaparti could you take a look at this one? We'd like this fix to make it into the upcoming 4.22.2 release. |
Signed-off-by: Brad House <bhouse@nexthop.ai>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 4.22 #14364 +/- ##
==========================================
Coverage 18.02% 18.02%
- Complexity 16247 16288 +41
==========================================
Files 5936 5937 +1
Lines 535823 536773 +950
Branches 65612 65783 +171
==========================================
+ Hits 96572 96777 +205
- Misses 428252 428943 +691
- Partials 10999 11053 +54
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A tcp or udp rule given only port 0 (startport=0, endport unset or 0) is stored and sent to the VR as the range 0:0, the same as a rule without ports. Now that the VR treats 0:0 as all ports, such a rule would quietly apply to every port; a "deny tcp port 0" would deny all tcp. Port 0 is not a usable tcp or udp port, so refuse the range 0:0 in validateSourceStartAndEndPorts, which covers createNetworkACL, updateNetworkACLItem and importNetworkACL, and point the caller at omitting the ports. A range starting at 0, such as 0:1024, is still accepted. Rules already stored as 0:0 are not changed. Updating one now needs its ports cleared or set to a real range. The "both ports null" test relied on Mockito's default of 0 for the Integer getters, so it now stubs null explicitly. Signed-off-by: Brad House <bhouse@nexthop.ai>
|
@blueorangutan package |
|
@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✖️ suse15. SL-JID 19645 |
|
@blueorangutan test |
|
@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
Damans227
left a comment
There was a problem hiding this comment.
thanks @bhouse-nexthop, CLGTM. can you get it tested on a vpc router and post the rules you see for a tcp rule with no ports and a 0:0 rule?
|
[SF] Trillian test result (tid-17190)
|
could this be related to your changes, @bhouse-nexthop ? (looks like it could) |
|
@DaanHoogland I went through the Marvin logs for tid-17190, and I don't think this one is caused by the PR.
A re-run should tell us more if you'd like to be sure. |
|
@DaanHoogland this has your and @Damans227's approvals, and the only Trillian failure was the redundant VPC VPN test (details above; it also failed on #14310). Could it be merged for 4.22.2? I understand it's due out late this week or early next. |
Description
On a VPC virtual router, a network ACL rule for
tcporudpwith no port range matched only port 0, instead of every port.Fixes #14363
Why it breaks
0:0(NetworkACLTO.getStringPortRange()).SetNetworkAclConfigItembuilds aTcpAclRule/UdpAclRule, whose ports are plainints, so the VR always receives"first_port": 0, "last_port": 0.configure.py'sAclRule.init_vpc()only checked thatfirst_portwas present, and rendered-m tcp --dport 0.What that did:
This is the iptables path: IPv4 on VPC tiers and private gateways that are not in routed mode. The nftables paths (routed IPv4 and IPv6) already treat
0as "no ports" and match every port. So the same rule allowed all TCP on IPv6 and none on IPv4.How it is fixed
AclRule.init_vpc()treats exactly0:0as "no ports" and adds no--dport, the same as the nftables paths do for0:0.0:1024, is still applied as given.startport=0) would also be stored as0:0, and the VR can't tell it apart from one without ports. The API now refuses0:0(NetworkACLServiceImpl.validateSourceStartAndEndPorts, which covers create, update and import), and says to omit the ports to match all ports. Port 0 is not a usable tcp or udp port. A range starting at 0 is still accepted.How to reproduce the old behaviour
10.0.0.0/8, Allow. Attach the list to a tier.iptables -S ACL_INBOUND_ethX:-A ACL_INBOUND_ethX -s 10.0.0.0/8 -p tcp -m tcp --dport 0 -j ACCEPT-A ACL_INBOUND_ethX -s 10.0.0.0/8 -p tcp -j ACCEPTUpgrade note
Once routers run the updated scripts (after a management server upgrade, then recreating the router or
restartVPC livepatch=true), existing tcp/udp ACL rules without ports match every port of that protocol, as they always should have:The API now refuses port 0 alone (
0:0), so no new such rules can be created. This only affects a rule stored as0:0before this change, created through the API with port 0 alone, for example a "deny tcp port 0" anti-scan rule. It becomes a deny of all TCP on IPv4, as it already is on IPv6. Updating such a rule now requires clearing its ports or setting a real range. The UI can't create such a rule; it sends an empty port for 0. To find these rules before upgrading:The rows with
start_port = 0are the ones set to port 0 on purpose; the rows with no ports are the ones this PR is about.Types of changes
Feature/Enhancement Scale or Bug Severity
Bug Severity
How Has This Been Tested?
systemvm/test/TestCsAclPorts.py:0:0render without--dport; that test fails on the current4.22code;0:1024) are still rendered as before;allrules are unaffected.NetworkACLServiceImplTest:0:0is refused, and a range starting at 0 (0:1024) is accepted. The existing "both ports null" test now stubs null explicitly, since it was relying on Mockito's default of 0.NetworkACLServiceImplTestand the other ACL tests inserverpass.pycodestyleandpylint(as insystemvm/test/runtests.sh) report nothing new.validateSourceStartAndEndPortsreturns early when both ports are null, and the UI doesn't require ports); I haven't reproduced it on a running VR.How did you try to break this feature and the system with this change?
allrules have nofirst_portand are unaffected.0:1024, as all ports, because they testif first_port:. The iptables path applies it as given. That is an existing, separate difference.