Skip to content

Commit

Permalink
add ux for workload identity for cloud provider azure
Browse files Browse the repository at this point in the history
Signed-off-by: Ashutosh Kumar <[email protected]>
  • Loading branch information
sonasingh46 committed Oct 16, 2023
1 parent b7de934 commit 4bf0aa8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ type AzureSharedGalleryImage struct {
}

// VMIdentity defines the identity of the virtual machine, if configured.
// +kubebuilder:validation:Enum=None;SystemAssigned;UserAssigned
// +kubebuilder:validation:Enum=None;SystemAssigned;UserAssigned;WorkloadIdentity
type VMIdentity string

const (
Expand All @@ -544,6 +544,8 @@ const (
VMIdentitySystemAssigned VMIdentity = "SystemAssigned"
// VMIdentityUserAssigned ...
VMIdentityUserAssigned VMIdentity = "UserAssigned"
// VMIdentityWorkloadIdentity ...
VMIdentityWorkloadIdentity VMIdentity = "WorkloadIdentity"
)

// SpotEvictionPolicy defines the eviction policy for spot VMs, if configured.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ spec:
- None
- SystemAssigned
- UserAssigned
- WorkloadIdentity
type: string
location:
description: Location is the Azure region location e.g. westus2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ spec:
- None
- SystemAssigned
- UserAssigned
- WorkloadIdentity
type: string
image:
description: Image is used to provide details of an image to use during
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ spec:
- None
- SystemAssigned
- UserAssigned
- WorkloadIdentity
type: string
image:
description: Image is used to provide details of an image
Expand Down
25 changes: 25 additions & 0 deletions controllers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const (
deprecatedManagerCredsWarning = "You're using deprecated functionality: " +
"Using Azure credentials from the manager environment is deprecated and will be removed in future releases. " +
"Please specify an AzureClusterIdentity for the AzureCluster instead, see: https://capz.sigs.k8s.io/topics/multitenancy.html "
// ToDo: Find a way to make this configurable for a user.
// This is the path where the projected service account token should be present for
// cloud provider azure.
aadFederatedTokenFilePath = "/var/run/secrets/azure/tokens/azure-identity-token" //nolint:gosec // Path of projected service account token
)

type (
Expand Down Expand Up @@ -203,6 +207,8 @@ func GetCloudProviderSecret(d azure.ClusterScoper, namespace, name string, owner
controlPlaneConfig, workerNodeConfig = userAssignedIdentityCloudProviderConfig(d, userIdentityID)
case infrav1.VMIdentityNone:
controlPlaneConfig, workerNodeConfig = newCloudProviderConfig(d)
case infrav1.VMIdentityWorkloadIdentity:
controlPlaneConfig, workerNodeConfig = workloadIdentityCloudProviderConfig(d)

Check warning on line 211 in controllers/helpers.go

View check run for this annotation

Codecov / codecov/patch

controllers/helpers.go#L210-L211

Added lines #L210 - L211 were not covered by tests
}

// Enable VMSS Flexible nodes if MachinePools are enabled
Expand Down Expand Up @@ -245,6 +251,19 @@ func systemAssignedIdentityCloudProviderConfig(d azure.ClusterScoper) (cpConfig
return controlPlaneConfig, workerConfig
}

func workloadIdentityCloudProviderConfig(d azure.ClusterScoper) (cpConfig *CloudProviderConfig, wkConfig *CloudProviderConfig) {
controlPlaneConfig, workerConfig := newCloudProviderConfig(d)
// secret is not needed in workload identity.
controlPlaneConfig.AadClientSecret = ""
controlPlaneConfig.UseFederatedWorkloadIdentityExtension = true
controlPlaneConfig.AADFederatedTokenFile = aadFederatedTokenFilePath

workerConfig.AadClientSecret = ""
workerConfig.UseFederatedWorkloadIdentityExtension = true
workerConfig.AADFederatedTokenFile = aadFederatedTokenFilePath
return controlPlaneConfig, workerConfig

Check warning on line 264 in controllers/helpers.go

View check run for this annotation

Codecov / codecov/patch

controllers/helpers.go#L254-L264

Added lines #L254 - L264 were not covered by tests
}

func userAssignedIdentityCloudProviderConfig(d azure.ClusterScoper, identityID string) (cpConfig *CloudProviderConfig, wkConfig *CloudProviderConfig) {
controlPlaneConfig, workerConfig := newCloudProviderConfig(d)
controlPlaneConfig.AadClientID = ""
Expand Down Expand Up @@ -343,6 +362,12 @@ type CloudProviderConfig struct {
UseInstanceMetadata bool `json:"useInstanceMetadata"`
EnableVmssFlexNodes bool `json:"enableVmssFlexNodes,omitempty"`
UserAssignedIdentityID string `json:"userAssignedIdentityID,omitempty"`
// AADFederatedTokenFile is the path of AAD federated token file
// Cloud provider azure should be deployed by projecting service account
// token volume as part of their pod spec
AADFederatedTokenFile string `json:"aadFederatedTokenFile,omitempty"`
// Use workload identity federation for the virtual machine to access Azure ARM APIs
UseFederatedWorkloadIdentityExtension bool `json:"useFederatedWorkloadIdentityExtension,omitempty"`
CloudProviderRateLimitConfig
BackOffConfig
}
Expand Down

0 comments on commit 4bf0aa8

Please sign in to comment.