Skip to content

Commit c2487dd

Browse files
authored
Use WIF rather than PAT for push to azure-public/vs-impl feed (#9496)
* Use WIF rather than PAT for push to azure-public/vs-impl feed
1 parent 9c9efad commit c2487dd

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed
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"

eng/pipelines/templates/build-official-release.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ jobs:
8282
displayName: Publish Nuget Packages to azure-publish
8383
packagesToPush: $(Build.SourcesDirectory)/artifacts/$(BuildConfiguration)/packages/*.nupkg
8484
packageParentPath: $(Build.SourcesDirectory)/artifacts/$(BuildConfiguration)/packages
85-
publishVstsFeed: DevDiv/vs-green
8685
publishFeedCredentials: azure-public/vs-impl
8786
allowPackageConflicts: true
8887
nuGetFeedType: external
@@ -269,12 +268,9 @@ jobs:
269268
!bin\Dlls\net472\Setup.dll
270269
!SymStore\**
271270
!VSSetup\Insertion\bootstrapper\**\vs_enterprise.exe
272-
273-
274-
# Authenticate with a service connection to be able to publish packages to external (different DevOps organization) NuGet feeds.
275-
# See: https://docs.microsoft.com/azure/devops/pipelines/tasks/package/nuget-authenticate?view=azure-devops
276-
# This connecction is used in the templateContext nuget outputs.
277-
- task: NuGetAuthenticate@1
278-
displayName: Authenticate NuGet
279-
inputs:
280-
nuGetServiceConnections: azure-public/vs-impl
271+
272+
- template: WIFtoPATauth.yml
273+
parameters:
274+
wifServiceConnectionName: azure-public/vside package push
275+
deadPATServiceConnectionId: 207efd62-fd0f-43e7-aeae-17c4febcc660 # azure-public/vs-impl
276+

0 commit comments

Comments
 (0)