Skip to content

Commit 84fc3ec

Browse files
[202205][caclmgrd][chassis]: Fix missing acl rules to allow internal docker traffic from fabric namespaces (#11956)
Why I did it Changes from master branch PR sonic-net/sonic-host-services#13 est_cacl_application fails on VoQ chassis Supervisor with the error: Failed: Missing expected iptables rules: set(['-A INPUT -s 240.127.1.1/32 -d 240.127.1.1/32 -j ACCEPT', '-A INPUT -s 240.127.1.3/32 -d 240.127.1.1/32 -j ACCEPT', '-A INPUT -s 240.127.1.2/32 -d 240.127.1.1/32 -j ACCEPT']) This failure is seen because acl rules to allow traffic from fabric namespaces is missing. This PR is to include fabric namespace docker mgmt ips so that acl rules to allow traffic from namespace is added for fabric namespace as well. How I did it Get list of fabric namespaces, use this list to get docker mgmt ip of fabric asic namespace as well. How to verify it Verified on voq chassis. unit-test passes
1 parent fe62175 commit 84fc3ec

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

src/sonic-host-services/scripts/caclmgrd

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,26 @@ class ControlPlaneAclManager(daemon_base.DaemonBase):
157157

158158
self.config_db_map[front_asic_namespace] = swsscommon.ConfigDBConnector(use_unix_socket_path=True, namespace=front_asic_namespace)
159159
self.config_db_map[front_asic_namespace].connect()
160-
self.iptables_cmd_ns_prefix[front_asic_namespace] = "ip netns exec " + front_asic_namespace + " "
161-
self.namespace_docker_mgmt_ip[front_asic_namespace] = self.get_namespace_mgmt_ip(self.iptables_cmd_ns_prefix[front_asic_namespace],
162-
front_asic_namespace)
163-
self.namespace_docker_mgmt_ipv6[front_asic_namespace] = self.get_namespace_mgmt_ipv6(self.iptables_cmd_ns_prefix[front_asic_namespace],
164-
front_asic_namespace)
160+
self.update_docker_mgmt_ip_acl(front_asic_namespace)
165161

166162
for back_asic_namespace in namespaces['back_ns']:
167163
self.update_thread[back_asic_namespace] = None
168164
self.lock[back_asic_namespace] = threading.Lock()
169165
self.num_changes[back_asic_namespace] = 0
170-
171-
self.iptables_cmd_ns_prefix[back_asic_namespace] = "ip netns exec " + back_asic_namespace + " "
172-
self.namespace_docker_mgmt_ip[back_asic_namespace] = self.get_namespace_mgmt_ip(self.iptables_cmd_ns_prefix[back_asic_namespace],
173-
back_asic_namespace)
174-
self.namespace_docker_mgmt_ipv6[back_asic_namespace] = self.get_namespace_mgmt_ipv6(self.iptables_cmd_ns_prefix[back_asic_namespace],
175-
back_asic_namespace)
166+
self.update_docker_mgmt_ip_acl(back_asic_namespace)
167+
168+
for fabric_asic_namespace in namespaces['fabric_ns']:
169+
self.update_thread[fabric_asic_namespace] = None
170+
self.lock[fabric_asic_namespace] = threading.Lock()
171+
self.num_changes[fabric_asic_namespace] = 0
172+
self.update_docker_mgmt_ip_acl(fabric_asic_namespace)
173+
174+
def update_docker_mgmt_ip_acl(self, namespace):
175+
self.iptables_cmd_ns_prefix[namespace] = "ip netns exec " + namespace + " "
176+
self.namespace_docker_mgmt_ip[namespace] = self.get_namespace_mgmt_ip(self.iptables_cmd_ns_prefix[namespace],
177+
namespace)
178+
self.namespace_docker_mgmt_ipv6[namespace] = self.get_namespace_mgmt_ipv6(self.iptables_cmd_ns_prefix[namespace],
179+
namespace)
176180

177181
def get_namespace_mgmt_ip(self, iptable_ns_cmd_prefix, namespace):
178182
ip_address_get_command = iptable_ns_cmd_prefix + "ip -4 -o addr show " + ("eth0" if namespace else "docker0") +\
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import sys
3+
4+
from sonic_py_common.general import load_module_from_source
5+
from unittest import TestCase, mock
6+
7+
class TestCaclmgrdNamespaceDockerIP(TestCase):
8+
"""
9+
Test caclmgrd Namespace docker management IP
10+
"""
11+
def setUp(self):
12+
test_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
13+
modules_path = os.path.dirname(test_path)
14+
scripts_path = os.path.join(modules_path, "scripts")
15+
sys.path.insert(0, modules_path)
16+
caclmgrd_path = os.path.join(scripts_path, 'caclmgrd')
17+
self.caclmgrd = load_module_from_source('caclmgrd', caclmgrd_path)
18+
self.maxDiff = None
19+
20+
def test_caclmgrd_namespace_docker_ip(self):
21+
self.caclmgrd.ControlPlaneAclManager.get_namespace_mgmt_ip = mock.MagicMock(return_value=[])
22+
self.caclmgrd.ControlPlaneAclManager.get_namespace_mgmt_ipv6 = mock.MagicMock(return_value=[])
23+
with mock.patch('sonic_py_common.multi_asic.get_all_namespaces',
24+
return_value={'front_ns': ['asic0'], 'back_ns': ['asic1'], 'fabric_ns': ['asic2']}):
25+
caclmgrd_daemon = self.caclmgrd.ControlPlaneAclManager("caclmgrd")
26+
self.assertTrue('asic0' in caclmgrd_daemon.namespace_docker_mgmt_ip)
27+
self.assertTrue('asic1' in caclmgrd_daemon.namespace_docker_mgmt_ip)
28+
self.assertTrue('asic2' in caclmgrd_daemon.namespace_docker_mgmt_ip)
29+
self.assertListEqual(caclmgrd_daemon.namespace_docker_mgmt_ip['asic0'], [])

0 commit comments

Comments
 (0)