Repository navigation
Fix E3688 false positives on IpProtocol "-1", icmpv6 and "ICMP" rules - #4806
Conversation
|
Hi, the [CI] Test PR / Test PR Data runs on this PR are parked waiting for a maintainer approval (first-time-contributor gate). Could someone approve them when you get a chance? Thanks. |
d56bb54 to
1f54cb7
Compare
|
Hi @kddejong, the [CI] Test PR and Test PR Data runs here are still parked waiting for a maintainer approval (first-time-contributor gate) after my follow-up push, and your earlier approval now sits on a superseded commit. Could you approve the workflow runs when you get a chance? Thanks. |
ea770f4 to
026a072
Compare
E3688 validated security group port pairing against all_to_and_from_ports.json. For IpProtocol "1"/"icmp" only a wildcard FromPort required a wildcard ToPort, but every other protocol required both directions to be -1. That two-way branch also reported rules EC2 and CloudFormation accept: - IpProtocol "-1" with any port combination (EC2 stores every such rule as -1/-1; protocol -1 allows traffic on all ports regardless of any port range specified) - icmpv6/"58" with a specific type and ToPort -1 (the ICMPv6 form of the icmp 8/-1 shape allowed since aws-cloudformation#3482) - upper-case "ICMP" with a specific type and ToPort -1 (missed the case-sensitive enum; EC2 stores it as icmp) The schema now applies no pairing constraint for protocol -1, treats icmpv6/"58" like icmp, and matches the protocol name case-insensitively. tcp/udp with a -1 port and wildcard icmp/icmpv6 types with a specific code are still reported. Fixes aws-cloudformation#4800
The windows unitlint job's pre-commit ruff-format hook failed. Formatting-only change; no test logic touched. Signed-off-by: Varshith Puli <pulivarshit@gmail.com>
026a072 to
495af03
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4806 +/- ##
=======================================
Coverage 94.67% 94.67%
=======================================
Files 439 439
Lines 15995 15995
Branches 3104 3104
=======================================
Hits 15144 15144
Misses 468 468
Partials 383 383
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:
|
Bug
E3688 (
SecurityGroupAllToAndFromPorts) validates security group rules againstall_to_and_from_ports.json. ForIpProtocol"1"/"icmp"the schema only required thatFromPort: -1comes withToPort: -1; for every other protocol it required both directions to be -1 whenever one was. That two-way branch reported three kinds of rule that EC2 and CloudFormation accept (verified with a real stack in us-west-2 on 2026-10-20):IpProtocol: "-1"with one port set to -1 or absent. EC2 stores every such rule as -1/-1; protocol -1 "allows traffic on all ports, regardless of any port range you specify".icmpv6/"58"with a specific type andToPort: -1, the ICMPv6 form of theicmp8/-1 shape allowed since Allow ICMP to have fromport other than -1 with to port -1 #3482."ICMP"with a specific type andToPort: -1, which missed the case-sensitive enum; EC2 stores it asicmp.Root cause
The schema's outer
ifonly special-cased"1"/"icmp"(case-sensitive). Everything else, including protocol-1,icmpv6/"58", and"ICMP", fell into theelsebranch demanding both ports be -1 when one is.Fix
Restructured
all_to_and_from_ports.jsoninto three branches:-1(int or string): no pairing constraint at all.icmp/1andicmpv6/58, matched case-insensitively via(?i)patterns (a convention already used in this repo's schemas), withtype: ["string", "integer"]guards so intrinsic-function values keep their previous behavior: only a wildcardFromPort(-1, all types) requires a wildcardToPort(-1, all codes), matching the documented ICMP constraint that EC2 also enforces for ICMPv6.The rule description was updated to document the exemptions.
Test evidence
IpProtocol: "-1",icmpv6/"58"and"ICMP"rules with a -1 port #4800 before the fix: template A produced 9 E3688 false positives, template B produced the 4 correct E3688 reports.test/unit/rules/resources/ec2/test_sg_all_to_and_from_ports.py: the 9 existing cases (schema paths updated for the restructure) plus 17 new good/bad cases covering protocol-1port combinations,icmpv6/"58"/int 58, case variants (ICMP,Icmpv6,ICMPV6), and the still-rejected shapes (tcp/udp with a -1 port, wildcard icmp/icmpv6 type with a specific code). Result: 26 passed.test/unit/rules/resources/ec2/andtest/unit/rules/resources/ectwo/all pass (133 passed).{"Ref": "..."}) behave exactly as before the change (no errors either way).Fixes #4800