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

Enhance ExternalIPPool validation #5898

Merged
merged 3 commits into from
Jan 31, 2024

Conversation

aroradaman
Copy link
Contributor

@aroradaman aroradaman commented Jan 20, 2024

  • Validate if IPRange.Start <= IPRange.End
  • Validate if IPRange.Start and IPRange.End belongs to the same IP family
  • Validate if IPRanges don't overlap with each other

Fixes: #5842

@aroradaman
Copy link
Contributor Author

aroradaman commented Jan 20, 2024

I initially planned to use netip.Addr and netip.Prefix instead of net.IP and net.IPNet as netip.Addr is directly comparable.
In general netip is more efficient than net but it would require to rewriteIPNetContains for netip.Prefix. Maybe in future, we can consider this 🤔

func IPNetContains(ipNet1, ipNet2 *net.IPNet) bool {

@aroradaman
Copy link
Contributor Author

cc @tnqn

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.

The 3rd item of the issue originally means "All IPRanges of ExternalIPPools must not overlap", not only IP ranges of a single ExternalIPPool, because the datapath wouldn't be working if it's configured so. I guess it's hard to strictly prevent it because externalIPPoolLister may be not in sync with actual objects in kube-apiserver, but it should be able to prevent most configuration errors and still better than not checking at all, so could you also checking overlap with ranges in ExternalIPPoolController.externalIPPoolLister?

pkg/controller/externalippool/validate.go Outdated Show resolved Hide resolved
pkg/controller/externalippool/validate.go Outdated Show resolved Hide resolved
pkg/controller/externalippool/validate.go Outdated Show resolved Hide resolved
@aroradaman aroradaman requested a review from tnqn January 23, 2024 19:14
@aroradaman aroradaman force-pushed the external-ip-pool-validation branch 2 times, most recently from 8e2f678 to 388639a Compare January 23, 2024 20:04
pkg/controller/externalippool/validate.go Outdated Show resolved Hide resolved
pkg/controller/externalippool/validate.go Outdated Show resolved Hide resolved
pkg/controller/externalippool/validate.go Outdated Show resolved Hide resolved
pkg/controller/externalippool/validate.go Outdated Show resolved Hide resolved
@aroradaman aroradaman force-pushed the external-ip-pool-validation branch 2 times, most recently from ad31ed5 to f5da8d2 Compare January 28, 2024 19:12
@tnqn
Copy link
Member

tnqn commented Jan 29, 2024

3 e2e tests failed at TestEgress. There seemed to be a panic when calling the changed webhook:
https://github.com/antrea-io/antrea/actions/runs/7687867552/job/20948603505?pr=5898

Presently, when validating ExternalIPPool, attempting to invoke methods
defined on externalIPPoolController results in a nil pointer exception
and eventually triggers a panic. With this commit, the initialized
externalIPPoolController is used to construct the APIServer
configuration,facilitating access to other methods of
externalIPPoolController during the validation of ExternalIPPool.

Signed-off-by: Daman Arora <aroradaman@gmail.com>
Signed-off-by: Daman Arora <aroradaman@gmail.com>
@tnqn
Copy link
Member

tnqn commented Jan 29, 2024

3 e2e tests failed at TestEgress. There seemed to be a panic when calling the changed webhook:
https://github.com/antrea-io/antrea/actions/runs/7687867552/job/20948603505?pr=5898

It was because c.externalIPPoolController below is nil. It worked previously because it never relies on any member variables to do the validation. You need to change NewConfig to pass the externalIPPoolController.

s.Handler.NonGoRestfulMux.HandleFunc("/validate/externalippool", webhook.HandlerForValidateFunc(c.externalIPPoolController.ValidateExternalIPPool))

@aroradaman
Copy link
Contributor Author

aroradaman commented Jan 29, 2024

3 e2e tests failed at TestEgress. There seemed to be a panic when calling the changed webhook:
https://github.com/antrea-io/antrea/actions/runs/7687867552/job/20948603505?pr=5898

It was because c.externalIPPoolController below is nil. It worked previously because it never relies on any member variables to do the validation. You need to change NewConfig to pass the externalIPPoolController.

s.Handler.NonGoRestfulMux.HandleFunc("/validate/externalippool", webhook.HandlerForValidateFunc(c.externalIPPoolController.ValidateExternalIPPool))

yeah, figured that. I was just about to push the commit fixing that.

tnqn
tnqn previously approved these changes Jan 29, 2024
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, thanks @aroradaman

@tnqn tnqn added the action/release-note Indicates a PR that should be included in release notes. label Jan 29, 2024
@tnqn
Copy link
Member

tnqn commented Jan 29, 2024

/skip-all

@tnqn
Copy link
Member

tnqn commented Jan 29, 2024

/test-ipv6-e2e
/test-ipv6-only-e2e

@tnqn
Copy link
Member

tnqn commented Jan 30, 2024

@aroradaman e2e test failed when it tried to update an externalIPPool. The combinedRanges should exclude the existing ip ranges of the pool being update.

@aroradaman
Copy link
Contributor Author

@aroradaman e2e test failed when it tried to update an externalIPPool. The combinedRanges should exclude the existing ip ranges of the pool being update.

I added a unit test to update 10.10.10.0/24 range with 10.10.0.0/16 to check the same but it failed. Right now getIPRangeSet makes a string/set comparison, should I enhance this validation as well?

Assuming an update from 10.10.10.0/24 to 10.10.0.0/16 should be allowed as no range is deleted.

@tnqn
Copy link
Member

tnqn commented Jan 30, 2024

@aroradaman e2e test failed when it tried to update an externalIPPool. The combinedRanges should exclude the existing ip ranges of the pool being update.

I added a unit test to update 10.10.10.0/24 range with 10.10.0.0/16 to check the same but it failed. Right now getIPRangeSet makes a string/set comparison, should I enhance this validation as well?

Assuming an update from 10.10.10.0/24 to 10.10.0.0/16 should be allowed as no range is deleted.

That's another story and may require more changes in ip allocators as well. It's better to focus on the 3 validations in this PR.

* Validate if any IPRange don't overlap with another IPRange of current or existing pool
* Validate if IPRange.Start <= IPRange.End
* Validate if IPRange.Start and IPRange.End belong to same IP family

Signed-off-by: Daman Arora <aroradaman@gmail.com>
@aroradaman
Copy link
Contributor Author

/test-ipv6-e2e
/test-ipv6-only-e2e

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 Jan 31, 2024

/skip-all

@tnqn tnqn merged commit 003eb71 into antrea-io:main Jan 31, 2024
52 of 55 checks passed
@aroradaman aroradaman deleted the external-ip-pool-validation branch January 31, 2024 06:08
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.

Enhance ExternalIPPool validation
2 participants