Skip to content

Commit f030c4c

Browse files
authored
ci: Use ODIC and TME for test-templates (#4522)
This change reworks the `test-templates` test legs to use OIDC and move to our TME subscription. To do so, we capture the relevent `AZURESUBSCRIPTION_` environment variables that are set by the AzureCLI task and then flow them into the dev container when we run tests. This allows us to do `azd auth login` inside the devcontainer but still use OIDC so we don't have a long lived secret. The call to `az login` was removed because we don't yet have a way to have this work well with ODIC in the container. This means the terraform flavor of the tests won't work (since auth is broken) but these legs have been broken in both the bicep and terraform flavors for a while, so this moves us in a better direction (and gets us off of client secrets and onto TME for these tests). Contributes To #4341
1 parent 9d71912 commit f030c4c

File tree

2 files changed

+30
-45
lines changed

2 files changed

+30
-45
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
parameters:
2+
ServiceConnectionName: "azd-service-connection"
3+
4+
steps:
5+
- task: AzureCLI@2
6+
condition: and(succeeded(), ne(variables['Skip.LiveTest'], 'true'))
7+
inputs:
8+
azureSubscription: ${{ parameters.ServiceConnectionName }}
9+
scriptType: pscore
10+
scriptLocation: inlineScript
11+
inlineScript: |
12+
Write-Host "##vso[task.setvariable variable=AzureSubscriptionClientId;issecret=false]$($env:AZURESUBSCRIPTION_CLIENT_ID)"
13+
Write-Host "##vso[task.setvariable variable=AzureSubscriptionTenantId;issecret=false]$($env:AZURESUBSCRIPTION_TENANT_ID)"
14+
Write-Host "##vso[task.setvariable variable=AzureSubscriptionServiceConnectionId;issecret=false]$($env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID)"
15+
Write-Host "##vso[task.setvariable variable=SubscriptionId;issecret=false]$((az account show -o json | ConvertFrom-Json -AsHashtable)['id'])"
16+
displayName: Configure OIDC Authentication

eng/pipelines/templates/steps/template-test-run-job.yml

+14-45
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ steps:
1212
parameters:
1313
Version: $(AzdVersion)
1414

15-
- template: /eng/pipelines/templates/steps/azd-login.yml
16-
17-
# Java pre-requisites that isn't met
18-
# TODO: Use azd container as a form of validation that the container works
19-
- template: /eng/pipelines/templates/steps/install-ms-openjdk.yml
20-
2115
# Required to clone repos that are not yet public
2216
- template: /eng/pipelines/templates/steps/set-git-credentials.yml
2317

18+
- template: /eng/pipelines/templates/steps/configure-oidc-auth.yml
19+
2420
- pwsh: |
2521
# Get the name without any path
2622
$template = '$(TemplateName)'
@@ -69,29 +65,18 @@ steps:
6965
- task: DevcontainersCI@0
7066
inputs:
7167
env: |
72-
# Required secrets for Terraform service principal authentication
73-
# $(arm-*) secrets are set by azd-login.yml
74-
ARM_CLIENT_ID=$(arm-client-id-test-tenant)
75-
ARM_CLIENT_SECRET=$(arm-client-secret-test-tenant)
76-
ARM_TENANT_ID=$(arm-tenant-id-test-tenant)
77-
SUBSCRIPTION_ID=$(SubscriptionId-test-tenant)
68+
# Service Connection Configuration
69+
AZURESUBSCRIPTION_CLIENT_ID=$(AzureSubscriptionClientId)
70+
AZURESUBSCRIPTION_TENANT_ID=$(AzureSubscriptionTenantId)
71+
AZURESUBSCRIPTION_SERVICE_CONNECTION_ID=$(AzureSubscriptionServiceConnectionId)
72+
SYSTEM_ACCESSTOKEN=$(System.AccessToken)
73+
SYSTEM_OIDCREQUESTURI=$(System.OidcRequestUri)
7874
7975
# Pass in TemplateRunEnvironmentVariables
8076
$(VARIABLE_LIST)
8177
82-
# Bash Script parameters
83-
BRANCH_NAME=$(TemplateBranchName)
84-
ENV_NAME_PREFIX=$(EnvPrefixName)
85-
TEMPLATE_NAME=$(TemplateName)
86-
VALIDATE=$(TemplateName)
87-
PLAYWRIGHT_REPORTER='list'
88-
LOCATION=$(AzureLocation)
89-
SUBSCRIPTION=$(SubscriptionId-test-tenant)
90-
ENV_SUFFIX=$(Build.BuildId)-$(System.JobAttempt)
91-
CLEANUP=$(SynchronousCleanup)
92-
93-
AZD_VERSION=$(AzdVersion)
94-
AZD_DEBUG_FORCE_NO_TTY="1"
78+
# Force no TTY in CI
79+
AZD_DEBUG_FORCE_NO_TTY=1
9580
subFolder: "$(Build.SourcesDirectory)/temp"
9681
runCmd: |
9782
# Uninstall azd version
@@ -113,23 +98,7 @@ steps:
11398
azd version
11499
115100
# Login azd
116-
azd auth login \
117-
--client-id "$(arm-client-id-test-tenant)" \
118-
--client-secret "$(arm-client-secret-test-tenant)" \
119-
--tenant-id "$(arm-tenant-id-test-tenant)"
120-
121-
# Login az CLI (required for scenarios where az is invoked)
122-
az login \
123-
--service-principal \
124-
-u "$(arm-client-id-test-tenant)" \
125-
-p="$(arm-client-secret-test-tenant)" \
126-
--tenant "$(arm-tenant-id-test-tenant)"
127-
128-
# set default sub for az to be the same used by azd
129-
az account set --subscription "$(SubscriptionId-test-tenant)"
130-
131-
# enable alpha features
132-
azd config set alpha.all on
101+
azd auth login --federated-credential-provider azure-pipelines
133102
134103
# Install these packages for playwright tests. Otherwise, it will cause a error of playwright missing libraries
135104
sudo add-apt-repository ppa:gstreamer-developers/ppa
@@ -143,21 +112,21 @@ steps:
143112
-e '$(EnvPrefixName)' \
144113
-t '$(TemplateName)' \
145114
-b '$(TemplateBranchName)' \
146-
-s '$(SubscriptionId-test-tenant)' \
115+
-s '$(SubscriptionId)' \
147116
-u '$(Build.BuildId)-$(System.JobAttempt)' \
148117
-l '$(AzureLocation)' \
149118
-p 'list' \
150119
-c '$(SynchronousCleanup)' \
151120
-v "$RUN_VALIDATION" \
152121
153-
displayName: Test templates in Devcontainer
122+
displayName: Run template-test.sh in Devcontainer
154123

155124
# First tag the resource group (if exists) so that it can get cleaned up
156125
# by the cleanup pipeline. Then attempt to delete the resource group
157126
# directly. If the delete fails the cleanup pipeline will delete it.
158127
- task: AzureCLI@2
159128
inputs:
160-
azureSubscription: azure-sdk-tests
129+
azureSubscription: azd-service-connection
161130
keepAzSessionActive: true
162131
scriptType: pscore
163132
scriptLocation: inlineScript

0 commit comments

Comments
 (0)