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

Fix nil pointer dereference in subnet validation #3150

Merged

Conversation

bennerv
Copy link
Collaborator

@bennerv bennerv commented Sep 6, 2023

Which issue this PR addresses:

Fixes a nil pointer dereference in cluster creation due to addressPrefix not being set during cluster creation.

What this PR does / why we need it:

Switch between addressPrefix and addressPrefixes on subnets.

Test plan for issue:

e2e & green ci

Is there any documentation that needs to be updated for this PR?

nope

Comment on lines +770 to +774
if err = validateSubnetSize(s, address); err != nil {
return err
}
Copy link
Member

@cblecker cblecker Sep 6, 2023

Choose a reason for hiding this comment

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

If this is validating a range, do we want to error if any element of the slice doesn't validate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Honestly I'm not sure.

I'm not even sure how openshift will handle this. You can technically specify multiple IP address ranges on a subnet now (wasn't that the point of a subnet to begin with!??).

For now, we've only seen customers with a single one defined. You have to opt into the MSFT AFEC feature flag Microsoft.Network/AllowMultipleAddressPrefixesOnSubnet in order to use it for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not even sure how openshift will handle this. You can technically specify multiple IP address ranges on a subnet now (wasn't that the point of a subnet to begin with!??).

For now, we've only seen customers with a single one defined. You have to opt into the MSFT AFEC feature flag Microsoft.Network/AllowMultipleAddressPrefixesOnSubnet in order to use it for now.

I poked around in the installer code and nothing I found indicated that the installer will be unhappy if you provide a subnet with multiple address ranges. Complicated stuff though, so it would be good to ask the installer folks to verify.

If OCP doesn't support multiple address ranges, we can error out here if the cx has put more than one and then the original question in this thread is moot.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the investigation.

I also poked around in machine-config-provider-azure and there is never an explicit subnet address assignment used during NIC provisioning, so it should be handled transparently. The only thing that is specified during creation is the subnet ID.

So I think the proper validation here would be to add up all the address spaces and make sure the total address space is >27 mask, also taking into account the number of reserved IP addresses in smaller address spaces may have an impact.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not perfect, but instead of adding up individual ranges, I'm going to validate that at least one address prefix has a /27 or greater and error out if not.

If we have a bunch of /30s it's not going to make sense as there isn't enough address space for anything there. The cases around this are going to get crazy, and at least we're returning a valid message to the customer.

Copy link

@AldoFusterTurpin AldoFusterTurpin left a comment

Choose a reason for hiding this comment

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

Thanks for this!
One minor suggestion and the usage of an existing aux function to check errors.

pkg/validate/dynamic/dynamic.go Outdated Show resolved Hide resolved
pkg/validate/dynamic/dynamic_test.go Outdated Show resolved Hide resolved
This should allow us to catch any issues with using one over the other,
since both are valid configurations on both vnets and subnets in Azure.
wantErr: fmt.Sprintf("400: InvalidLinkedVNet: %s: The provided subnet '%s' is invalid: must be /27 or larger.", subnetPath, subnetId),
},
{
name: "subnet size is gucci gang",
Copy link
Contributor

Choose a reason for hiding this comment

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

🚀

@cadenmarchese cadenmarchese merged commit c4cf22a into Azure:master Sep 11, 2023
18 checks passed
@bennerv bennerv deleted the fix-nil-pointer-dereference-in-dynamic branch September 20, 2023 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working next-release To be included in the next RP release rollout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants