Skip to content

Commit b6e207a

Browse files
authored
Authorize azidentity test app deployment with WIF (Azure#23322)
1 parent 76bd6fe commit b6e207a

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

sdk/azidentity/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ extends:
3737
UsePipelineProxy: false
3838

3939
${{ if endsWith(variables['Build.DefinitionName'], 'weekly') }}:
40+
PreSteps:
41+
- task: AzureCLI@2
42+
displayName: Set OIDC token
43+
inputs:
44+
addSpnToEnvironment: true
45+
azureSubscription: azure-sdk-tests
46+
inlineScript: Write-Host "##vso[task.setvariable variable=OIDC_TOKEN;]$($env:idToken)"
47+
scriptLocation: inlineScript
48+
scriptType: pscore
4049
MatrixConfigs:
4150
- Name: managed_identity_matrix
4251
GenerateVMJobs: true

sdk/azidentity/test-resources-post.ps1

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55

66
param (
77
[hashtable] $AdditionalParameters = @{},
8-
[hashtable] $DeploymentOutputs
8+
[hashtable] $DeploymentOutputs,
9+
10+
[Parameter(ParameterSetName = 'Provisioner', Mandatory = $true)]
11+
[ValidateNotNullOrEmpty()]
12+
[string] $TenantId,
13+
14+
[Parameter()]
15+
[ValidatePattern('^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$')]
16+
[string] $TestApplicationId,
17+
18+
# Captures any arguments from eng/New-TestResources.ps1 not declared here (no parameter errors).
19+
[Parameter(ValueFromRemainingArguments = $true)]
20+
$RemainingArguments
921
)
1022

1123
$ErrorActionPreference = 'Stop'
@@ -16,14 +28,14 @@ if ($CI) {
1628
Write-Host "Skipping post-provisioning script because resources weren't deployed"
1729
return
1830
}
19-
az login --service-principal -u $DeploymentOutputs['AZIDENTITY_CLIENT_ID'] -p $DeploymentOutputs['AZIDENTITY_CLIENT_SECRET'] --tenant $DeploymentOutputs['AZIDENTITY_TENANT_ID']
31+
az login --federated-token $env:OIDC_TOKEN --service-principal -t $TenantId -u $TestApplicationId
2032
az account set --subscription $DeploymentOutputs['AZIDENTITY_SUBSCRIPTION_ID']
2133
}
2234

2335
Write-Host "Building container"
2436
$image = "$($DeploymentOutputs['AZIDENTITY_ACR_LOGIN_SERVER'])/azidentity-managed-id-test"
2537
Set-Content -Path "$PSScriptRoot/Dockerfile" -Value @"
26-
FROM mcr.microsoft.com/oss/go/microsoft/golang:latest as builder
38+
FROM mcr.microsoft.com/oss/go/microsoft/golang:latest AS builder
2739
ENV GOARCH=amd64 GOWORK=off
2840
COPY . /azidentity
2941
WORKDIR /azidentity/testdata/managed-id-test
@@ -53,9 +65,9 @@ az container create -g $rg -n $aciName --image $image `
5365
--role "Storage Blob Data Reader" `
5466
--scope $($DeploymentOutputs['AZIDENTITY_STORAGE_ID']) `
5567
-e AZIDENTITY_STORAGE_NAME=$($DeploymentOutputs['AZIDENTITY_STORAGE_NAME']) `
56-
AZIDENTITY_STORAGE_NAME_USER_ASSIGNED=$($DeploymentOutputs['AZIDENTITY_STORAGE_NAME_USER_ASSIGNED']) `
57-
AZIDENTITY_USER_ASSIGNED_IDENTITY=$($DeploymentOutputs['AZIDENTITY_USER_ASSIGNED_IDENTITY']) `
58-
FUNCTIONS_CUSTOMHANDLER_PORT=80
68+
AZIDENTITY_STORAGE_NAME_USER_ASSIGNED=$($DeploymentOutputs['AZIDENTITY_STORAGE_NAME_USER_ASSIGNED']) `
69+
AZIDENTITY_USER_ASSIGNED_IDENTITY=$($DeploymentOutputs['AZIDENTITY_USER_ASSIGNED_IDENTITY']) `
70+
FUNCTIONS_CUSTOMHANDLER_PORT=80
5971
Write-Host "##vso[task.setvariable variable=AZIDENTITY_ACI_NAME;]$aciName"
6072

6173
# Azure Functions deployment: copy the Windows binary from the Docker image, deploy it in a zip

0 commit comments

Comments
 (0)