Skip to content

Commit 4a3da7b

Browse files
authored
Use common OIDC token env vars for identity live tests (Azure#47869)
1 parent 896afed commit 4a3da7b

File tree

6 files changed

+32
-29
lines changed

6 files changed

+32
-29
lines changed

eng/pipelines/templates/jobs/live.tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ parameters:
5757
- name: UseFederatedAuth
5858
type: boolean
5959
default: true
60+
- name: PersistOidcToken
61+
type: boolean
62+
default: false
6063

6164
jobs:
6265
- job:
@@ -142,6 +145,7 @@ jobs:
142145
SubscriptionConfiguration: $(SubscriptionConfiguration)
143146
ArmTemplateParameters: $(ArmTemplateParameters)
144147
UseFederatedAuth: ${{ parameters.UseFederatedAuth }}
148+
PersistOidcToken: ${{ parameters.PersistOidcToken }}
145149
ServiceConnection: ${{ parameters.CloudConfig.ServiceConnection }}
146150
SubscriptionConfigurationFilePaths: ${{ parameters.CloudConfig.SubscriptionConfigurationFilePaths }}
147151
EnvVars:
@@ -197,6 +201,8 @@ jobs:
197201
env:
198202
AZURE_TEST_MODE: $(TestMode)
199203
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
204+
${{ if parameters.PersistOidcToken }}:
205+
ARM_OIDC_TOKEN: $(ARM_OIDC_TOKEN)
200206
${{ each var in parameters.EnvVars }}:
201207
${{ var.key }}: ${{ var.value }}
202208

eng/pipelines/templates/stages/archetype-sdk-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ parameters:
103103
- name: UseFederatedAuth
104104
type: boolean
105105
default: true
106+
- name: PersistOidcToken
107+
type: boolean
108+
default: false
106109

107110
extends:
108111
template: /eng/pipelines/templates/stages/1es-redirect.yml
@@ -143,6 +146,7 @@ extends:
143146
TestSetupSteps: ${{ parameters.TestSetupSteps }}
144147
DeployTestResources: ${{ parameters.DeployTestResources }}
145148
UseFederatedAuth: ${{ parameters.UseFederatedAuth }}
149+
PersistOidcToken: ${{ parameters.PersistOidcToken }}
146150
MatrixConfigs:
147151
# Enumerate platforms and additional platforms based on supported clouds (sparse platform<-->cloud matrix).
148152
- ${{ each config in parameters.MatrixConfigs }}:

sdk/identity/Azure.Identity/tests/ManagedIdentityAKSIntegrationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public ManagedIdentityAKSIntegrationTests(bool isAsync) : base(isAsync)
2121

2222
public void SetupKubernetesEnvironment()
2323
{
24-
string sp = Environment.GetEnvironmentVariable("ARM_CLIENT_ID");
25-
string tenant = Environment.GetEnvironmentVariable("ARM_TENANT_ID");
24+
string sp = Environment.GetEnvironmentVariable("IDENTITY_CLIENT_ID");
25+
string tenant = Environment.GetEnvironmentVariable("IDENTITY_TENANT_ID");
2626
string oidc = Environment.GetEnvironmentVariable("ARM_OIDC_TOKEN");
2727
string rg = Environment.GetEnvironmentVariable("IDENTITY_RESOURCE_GROUP");
2828
string aks = Environment.GetEnvironmentVariable("IDENTITY_AKS_CLUSTER_NAME");

sdk/identity/test-resources-pre.ps1

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ param (
88
[ValidatePattern('^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$')]
99
[string] $TestApplicationId,
1010

11-
[Parameter()]
12-
[string] $TestApplicationSecret,
11+
[Parameter(Mandatory = $true)]
12+
[ValidateNotNullOrEmpty()]
13+
[string] $Environment,
1314

14-
[Parameter(ParameterSetName = 'Provisioner', Mandatory = $true)]
15+
[Parameter(Mandatory = $true)]
1516
[ValidateNotNullOrEmpty()]
1617
[string] $TenantId
1718
)
@@ -23,9 +24,11 @@ $sshKey = Get-Content $PSScriptRoot/sshKey.pub
2324

2425
$templateFileParameters['sshPubKey'] = $sshKey
2526

26-
# Get the max version that is not preview and then get the name of the patch version with the max value
27+
az cloud set --name $Environment
2728
az login --service-principal -u $TestApplicationId --tenant $TenantId --allow-no-subscriptions --federated-token $env:ARM_OIDC_TOKEN
28-
$versions = az aks get-versions -l westus -o json | ConvertFrom-Json
29+
# Get the max version that is not preview and then get the name of the patch version with the max value
30+
$region = if ($Environment -eq 'AzureUSGovernment') { 'usgovvirginia' } elseif ($Environment -eq 'AzureChinaCloud') { 'chinanorth3' } else { 'westus' }
31+
$versions = az aks get-versions -l $region -o json | ConvertFrom-Json
2932
Write-Host "AKS versions: $($versions | ConvertTo-Json -Depth 100)"
3033
$patchVersions = $versions.values | Where-Object { $_.isPreview -eq $null } | Select-Object -ExpandProperty patchVersions
3134
Write-Host "AKS patch versions: $($patchVersions | ConvertTo-Json -Depth 100)"
@@ -61,4 +64,4 @@ Write-Host "##vso[task.setvariable variable=IDENTITY_SP_CERT_SNI;]$sniPath"
6164
# Set for local
6265
$env:IDENTITY_SP_CERT_PFX = $pfxPath
6366
$env:IDENTITY_SP_CERT_PEM = $pemPath
64-
$env:IDENTITY_SP_CERT_SNI = $sniPath
67+
$env:IDENTITY_SP_CERT_SNI = $sniPath

sdk/identity/test-resources.bicep

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
@description('The client OID to grant access to test resources.')
22
param testApplicationOid string
33

4+
@description('The client ID to grant access to test resources.')
5+
param testApplicationId string
6+
7+
@description('The tenant ID to grant access to test resources.')
8+
param tenantId string
9+
410
@minLength(6)
511
@maxLength(50)
612
@description('The base resource name.')
@@ -235,7 +241,7 @@ resource newCluster 'Microsoft.ContainerService/managedClusters@2023-06-01' = {
235241
{
236242
name: 'agentpool'
237243
count: 1
238-
vmSize: 'Standard_D2s_v3'
244+
vmSize: 'Standard_D2s_v4'
239245
osDiskSizeGB: 128
240246
osDiskType: 'Managed'
241247
kubeletDiskType: 'OS'
@@ -268,6 +274,8 @@ resource newCluster 'Microsoft.ContainerService/managedClusters@2023-06-01' = {
268274
}
269275
}
270276

277+
output IDENTITY_TENANT_ID string = tenantId
278+
output IDENTITY_CLIENT_ID string = testApplicationId
271279
output IDENTITY_WEBAPP_NAME string = web.name
272280
output IDENTITY_USER_DEFINED_IDENTITY string = usermgdid.id
273281
output IDENTITY_USER_DEFINED_IDENTITY_CLIENT_ID string = usermgdid.properties.clientId

sdk/identity/tests.yml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,8 @@ trigger: none
33
extends:
44
template: /eng/pipelines/templates/stages/archetype-sdk-tests.yml
55
parameters:
6-
PreSteps:
7-
- task: AzureCLI@2
8-
displayName: Set OIDC variables
9-
env:
10-
ARM_OIDC_TOKEN: $(ARM_OIDC_TOKEN)
11-
ARM_CLIENT_ID: $(ARM_CLIENT_ID)
12-
ARM_TENANT_ID: $(ARM_TENANT_ID)
13-
inputs:
14-
azureSubscription: azure-sdk-tests
15-
scriptType: pscore
16-
scriptLocation: inlineScript
17-
addSpnToEnvironment: true
18-
inlineScript: |
19-
Write-Host "##vso[task.setvariable variable=ARM_CLIENT_ID;issecret=true]$($env:servicePrincipalId)"
20-
Write-Host "##vso[task.setvariable variable=ARM_TENANT_ID;issecret=true]$($env:tenantId)"
21-
Write-Host "##vso[task.setvariable variable=ARM_OIDC_TOKEN;issecret=true]$($env:idToken)"
226
TimeoutInMinutes: 120
7+
PersistOidcToken: true
238
AdditionalMatrixConfigs:
249
- Name: identity_msi
2510
Path: sdk/identity/platform-matrix.json
@@ -28,10 +13,7 @@ extends:
2813
ServiceDirectory: identity
2914
CloudConfig:
3015
Public:
16+
Location: westus2
3117
SubscriptionConfigurations:
3218
# Contains alternate tenant, AAD app and cert info for testing
3319
- $(sub-config-identity-test-resources)
34-
EnvVars:
35-
ARM_OIDC_TOKEN: $(ARM_OIDC_TOKEN)
36-
ARM_CLIENT_ID: $(ARM_CLIENT_ID)
37-
ARM_TENANT_ID: $(ARM_TENANT_ID)

0 commit comments

Comments
 (0)