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. |
|
[SF] Trillian test result (tid-17218)
|
|
@sureshanaparti this has three approvals (@DaanHoogland, @weizhouapache, @Damans227), and the Trillian rerun (tid-17218) passed 149/149. Could it be merged for 4.22.2? |
@bhouse-nexthop P.S. Based on the merge agreement, one manual verification is required. |
Test report: tcp/udp ACL rules without ports, on a running VPC router@Damans227 asked for the rules a VPC router shows for a tcp rule with no ports and for a Environment
Steps and evidence
Result: pass.
Not covered
|
|
@Damans227 @nvazquez this makes a VPC tcp/udp ACL rule given without ports match all ports. It has three code approvals (DaanHoogland, @Damans227, weizhouapache) and Trillian tid-17218 passed 149/149.
|
|
thanks @bhouse-nexthop, the rules look right. a tcp rule with no ports and a stored 0:0 rule both match every port now, and port 0 alone gets refused. |
|
Thanks @Damans227. Could you post that as a review (Review changes -> Approve)? It would count as the independent test review. @nvazquez once that review is in, it has the test review on top of the three code approvals. Could you merge it then? |
|
@bhouse-nexthop my approval is already in as one of the three code reviews, and my last comment was a read of the rules you posted, not my own test |
|
@Damans227 thanks for clarifying, I misread your comment as a test. So this still needs an independent test. If anyone with a VPC router can run it, a review with the result would count. A short version of my 11-08 report is enough:
|
|
@jmsperu would you be able to test this one on a VPC router? It has three code approvals and a passing Trillian run, and only needs an independent test to merge. The steps are in my comment above (a tcp ACL rule with no ports should match every port, and a |
jmsperu
left a comment
There was a problem hiding this comment.
Test approval. Independent test on a VPC router, before and after the change.
Environment
- CloudStack 4.22.1.1 packages (the lab carries a few unrelated local patches), KVM on Ubuntu 24.04, NFS primary storage, system VM template 4.22.0.
- The PR's two source changes were applied on top:
NetworkACLServiceImplcompiled from the PR and put in the management server, and theconfigure.pyhunk put incloud-scripts.tgz. The unit tests of the PR were not run. - One VPC (
Default VPC offering) with two tiers: T1 (10.60.1.0/24) holds the server VM and has the test ACL list; T2 (10.60.2.0/24) hasdefault_allow. The client was a network namespace on the KVM host plugged into the T2 bridge, with the router as its gateway. The server VM listens on tcp 22 only, so "connection refused" on another port means the packet passed the ACL and "timed out" means it was dropped.
1. tcp rule without ports (allow from T2), plus a udp egress rule without ports
| Router rules for T1 | From T2 to the server | |
|---|---|---|
| Without the PR | -A ACL_INBOUND_eth2 -s 10.60.2.0/24 -p tcp -m tcp --dport 0 -j ACCEPT and -A ACL_OUTBOUND_eth2 -p udp -m udp --dport 0 -j ACCEPT |
tcp 22, 80, 8080, 5000 all timed out |
| With the PR | -A ACL_INBOUND_eth2 -s 10.60.2.0/24 -p tcp -j ACCEPT and -A ACL_OUTBOUND_eth2 -p udp -j ACCEPT |
tcp 22 connected; 80, 8080, 5000 refused by the VM (so they passed the ACL) |
The same router was used for both rows. It picked up the new script through restartVPC cleanup=false livepatch=true, with no router recreate.
2. Port 0 alone
- Without the PR,
createNetworkACL protocol=tcp startport=0 endport=0was accepted and stored as0:0. - With the PR, all of these are refused with
(HTTP 431, error code 4350) Port 0 alone is not a valid port range; omit start port and end port to match all ports: create tcp0:0, create udp0:0, create tcp withstartport=0only, andupdateNetworkACLItem startport=0 endport=0on an existing rule. startport=0 endport=1024is still accepted.
3. A rule stored as 0:0 before the change
The 0:0 rule created in step 2 without the PR was left in place. After restartVPC cleanup=false livepatch=true with the PR it rendered as -A ACL_INBOUND_eth2 -s 10.60.2.0/24 -p tcp -j ACCEPT, the same as a rule without ports.
4. Deny without ports
With the PR, a tcp deny without ports (number 5) followed by a protocol all allow (number 40):
-A ACL_INBOUND_eth2 -s 10.60.2.0/24 -p tcp -j DROP
-A ACL_INBOUND_eth2 -s 10.60.2.0/24 -j ACCEPT
-A ACL_INBOUND_eth2 -j DROP
tcp 22, 80, 8080 and 5000 from T2 timed out, while ping from T2 got replies (2 of 2).
Not tested: udp traffic itself (only the rendered rule), IPv6, routed mode (nftables), private gateways, redundant VPC routers, and ACL import.
|
Thanks @jmsperu, that's a thorough test, and the before/after router rules show exactly what the change is meant to do. With your test approval this now has the independent test it was missing, alongside the three code approvals, and CI is green. |
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.