OSAC-365: canonicalize CIDR values on VirtualNetwork and Subnet Create#687
OSAC-365: canonicalize CIDR values on VirtualNetwork and Subnet Create#687tchughesiv wants to merge 3 commits into
Conversation
|
@tchughesiv: This pull request references [OSAC-365](https://redhat.atlassian.net/browse/OS[AC-3](https://redhat.atlassian.net/browse/AC-3)65) which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: tchughesiv The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@tchughesiv: This pull request references [OSAC-365](https://redhat.atlassian.net/browse/OS[AC-3](https://redhat.atlassian.net/browse/AC-3)65) which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
Warning Review limit reached
More reviews will be available in 43 minutes and 8 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository: osac-project/coderabbit/.coderabbit.yaml Review profile: ASSERTIVE Plan: Enterprise Run ID: 📒 Files selected for processing (6)
WalkthroughThis PR introduces CIDR canonicalization across subnet and virtual network server validation. A new ChangesCIDR Canonicalization on Create
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 11✅ Passed checks (11 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@tchughesiv: This pull request references OSAC-365 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
9568420 to
8a26dc2
Compare
| } | ||
|
|
||
| isIPv4 := network.IP.To4() != nil | ||
| if ipVersion == "IPv4" && !isIPv4 { |
There was a problem hiding this comment.
Should IPv4 and IPv6 defined as constants somewhere? Shouldn't break on a typo
There was a problem hiding this comment.
Good catch... I’ll add constants in cidr_validation.go and use them at call sites in this PR.
There was a problem hiding this comment.
added cidrIPv4/cidrIPv6 constants in cidr_validation.go.
| } | ||
|
|
||
| // validateCIDR validates a CIDR string and checks if it matches the expected IP version. | ||
| func validateCIDR(cidrStr string, ipVersion string) error { |
There was a problem hiding this comment.
Is this method used anywhere? I couldn't find it in this PR, but maybe somewhere else
There was a problem hiding this comment.
Yes... still used by SG rule validation:
fulfillment-service/internal/servers/private_security_groups_server.go
Lines 344 to 354 in 8a26dc2
VN/Subnet use parseAndValidateCIDR to canonicalize on Create; SG keeps validateCIDR (validate only) per OSAC-365 scope:
fulfillment-service/internal/servers/cidr_validation.go
Lines 45 to 49 in 8a26dc2
If you want SG (or PublicIPPool spec.cidrs[]) canonicalized here too, say the word... otherwise I’d track those as follow-ups.
| if err != nil { | ||
| return err | ||
| } | ||
| if existingSubnet == nil { |
There was a problem hiding this comment.
I guess this is done to facilitate further validation. But, it's not clear why and why it depends on existingSubnet being nil can you add a comment about it?
There was a problem hiding this comment.
added comments on both paths.
existingVN == nil / existingSubnet == nil distinguishes Create from Update. We canonicalize only on Create today because:
- OSAC-365 scope is new Create behavior, not a data migration.
- Legacy rows may already store non-canonical strings; normalizing on Update would rewrite stored values on unrelated updates.
- Immutability is string-based - a client sending the canonical form against a legacy stored value would fail even though the network is the same.
We can do Update canonicalization, but it’s a product decision about migrating existing data... we’d want agreed Update/migration rules, tests for legacy rows, and a quick check that anything downstream wouldn’t break if the stored CIDR text changed but the network didn’t.
Extract parseAndValidateCIDR helper and normalize ipv4_cidr/ipv6_cidr to canonical form during Create validation before persistence. Update and SecurityGroup rule validation are unchanged. Add contract tests for VirtualNetwork and Subnet Create canonicalization, Create round-trip, Update no-op, and legacy non-canonical parent VN subset acceptance. Signed-off-by: Tommy Hughes <tohughes@redhat.com>
Define cidrIPv4/cidrIPv6 constants and document why canonicalization is guarded by existingVN/existingSubnet nil checks (immutable CIDR on Update). Signed-off-by: Tom Hughes <tohughes@redhat.com>
netip.ParsePrefix preserves host bits unlike net.ParseCIDR; Masked() zeros them to match the canonical form expected by Create validation.
cd1698c to
b64bf27
Compare
|
/retest-required |
Canonicalize CIDR values on Create for Subnet and VirtualNetwork
Jira: https://redhat.atlassian.net/browse/OSAC-365
Story type: Task
Summary
Normalize CIDR values to canonical form when creating VirtualNetworks and Subnets so stored values are consistent regardless of how callers express the network address (e.g.,
10.0.1.5/24→10.0.1.0/24). Canonicalization applies on Create only; Update and SecurityGroup rule validation are unchanged.Changes
parseAndValidateCIDRandvalidateCIDRhelpers intointernal/servers/cidr_validation.goipv4_cidrandipv6_cidron VirtualNetwork Create invalidateVirtualNetworkipv4_cidrandipv6_cidron Subnet Create invalidateSubnet(before subset/overlap checks)Testing
private_virtual_networks_server_test.goandprivate_subnets_server_test.goit/on PR)parseAndValidateCIDRandvalidateCIDRat 100%; fullinternal/suite passes (918/918 server specs, 64 suites)Deployment note
Before rollout, audit staging/prod for existing non-canonical CIDRs (operational prerequisite noted in the Jira ticket — not a code deliverable for this PR).
Acceptance Criteria
10.0.1.5/24→10.0.1.0/24)Summary by CodeRabbit
Improvements
Tests