Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate AntreaIPAM IP ranges #2995

Merged
merged 1 commit into from
Mar 1, 2022
Merged

Conversation

ksamoray
Copy link
Contributor

@ksamoray ksamoray commented Nov 7, 2021

Verify that:

  • There are no overlaps between an IPPool ranges while creating and
    updating pools.
  • Validate that the gateway IP belongs to the same subnet as the IP
    range addresses.

Signed-off-by: Kobi Samoray [email protected]

@codecov-commenter
Copy link

codecov-commenter commented Nov 7, 2021

Codecov Report

Merging #2995 (cb5b3b6) into main (b147eb2) will decrease coverage by 6.10%.
The diff coverage is 57.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2995      +/-   ##
==========================================
- Coverage   60.89%   54.79%   -6.11%     
==========================================
  Files         268      374     +106     
  Lines       26753    51398   +24645     
==========================================
+ Hits        16292    28162   +11870     
- Misses       8655    20786   +12131     
- Partials     1806     2450     +644     
Flag Coverage Δ
e2e-tests 53.47% <0.00%> (?)
integration-tests 35.77% <ø> (?)
kind-e2e-tests 48.53% <0.00%> (+0.85%) ⬆️
unit-tests 42.30% <84.21%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/controller/ipam/validate.go 57.95% <57.65%> (-22.05%) ⬇️
pkg/agent/cniserver/pod_configuration_linux.go 26.31% <0.00%> (-40.36%) ⬇️
pkg/controller/ipam/antrea_ipam_controller.go 48.71% <0.00%> (-31.57%) ⬇️
pkg/controller/networkpolicy/endpoint_querier.go 61.46% <0.00%> (-29.97%) ⬇️
pkg/controller/egress/controller.go 61.11% <0.00%> (-27.34%) ⬇️
.../registry/networkpolicy/clustergroupmember/rest.go 64.28% <0.00%> (-23.95%) ⬇️
pkg/agent/cniserver/ipam/antrea_ipam.go 55.55% <0.00%> (-23.62%) ⬇️
pkg/agent/cniserver/ipam/antrea_ipam_controller.go 55.93% <0.00%> (-23.59%) ⬇️
pkg/agent/util/ethtool/ethtool_linux.go 46.66% <0.00%> (-23.34%) ⬇️
pkg/agent/util/iptables/lock.go 60.00% <0.00%> (-21.82%) ⬇️
... and 336 more

@ksamoray ksamoray force-pushed the ipam-validate branch 3 times, most recently from 9126a38 to 560ec3f Compare November 9, 2021 10:12
Copy link
Contributor

@annakhm annakhm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can IP version validation for each range/cidr be added as well? All ranges should be consistent with IPPoolSpec.IPVersion

return validationResult(false, msg)
}

