Skip to content

Commit

Permalink
Improved cloud provider location matching for private endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
brett19 committed Sep 14, 2023
1 parent aa4e895 commit 0d2acc2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmd/cleanup-azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var cleanupAzureCmd = &cobra.Command{
Logger: logger,
Region: config.Azure.Region,
Creds: azureCreds,
SubID: "5ef34701-b858-4231-a9c1-103e4604ad8f",
RgName: "sdkqe-github-runners",
SubID: config.Azure.SubID,
RgName: config.Azure.RGName,
}

err := peCtrl.Cleanup(ctx)
Expand Down
15 changes: 13 additions & 2 deletions cmd/privateendpoints-setuplink.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var privateEndpointsSetupLinkCmd = &cobra.Command{
helper := CmdHelper{}
logger := helper.GetLogger()
ctx := helper.GetContext()
config := helper.GetConfig(ctx)

shouldAutoConfig, _ := cmd.Flags().GetBool("auto")
instanceId, _ := cmd.Flags().GetString("instance-id")
Expand Down Expand Up @@ -74,9 +75,13 @@ var privateEndpointsSetupLinkCmd = &cobra.Command{
if instanceId != "" {
awsCreds := helper.GetAWSCredentials(ctx)

if !config.AWS.Enabled.Value() {
logger.Fatal("cannot setup AWS private endpoint without AWS configuration")
}

peCtrl := awscontrol.PrivateEndpointsController{
Logger: logger,
Region: cloudCluster.Region,
Region: config.AWS.Region,
Credentials: awsCreds,
}

Expand All @@ -103,10 +108,16 @@ var privateEndpointsSetupLinkCmd = &cobra.Command{
} else if vmId != "" {
azureCreds := helper.GetAzureCredentials(ctx)

if !config.Azure.Enabled.Value() {
logger.Fatal("cannot setup Azure private endpoint without Azure configuration")
}

peCtrl := azurecontrol.PrivateEndpointsController{
Logger: logger,
Region: cloudCluster.Region,
Region: config.Azure.Region,
Creds: azureCreds,
SubID: config.Azure.SubID,
RgName: config.Azure.RGName,
}

peData, err := peCtrl.CreateVPCEndpoint(ctx, &azurecontrol.CreateVPCEndpointOptions{
Expand Down
11 changes: 9 additions & 2 deletions utils/azurecontrol/privateendpointcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ func (c *PrivateEndpointsController) CreateVPCEndpoint(ctx context.Context, opts
}

vmName := vmResInfo.Name
rgName := vmResInfo.ResourceGroupName
subId := vmResInfo.SubscriptionID
rgName := vmResInfo.ResourceGroupName

if c.SubID != subId {
return nil, errors.New("virtual machine is not in expected subscription")
}
if c.RgName != rgName {
return nil, errors.New("virtual machine is not in expected resource-group")
}

computeClient, err := armcompute.NewVirtualMachinesClient(subId, c.Creds, nil)
if err != nil {
Expand All @@ -61,7 +68,7 @@ func (c *PrivateEndpointsController) CreateVPCEndpoint(ctx context.Context, opts

vmLocation := *vmData.Location
if c.Region != vmLocation {
return nil, errors.New("virtual machine is not in same region")
return nil, errors.New("virtual machine is not in expected region")
}

if len(vmData.Properties.NetworkProfile.NetworkInterfaces) < 1 {
Expand Down

0 comments on commit 0d2acc2

Please sign in to comment.