diff --git a/build_debian.sh b/build_debian.sh index 01dca9a03aca..ab24d269bb83 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -232,6 +232,8 @@ sudo cp files/sshd/host-ssh-keygen.sh $FILESYSTEM_ROOT/usr/local/bin/ sudo cp -f files/sshd/sshd.service $FILESYSTEM_ROOT/lib/systemd/system/ssh.service ## Config sshd sudo augtool --autosave "set /files/etc/ssh/sshd_config/UseDNS no" -r $FILESYSTEM_ROOT +sudo sed -i 's/^ListenAddress ::/#ListenAddress ::/' $FILESYSTEM_ROOT/etc/ssh/sshd_config +sudo sed -i 's/^#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' $FILESYSTEM_ROOT/etc/ssh/sshd_config ## Config monit sudo sed -i ' diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index bf603d249d95..f861543e98c8 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -162,6 +162,12 @@ sudo cp $IMAGE_CONFIGS/asn/deployment_id_asn_map.yml $FILESYSTEM_ROOT/etc/sonic/ # Copy sudoers configuration file sudo cp $IMAGE_CONFIGS/sudoers/sudoers $FILESYSTEM_ROOT/etc/ +# Copy control plane ACL management daemon files +sudo cp $IMAGE_CONFIGS/caclmgrd/caclmgrd.service $FILESYSTEM_ROOT/etc/systemd/system/ +sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable caclmgrd.service +sudo cp $IMAGE_CONFIGS/caclmgrd/caclmgrd-start.sh $FILESYSTEM_ROOT/usr/bin/ +sudo cp $IMAGE_CONFIGS/caclmgrd/caclmgrd $FILESYSTEM_ROOT/usr/bin/ + ## Install package without starting service ## ref: https://wiki.debian.org/chroot sudo tee -a $FILESYSTEM_ROOT/usr/sbin/policy-rc.d > /dev/null < 0: + rule_cmd += " --tcp-flags " + + if tcp_flags & 0x01: + rule_cmd += "FIN," + if tcp_flags & 0x02: + rule_cmd += "SYN," + if tcp_flags & 0x04: + rule_cmd += "RST," + if tcp_flags & 0x08: + rule_cmd += "PSH," + if tcp_flags & 0x10: + rule_cmd += "ACK," + if tcp_flags & 0x20: + rule_cmd += "URG," + if tcp_flags & 0x40: + rule_cmd += "ECE," + if tcp_flags & 0x80: + rule_cmd += "CWR," + + # Delete the trailing comma + rule_cmd = rule_cmd[:-1] + + # Append the packet action as the jump target + rule_cmd += " -j {}".format(rule_props["PACKET_ACTION"]) + + iptables_cmds.append(rule_cmd) + + return iptables_cmds + + def update_control_plane_acls(self): + """ + Convenience wrapper which retrieves current ACL tables and rules from + Config DB, translates control plane ACLs into a list of iptables + commands and runs them. + """ + iptables_cmds = self.get_acl_rules_and_translate_to_iptables_commands() + + log_info("Issuing the following iptables commands:") + for cmd in iptables_cmds: + log_info(" " + cmd) + + self.run_commands(iptables_cmds) + + def notification_handler(self, key, data): + log_info("ACL configuration changed. Updating iptables rules for control plane ACLs...") + self.update_control_plane_acls() + + def run(self): + # Unconditionally update control plane ACLs once at start + self.update_control_plane_acls() + + # Subscribe to notifications when ACL tables or rules change + self.config_db.subscribe(self.ACL_TABLE, + lambda table, key, data: self.notification_handler(key, data)) + self.config_db.subscribe(self.ACL_RULE, + lambda table, key, data: self.notification_handler(key, data)) + + # Indefinitely listen for Config DB notifications + self.config_db.listen() + + +# ============================= Functions ============================= + +def main(): + log_info("Starting up...") + + if not os.geteuid() == 0: + log_error("Must be root to run this daemon") + print "Error: Must be root to run this daemon" + sys.exit(1) + + # Instantiate a ControlPlaneAclManager object + caclmgr = ControlPlaneAclManager() + caclmgr.run() + + +if __name__ == "__main__": + main() diff --git a/files/image_config/caclmgrd/caclmgrd-start.sh b/files/image_config/caclmgrd/caclmgrd-start.sh new file mode 100755 index 000000000000..3c7a2afbdf8b --- /dev/null +++ b/files/image_config/caclmgrd/caclmgrd-start.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Only start control plance ACL manager daemon if not an Arista platform. +# Arista devices will use their own service ACL manager daemon(s) instead. +if [ "$(sonic-cfggen -v "platform" | grep -c "arista")" -gt 0 ]; then + echo "Not starting caclmgrd - unsupported platform" + exit 0 +fi + +exec /usr/bin/caclmgrd diff --git a/files/image_config/caclmgrd/caclmgrd.service b/files/image_config/caclmgrd/caclmgrd.service new file mode 100644 index 000000000000..8e6cbb0c8e64 --- /dev/null +++ b/files/image_config/caclmgrd/caclmgrd.service @@ -0,0 +1,11 @@ +[Unit] +Description=Control Plane ACL configuration daemon +Requires=database.service +After=database.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/caclmgrd-start.sh + +[Install] +WantedBy=multi-user.target diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index a7297913eb44..0dc3085e1294 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -200,7 +200,17 @@ def parse_dpg(dpg, hname): acl_intfs = port_alias_map.values() break; if acl_intfs: - acls[aclname] = { 'policy_desc': aclname, 'ports': acl_intfs, 'type': 'MIRROR' if is_mirror else 'L3'} + acls[aclname] = {'policy_desc': aclname, + 'ports': acl_intfs, + 'type': 'MIRROR' if is_mirror else 'L3', + 'service': 'N/A'} + else: + # This ACL has no interfaces to attach to -- consider this a control plane ACL + aclservice = aclintf.find(str(QName(ns, "Type"))).text + acls[aclname] = {'policy_desc': aclname, + 'ports': acl_intfs, + 'type': 'CTRLPLANE', + 'service': aclservice if aclservice is not None else ''} return intfs, lo_intfs, mgmt_intf, vlans, vlan_members, pcs, acls return None, None, None, None, None, None, None diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index 2eee6fe331c8..768052a1d7e2 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -73,7 +73,7 @@ def test_render_template(self): def test_minigraph_acl(self): argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v ACL_TABLE' output = self.run_script(argument) - self.assertEqual(output.strip(), "{'DATAACL': {'type': 'L3', 'policy_desc': 'DATAACL', 'ports': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}") + self.assertEqual(output.strip(), "{'DATAACL': {'type': 'L3', 'policy_desc': 'DATAACL', 'service': 'N/A', 'ports': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}") def test_minigraph_everflow(self): argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v MIRROR_SESSION' diff --git a/src/sonic-utilities b/src/sonic-utilities index 5ad84866491e..6823ce2f3e46 160000 --- a/src/sonic-utilities +++ b/src/sonic-utilities @@ -1 +1 @@ -Subproject commit 5ad84866491e7d4cf4cebcb96e469423c9c91961 +Subproject commit 6823ce2f3e46d9bbf5fcfa6b371705a7368929cb