if allowed {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can allowed be false at this stage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's redundant, I'll remove.

@ksamoray ksamoray force-pushed the ipam-validate branch 3 times, most recently from d08ef44 to 87b2e3f Compare November 15, 2021 09:27
pkg/controller/ipam/validate.go Outdated Show resolved Hide resolved
pkg/controller/ipam/validate.go Outdated Show resolved Hide resolved
pkg/controller/ipam/validate.go Outdated Show resolved Hide resolved
_, cidr, _ := net.ParseCIDR(r.CIDR)
if !cidr.Contains(gateway) {
return false, fmt.Sprintf(
"Range is invalid. Gateway %s is unreachable from CIDR %s", r.Gateway, r.CIDR)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my understanding, as the feature requires the Pod CIDR is in the same subnet of Node IP addresses. The CIDR will be a subset of the underlay subnet and the gateway will not be within the CIDR. For example, the underlay subnet is 192.168.0.0/22, the Node CIDR is 192.168.0.0/24, the Pod CIDR is 192.168.1.0/24, but the gateway 192.168.0.1 is not within 192.168.1.0/24.
I think it should check PodCIDR/r.PrefixLength contains the gateway IP.
@GraysonWu @annakhm could you confirm?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should @gran-vmv, not Grayson.

Copy link
Contributor

@gran-vmv gran-vmv Nov 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be checked.
@annakhm Do you think we need to check it here?

reservedIPs := []net.IP{net.ParseIP(ipRange.SubnetInfo.Gateway)}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gran-vmv is my understanding correct? We should check whether PodCIDR/PrefixLength contains the gateway IP, instead of the provided PodCIDR itself, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should check that subnet CIDR defined by SubnetInfo.Gateway/SubnetInfo.PrefixLength should contain the CIDR/range that we are validating.

@ksamoray ksamoray force-pushed the ipam-validate branch 2 times, most recently from 8811652 to 85ab7f9 Compare November 18, 2021 12:23
@ksamoray ksamoray requested a review from tnqn November 18, 2021 14:28
pkg/controller/ipam/validate.go Outdated Show resolved Hide resolved
pkg/controller/ipam/validate.go Outdated Show resolved Hide resolved
},
},
{
name: "CREATE operation with CIDR overlap with IP range should not be allowed",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between the above one and this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1st one intersect while the 2nd one is contained. I added the latter as your review comment above was that the latter case is not covered by the validation. If you think that one of these is redundant, I can remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two cases look good to me. I just didn't tell the difference from the name of the cases. Could we make the name a bit more explict to explain the difference?

pkg/controller/ipam/validate.go Outdated Show resolved Hide resolved

func validateIPRange(r crdv1alpha2.SubnetIPRange, poolIPVersion int) (bool, string) {
// Validate the integrity of IPs within the IP range
gateway := net.ParseIP(r.Gateway)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to save 4 lines of code, can we validate GW IP version here and rely on further checks to fail if IP version differs for other attributes?

Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, a minor comment about test case name.

},
},
{
name: "CREATE operation with CIDR overlap with IP range should not be allowed",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two cases look good to me. I just didn't tell the difference from the name of the cases. Could we make the name a bit more explict to explain the difference?

@ksamoray ksamoray force-pushed the ipam-validate branch 2 times, most recently from 9800a09 to 9560fd8 Compare November 25, 2021 10:25
@ksamoray
Copy link
Contributor Author

/test-all

tnqn
tnqn previously approved these changes Nov 26, 2021
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, will wait for @annakhm's final review before merging.

annakhm
annakhm previously approved these changes Nov 27, 2021
@ksamoray
Copy link
Contributor Author

/test-all

@ksamoray ksamoray dismissed stale reviews from annakhm and tnqn via 9dc67b0 November 28, 2021 09:29
@ksamoray ksamoray force-pushed the ipam-validate branch 2 times, most recently from 9dc67b0 to 5394ae2 Compare November 30, 2021 12:35
@annakhm
Copy link
Contributor

annakhm commented Nov 30, 2021

LGTM

@ksamoray
Copy link
Contributor Author

ksamoray commented Dec 1, 2021

/test-all

tnqn
tnqn previously approved these changes Dec 14, 2021
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tnqn
Copy link
Member

tnqn commented Dec 14, 2021

Sorry, wait too long to merge this PR. Will merge it once CI is recovered.

Verify that:
- There are no overlaps between an IPPool ranges while creating and
updating pools.
- Validate that the gateway IP belongs to the same subnet as the IP
range addresses.

Signed-off-by: Kobi Samoray <[email protected]>
@ksamoray
Copy link
Contributor Author

@tnqn this has been sitting for a while, mind having a look again (no changes whatsoever, I've just rebased it).

Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @ksamoray, I missed this one since last comment.

@tnqn tnqn merged commit b85d2c0 into antrea-io:main Mar 1, 2022
@tnqn tnqn added the action/release-note Indicates a PR that should be included in release notes. label Mar 1, 2022
GraysonWu pushed a commit to GraysonWu/antrea that referenced this pull request Mar 10, 2022
Verify that:
- There are no overlaps between an IPPool ranges while creating and
updating pools.
- Validate that the gateway IP belongs to the same subnet as the IP
range addresses.

Signed-off-by: Kobi Samoray <[email protected]>
@ksamoray ksamoray deleted the ipam-validate branch August 2, 2022 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants