Commit e31cf38
committed
[caclmgrd] Fix EXTERNAL_CLIENT ACL: duplicate rules, multi-port, and stale state
Fix duplicate iptables/ip6tables rules for EXTERNAL_CLIENT Control Plane
ACL. The rule-emission loop could append identical full commands
(ns-prefix + rule) multiple times. Fix builds the full command first and
uses a per-table shadow set (acl_cmds_seen) for O(1) duplicate detection.
iptables_cmds stays a list to preserve rule ordering.
Fix single-port limitation for EXTERNAL_CLIENT ACL: previously each rule
overwrote dst_ports with a single-element list, so only the last rule's
port was used. Fix accumulates ports via append-if-not-present so all
configured ports generate iptables rules.
Fix ACL_SERVICES class dict pollution: dst_ports was written back into the
class-level ACL_SERVICES dict on every call, causing stale ports from
deleted rules to persist across reloads until process restart. dst_ports
is now kept strictly local to each call.
Fix int/str type mismatch in dst_ports: L4_DST_PORT_RANGE expansion now
appends str(port) to stay type-consistent with L4_DST_PORT (which is a
string from Redis). The mixed-type list silently broke the duplicate check
producing duplicate --dport rules when a port appeared in both a range
and an individual rule.
Fix acl_cmds_seen scope: the dedup shadow set was reset per service, so
duplicate commands generated by two services on the same ACL table were
not caught. Moved to per-table scope.
Fix ip2me block rules using network address instead of interface IP for
non-/32 non-VLAN interfaces. ip_ntwrk.network_address returned the
network base address (e.g. 10.0.1.0 for 10.0.1.2/24) instead of the
interface's own IP. Fix uses ipaddress.ip_interface(iface_cidr).ip.
Fix empty management IP string passed to iptables -s/-d arguments in
generate_allow_internal_docker_ip_traffic_commands when
get_namespace_mgmt_ip fails. Guard added to return early with a warning
when the management IP is unavailable.
Tests:
- Add dedup assertion to existing parameterized test harness
- Add vector: IPv4 multi-port + src-ip
- Add vector: L4_DST_PORT_RANGE + overlapping L4_DST_PORT
- Add vector: service listed twice on same table
- Add standalone two-call reload test: port deleted between reloads must
not leak stale rules
- Add vector: non-/32 non-VLAN interfaces block interface IP not network
address
- Add standalone test: empty management IP returns empty list without crash
Signed-off-by: littlespace <littlespace@users.noreply.github.com>1 parent f24efde commit e31cf38
5 files changed
Lines changed: 1024 additions & 140 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
309 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
310 | 312 | | |
311 | 313 | | |
312 | 314 | | |
| |||
373 | 375 | | |
374 | 376 | | |
375 | 377 | | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
383 | 391 | | |
384 | 392 | | |
385 | 393 | | |
| |||
742 | 750 | | |
743 | 751 | | |
744 | 752 | | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
745 | 758 | | |
746 | 759 | | |
747 | 760 | | |
| |||
782 | 795 | | |
783 | 796 | | |
784 | 797 | | |
785 | | - | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
786 | 801 | | |
787 | | - | |
788 | | - | |
| 802 | + | |
| 803 | + | |
789 | 804 | | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
794 | 813 | | |
795 | | - | |
796 | | - | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
797 | 818 | | |
798 | 819 | | |
799 | 820 | | |
| |||
869 | 890 | | |
870 | 891 | | |
871 | 892 | | |
872 | | - | |
873 | | - | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
874 | 901 | | |
875 | 902 | | |
876 | 903 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
28 | | - | |
| 28 | + | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | | - | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | | - | |
40 | | - | |
41 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
42 | 49 | | |
43 | 50 | | |
44 | | - | |
45 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
46 | 57 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
0 commit comments