Skip to content

fix(ec2): NACL rule-number precedence + reject out-of-range NetworkPolicy ports#1763

Merged
vieiralucas merged 1 commit into
mainfrom
worktree-ec2-netiso-fix4-nacl-ports
Jun 18, 2026
Merged

fix(ec2): NACL rule-number precedence + reject out-of-range NetworkPolicy ports#1763
vieiralucas merged 1 commit into
mainfrom
worktree-ec2-netiso-fix4-nacl-ports

Conversation

@vieiralucas

@vieiralucas vieiralucas commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary

Bug-hunt 2026-06-18 findings 1.4, 2.1.

  • 1.4 (MED) — the nft NACL render emitted every deny and dropped allows entirely, so a deny always beat a lower-numbered allow for the same traffic — the opposite of AWS first-match-by-rule-number (100 allow tcp/22 + 200 deny tcp/22 silently blocked SSH). NaclRule now carries rule_number; the renderer sorts by it and skips a deny when an earlier-numbered allow covers the identical direction/protocol/ports/CIDR. Conservative exact-match shadowing (partial overlaps still emit the drop). NACL allows still ride the default-accept policy — SG remains an independent gate.
  • 2.1 (LOW) — NetworkPolicy port translation cast i64 ports to i32 unchecked; a value outside 0..=65535 truncated to a wrong/negative port. Now rejects the ports clause for an out-of-range port.

Test plan

  • cargo test -p fakecloud-ec2 — new unit tests for allow-shadows-deny (both orderings) + out-of-range port rejection (45/45). clippy + fmt clean. (nft/NetworkPolicy actual enforcement isn't CI-testable; the generators are unit-tested.)

Summary by cubic

Fixes NACL evaluation to honor AWS rule-number precedence and rejects invalid NetworkPolicy ports to prevent bogus rules and unintended blocks.

  • Bug Fixes
    • NACL rendering now sorts by rule_number (first-match) and skips a deny when an earlier-numbered allow exactly matches the same direction/protocol/ports/CIDR; allows remain implicit.
    • NetworkPolicy port translation validates 0..=65535; if any port is out of range, the ports clause is omitted instead of truncating to a wrong/negative port.

Written for commit 142d375. Summary will update on new commits.

Review in cubic

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.43750% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/fakecloud-ec2/src/service/firewall_model.rs 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@vieiralucas vieiralucas force-pushed the worktree-ec2-netiso-fix4-nacl-ports branch from 79e37cc to 49b6013 Compare June 18, 2026 14:56
…licy ports

Bug-hunt 2026-06-18 findings 1.4, 2.1.

- 1.4: the nft NACL render emitted every deny and dropped allows entirely, so a
  `deny` always beat a lower-numbered `allow` for the same traffic — the
  opposite of AWS first-match-by-rule-number (e.g. `100 allow tcp/22` +
  `200 deny tcp/22` silently blocked SSH). NaclRule now carries `rule_number`;
  the renderer sorts by it and skips a deny when an earlier-numbered allow
  covers the identical direction/protocol/ports/CIDR (allow shadows deny).
  Conservative exact-match shadowing — partial overlaps still emit the drop
  (over-deny rather than silently allow). NACL allows still ride the
  default-accept policy (SG layer remains independent).
- 2.1: NetworkPolicy port translation cast i64 ports to i32 unchecked; a value
  outside 0..=65535 truncated to a wrong/negative port. Now reject the whole
  ports clause for an out-of-range port instead of emitting a bogus one.

Tests: unit tests for allow-shadows-deny precedence (both orderings) and
out-of-range port rejection.
@vieiralucas vieiralucas force-pushed the worktree-ec2-netiso-fix4-nacl-ports branch from 49b6013 to 142d375 Compare June 18, 2026 15:56
@vieiralucas vieiralucas merged commit 65b53f5 into main Jun 18, 2026
52 of 53 checks passed
@vieiralucas vieiralucas deleted the worktree-ec2-netiso-fix4-nacl-ports branch June 18, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant