Skip to content

Commit 06bbcd8

Browse files
authored
Merge pull request Azure#4166 from Azure/hawkowl/ARO-15999
[ARO-15999] Initial stab at using workload identity
2 parents 141b59a + 70ff9eb commit 06bbcd8

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/env/msiauthorizer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,18 @@ const (
2020
MSIContextGateway MSIContext = "GATEWAY"
2121
)
2222

23+
const EnvUseWorkloadIdentity = "ARO_RP_WORKLOAD_IDENTITY"
24+
2325
func (c *core) NewMSITokenCredential() (azcore.TokenCredential, error) {
2426
if !c.IsLocalDevelopmentMode() {
27+
// If ARO_RP_WORKLOAD_IDENTITY is set, use a WorkloadIdentity credential
28+
// for RP authentication to FPSP keyvault instead
29+
useWorkloadIdentity := os.Getenv(EnvUseWorkloadIdentity)
30+
if useWorkloadIdentity != "" {
31+
options := c.Environment().WorkloadIdentityCredentialOptions()
32+
return azidentity.NewWorkloadIdentityCredential(options)
33+
}
34+
2535
options := c.Environment().ManagedIdentityCredentialOptions()
2636
return azidentity.NewManagedIdentityCredential(options)
2737
}

pkg/util/azureclient/environments.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ func (e *AROEnvironment) ManagedIdentityCredentialOptions() *azidentity.ManagedI
149149
}
150150
}
151151

152+
func (e *AROEnvironment) WorkloadIdentityCredentialOptions() *azidentity.WorkloadIdentityCredentialOptions {
153+
return &azidentity.WorkloadIdentityCredentialOptions{
154+
ClientOptions: e.AzureClientOptions(),
155+
}
156+
}
157+
152158
func (e *AROEnvironment) AzureClientOptions() azcore.ClientOptions {
153159
return azcore.ClientOptions{
154160
Cloud: e.Cloud,

0 commit comments

Comments
 (0)