Skip to content

Commit 16b4bc0

Browse files
committed
Switch from PAT-based to WIF-based auth
When pulling from or pushing packages to the `azure-public` account, we need to authenticate when doing so from the `devdiv` account. We were previously doing this through PAT-based service connections. With this change, we switch to WIF (Workload Identity Federation) to authenticate.
1 parent a5fbced commit 16b4bc0

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

azure-pipelines/WIFtoPATauth.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
parameters:
2+
- name: deadPATServiceConnectionId # The GUID of the PAT-based service connection whose access token must be replaced.
3+
type: string
4+
- name: wifServiceConnectionName # The name of the WIF service connection to use to get the access token.
5+
type: string
6+
- name: resource # The scope for which the access token is requested.
7+
type: string
8+
default: 499b84ac-1321-427f-aa17-267ca6975798 # Azure Artifact feeds (any of them)
9+
10+
steps:
11+
- task: AzureCLI@2
12+
displayName: 🔏 Authenticate with WIF service connection
13+
inputs:
14+
azureSubscription: ${{ parameters.wifServiceConnectionName }}
15+
scriptType: pscore
16+
scriptLocation: inlineScript
17+
inlineScript: |
18+
$accessToken = az account get-access-token --query accessToken --resource '${{ parameters.resource }}' -o tsv
19+
# Set the access token as a secret, so it doesn't get leaked in the logs
20+
Write-Host "##vso[task.setsecret]$accessToken"
21+
# Override the apitoken of the nuget service connection, for the duration of this stage
22+
Write-Host "##vso[task.setendpoint id=${{ parameters.deadPATServiceConnectionId }};field=authParameter;key=apitoken]$accessToken"

azure-pipelines/install-dependencies.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
parameters:
2-
initArgs:
2+
- name: initArgs
3+
- name: needsAzurePublicFeeds
4+
type: boolean
5+
default: true # If nuget.config pulls from the azure-public account, we need to authenticate when building on the devdiv account.
36

47
steps:
8+
- ${{ if and(parameters.needsAzurePublicFeeds, eq(variables['system.collectionId'], '011b8bdf-6d56-4f87-be0d-0092136884d9')) }}:
9+
- template: WIFtoPATauth.yml
10+
parameters:
11+
wifServiceConnectionName: azure-public/vside package pull
12+
deadPATServiceConnectionId: 0ae39abc-4d06-4436-a7b5-865833df49db # azure-public/msft_consumption
513

614
- task: NuGetAuthenticate@1
715
displayName: 🔏 Authenticate NuGet feeds
816
inputs:
9-
${{ if eq(variables['system.collectionId'], '011b8bdf-6d56-4f87-be0d-0092136884d9') }}:
10-
nuGetServiceConnections: azure-public/msft_consumption # Only necessary for GitHub-hosted repos
11-
forceReinstallCredentialProvider: true
17+
${{ if and(parameters.needsAzurePublicFeeds, eq(variables['system.collectionId'], '011b8bdf-6d56-4f87-be0d-0092136884d9')) }}:
18+
nuGetServiceConnections: azure-public/msft_consumption
1219

1320
- powershell: |
1421
$AccessToken = '$(System.AccessToken)' # Avoid specifying the access token directly on the init.ps1 command line to avoid it showing up in errors

azure-pipelines/prepare-insertion-stages.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ stages:
6161
- download: current
6262
artifact: deployables-Windows
6363
displayName: 🔻 Download deployables-Windows artifact
64+
- template: WIFtoPATauth.yml
65+
parameters:
66+
wifServiceConnectionName: azure-public/vside package push
67+
deadPATServiceConnectionId: 207efd62-fd0f-43e7-aeae-17c4febcc660 # azure-public/vs-impl

0 commit comments

Comments
 (0)