Repository navigation
VPC ACL: match all ports for a tcp/udp rule given without ports #14364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bhouse-nexthop
wants to merge
2
commits into
apache:4.22
Choose a base branch
from
bhouse-nexthop:fix-acl-tcp-udp-no-ports
base: 4.22
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+103
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| import unittest | ||
| from configure import CsAcl | ||
|
|
||
|
|
||
| class FakeConfig: | ||
|
|
||
| def __init__(self): | ||
| self.fw = [] | ||
| self.ipv6_acl = [] | ||
| self.nft_ipv4_acl = [] | ||
|
|
||
| def get_fw(self): | ||
| return self.fw | ||
|
|
||
| def get_ipv6_acl(self): | ||
| return self.ipv6_acl | ||
|
|
||
| def get_nft_ipv4_acl(self): | ||
| return self.nft_ipv4_acl | ||
|
|
||
| def is_vpc(self): | ||
| return True | ||
|
|
||
| def is_routed(self): | ||
| return False | ||
|
|
||
| def get_ingress_chain(self, device, ip): | ||
| return "ACL_INBOUND_%s" % device | ||
|
|
||
| def get_egress_chain(self, device, ip): | ||
| return "ACL_OUTBOUND_%s" % device | ||
|
|
||
| def get_egress_table(self): | ||
| return "mangle" | ||
|
|
||
|
|
||
| class TestCsAclPorts(unittest.TestCase): | ||
|
|
||
| def acl(self, ingress, egress=None): | ||
| config = FakeConfig() | ||
| obj = {"device": "eth3", "nic_ip": "10.1.1.1", "nic_netmask": "24", "nic_ip6_cidr": "fd00:1::/64", | ||
| "ingress_rules": ingress, "egress_rules": egress or []} | ||
| CsAcl.AclDevice(obj, config).create() | ||
| return config | ||
|
|
||
| def iptables_rules(self, ingress, egress=None): | ||
| return [fw[2] for fw in self.acl(ingress, egress).fw] | ||
|
|
||
| def test_tcp_and_udp_without_ports_match_all_ports(self): | ||
| # a tcp or udp rule without ports reaches the VR as the port range 0:0 | ||
| rules = self.iptables_rules( | ||
| [{"type": "tcp", "cidr": "10.0.0.0/8", "first_port": 0, "last_port": 0, "allowed": True}], | ||
| [{"type": "udp", "cidr": "10.0.0.0/8", "first_port": 0, "last_port": 0, "allowed": False}]) | ||
| self.assertEqual(rules, ["-A ACL_INBOUND_eth3 -p tcp -s 10.0.0.0/8 -j ACCEPT", | ||
| "-A ACL_OUTBOUND_eth3 -p udp -d 10.0.0.0/8 -j DROP"]) | ||
|
|
||
| def test_tcp_without_ports_matches_all_ports_on_ipv6_too(self): | ||
| config = self.acl([{"type": "tcp", "cidr": "10.0.0.0/8,fd00:2::/64", "first_port": 0, "last_port": 0, "allowed": True}]) | ||
| self.assertEqual([fw[2] for fw in config.fw], ["-A ACL_INBOUND_eth3 -p tcp -s 10.0.0.0/8 -j ACCEPT"]) | ||
| ipv6 = [r['rule'] for r in config.ipv6_acl if r.get('chain') == "eth3_ingress_policy" and 'rule' in r] | ||
| self.assertIn("ip6 saddr fd00:2::/64 tcp dport { 0-65535 } accept", ipv6) | ||
|
|
||
| def test_rules_without_port_fields_are_unaffected(self): | ||
| rules = self.iptables_rules([ | ||
| {"type": "icmp", "cidr": "10.0.0.0/8", "icmp_type": 8, "icmp_code": 0, "allowed": True}, | ||
| {"type": "protocol", "protocol": 47, "cidr": "10.0.0.0/8", "allowed": True}, | ||
| {"type": "all", "cidr": "10.0.0.0/8", "allowed": False}]) | ||
| self.assertEqual(rules, ["-A ACL_INBOUND_eth3 -p icmp -s 10.0.0.0/8 -m icmp --icmp-type 8/0 -j ACCEPT", | ||
| "-A ACL_INBOUND_eth3 -p 47 -s 10.0.0.0/8 -j ACCEPT", | ||
| "-A ACL_INBOUND_eth3 -p all -s 10.0.0.0/8 -j DROP"]) | ||
|
|
||
| def test_ports_and_port_ranges_are_kept(self): | ||
| rules = self.iptables_rules([ | ||
| {"type": "tcp", "cidr": "10.0.0.0/8", "first_port": 22, "last_port": 22, "allowed": True}, | ||
| {"type": "udp", "cidr": "10.0.0.0/8", "first_port": 1000, "last_port": 2000, "allowed": True}, | ||
| {"type": "tcp", "cidr": "10.0.0.0/8", "first_port": 0, "last_port": 1024, "allowed": False}]) | ||
| self.assertEqual(rules, ["-A ACL_INBOUND_eth3 -p tcp -s 10.0.0.0/8 -m tcp --dport 22 -j ACCEPT", | ||
| "-A ACL_INBOUND_eth3 -p udp -s 10.0.0.0/8 -m udp --dport 1000:2000 -j ACCEPT", | ||
| "-A ACL_INBOUND_eth3 -p tcp -s 10.0.0.0/8 -m tcp --dport 0:1024 -j DROP"]) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the api refuse a tcp or udp rule with port 0 alone now? with this a deny on port 0 quietly becomes a deny on every port