fix(ec2): NACL rule-number precedence + reject out-of-range NetworkPolicy ports#1763
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
79e37cc to
49b6013
Compare
…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.
49b6013 to
142d375
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bug-hunt 2026-06-18 findings 1.4, 2.1.
denyalways beat a lower-numberedallowfor the same traffic — the opposite of AWS first-match-by-rule-number (100 allow tcp/22+200 deny tcp/22silently blocked SSH).NaclRulenow carriesrule_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.0..=65535truncated 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.
rule_number(first-match) and skips a deny when an earlier-numbered allow exactly matches the same direction/protocol/ports/CIDR; allows remain implicit.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.