Skip to content

Commit 625b0a9

Browse files
marmijoprestist
andcommitted
mantle/azure: Add ability to set managed identity on Azure instances
Add support for configuring user-assigned managed identities[1] on Azure VM instances to be able to access secure resources within Azure. Add an option to kola to set the managed identity ID and carry it through to VM instance creation. [1]: https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/overview see: coreos/fedora-coreos-tracker#1871 Co-authored-by: Steven Presti <[email protected]>
1 parent 7c01f86 commit 625b0a9

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

mantle/cmd/kola/kola.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,15 @@ func writeProps() error {
300300
InstanceType string `json:"type"`
301301
}
302302
type Azure struct {
303-
DiskURI string `json:"diskUri"`
304-
Publisher string `json:"publisher"`
305-
Offer string `json:"offer"`
306-
Sku string `json:"sku"`
307-
Version string `json:"version"`
308-
Location string `json:"location"`
309-
Size string `json:"size"`
310-
AvailabilityZone string `json:"availability_zone"`
303+
DiskURI string `json:"diskUri"`
304+
Publisher string `json:"publisher"`
305+
Offer string `json:"offer"`
306+
Sku string `json:"sku"`
307+
Version string `json:"version"`
308+
Location string `json:"location"`
309+
Size string `json:"size"`
310+
AvailabilityZone string `json:"availability_zone"`
311+
ManagedIdentityID string `json:"managed_identity_id"`
311312
}
312313
type DO struct {
313314
Region string `json:"region"`
@@ -356,14 +357,15 @@ func writeProps() error {
356357
InstanceType: kola.AWSOptions.InstanceType,
357358
},
358359
Azure: Azure{
359-
DiskURI: kola.AzureOptions.DiskURI,
360-
Publisher: kola.AzureOptions.Publisher,
361-
Offer: kola.AzureOptions.Offer,
362-
Sku: kola.AzureOptions.Sku,
363-
Version: kola.AzureOptions.Version,
364-
Location: kola.AzureOptions.Location,
365-
Size: kola.AzureOptions.Size,
366-
AvailabilityZone: kola.AzureOptions.AvailabilityZone,
360+
DiskURI: kola.AzureOptions.DiskURI,
361+
Publisher: kola.AzureOptions.Publisher,
362+
Offer: kola.AzureOptions.Offer,
363+
Sku: kola.AzureOptions.Sku,
364+
Version: kola.AzureOptions.Version,
365+
Location: kola.AzureOptions.Location,
366+
Size: kola.AzureOptions.Size,
367+
AvailabilityZone: kola.AzureOptions.AvailabilityZone,
368+
ManagedIdentityID: kola.AzureOptions.ManagedIdentityID,
367369
},
368370
DO: DO{
369371
Region: kola.DOOptions.Region,

mantle/cmd/kola/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func init() {
102102
sv(&kola.AzureOptions.Location, "azure-location", "westus", "Azure location (default \"westus\"")
103103
sv(&kola.AzureOptions.Size, "azure-size", "", "Azure machine size")
104104
sv(&kola.AzureOptions.AvailabilityZone, "azure-availability-zone", "1", "Azure Availability Zone (default \"1\")")
105+
sv(&kola.AzureOptions.ManagedIdentityID, "azure-managed-identity", "", "Azure Managed Identity resource ID to assign to VM")
105106

106107
// do-specific options
107108
sv(&kola.DOOptions.ConfigPath, "do-config-file", "", "DigitalOcean config file (default \"~/"+auth.DOConfigPath+"\")")

mantle/platform/api/azure/instance.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ func (a *API) getVMParameters(name, userdata, sshkey, storageAccountURI, size st
106106
Version: &a.opts.Version,
107107
}
108108
}
109+
var managedIdentity *armcompute.VirtualMachineIdentity
110+
if a.opts.ManagedIdentityID != "" {
111+
managedIdentity = &armcompute.VirtualMachineIdentity{
112+
Type: to.Ptr(armcompute.ResourceIdentityTypeUserAssigned),
113+
UserAssignedIdentities: map[string]*armcompute.UserAssignedIdentitiesValue{
114+
a.opts.ManagedIdentityID: {},
115+
},
116+
}
117+
}
109118
// UltraSSDEnabled=true is required for NVMe support on Gen2 VMs
110119
additionalCapabilities := &armcompute.AdditionalCapabilities{
111120
UltraSSDEnabled: to.Ptr(true),
@@ -117,6 +126,7 @@ func (a *API) getVMParameters(name, userdata, sshkey, storageAccountURI, size st
117126
Tags: map[string]*string{
118127
"createdBy": to.Ptr("mantle"),
119128
},
129+
Identity: managedIdentity,
120130
Properties: &armcompute.VirtualMachineProperties{
121131
HardwareProfile: &armcompute.HardwareProfile{
122132
VMSize: to.Ptr(armcompute.VirtualMachineSizeTypes(size)),

mantle/platform/api/azure/options.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ type Options struct {
2525
AzureCredentials string
2626
AzureSubscription string
2727

28-
DiskURI string
29-
Publisher string
30-
Offer string
31-
Sku string
32-
Version string
33-
Size string
34-
Location string
35-
AvailabilityZone string
28+
DiskURI string
29+
Publisher string
30+
Offer string
31+
Sku string
32+
Version string
33+
Size string
34+
Location string
35+
AvailabilityZone string
36+
ManagedIdentityID string
3637

3738
SubscriptionName string
3839
SubscriptionID string

0 commit comments

Comments
 (0)