Skip to content

unable to set AssociatePublicIpAddress for network interface to false #115

@tuananh

Description

@tuananh

In corporate context, we often have a SCP (service control policy) to block AssociatePublicIpAddress when set to true by default.

However, in machine-api-provider-aws, we have this code path

var networkInterfaces = []*ec2.InstanceNetworkInterfaceSpecification{
{
DeviceIndex: aws.Int64(machineProviderConfig.DeviceIndex),
SubnetId: subnetID,
Groups: securityGroupsIDs,
},
}
// Public IP assignment is different in Wavelength Zones.
// AvailabilityZone and LocalZone uses InternetGateway.
// WavelengthZone uses Carrier Gateway.
if aws.BoolValue(machineProviderConfig.PublicIP) {
zoneName, err := getAvalabilityZoneFromSubnetID(*subnetID, awsClient)
if err != nil {
return nil, mapierrors.InvalidMachineConfiguration("error discoverying zone type: %v", err)
}
zoneType, err := getAvalabilityZoneTypeFromZoneName(zoneName, awsClient)
if err != nil {
return nil, mapierrors.InvalidMachineConfiguration("error discoverying zone type: %v", err)
}
if zoneType == "wavelength-zone" {
networkInterfaces[0].AssociateCarrierIpAddress = machineProviderConfig.PublicIP
} else {
networkInterfaces[0].AssociatePublicIpAddress = machineProviderConfig.PublicIP
}
}

where as when we create new network interface, we did not explicity set AssociatePublicIpAddress. This field, when omited, AWS will use the default value which is true as documented here

Together with the if aws.BoolValue(machineProviderConfig.PublicIP) { only check, render us unable to set this value to false even if we set machineProviderConfig.PublicIP to false.

The fix for this could be

  • Default value for network interface changes to AssociatePublicIpAddress to false.
  • Or Add a else clause to handle false path.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions