@@ -19,24 +19,35 @@ param(
1919 [int ]$DaysValid ,
2020
2121 [Parameter (Mandatory = $true )]
22- [string ]$Base64EncodedAuthToken
22+ [string ]$AccessToken
2323)
2424
25+ $unencodedAuthToken = " nobody:$AccessToken "
26+ $unencodedAuthTokenBytes = [System.Text.Encoding ]::UTF8.GetBytes($unencodedAuthToken )
27+ $encodedAuthToken = [System.Convert ]::ToBase64String($unencodedAuthTokenBytes )
28+
29+ # We are doing this here so that there is zero chance that this token is emitted in Azure Pipelines
30+ # build logs. Azure Pipelines will see this text and register the secret as a value it should *** out
31+ # before being transmitted to the server (and shown in logs). It means if the value is accidentally
32+ # leaked anywhere else that it won't be visible. The downside is that when the script is executed
33+ # on a local development box, it will be visible.
34+ Write-Host " ##vso[task.setvariable variable=_throwawayencodedaccesstoken;issecret=true;]$ ( $encodedAuthToken ) "
35+
2536. (Join-Path $PSScriptRoot common.ps1)
2637
2738LogDebug " Checking for existing leases on run: $RunId "
28- $existingLeases = Get-RetentionLeases - Organization $Organization - Project $Project - DefinitionId $DefinitionId - RunId $RunId - OwnerId $OwnerId - Base64EncodedAuthToken $Base64EncodedAuthToken
39+ $existingLeases = Get-RetentionLeases - Organization $Organization - Project $Project - DefinitionId $DefinitionId - RunId $RunId - OwnerId $OwnerId - Base64EncodedAuthToken $encodedAuthToken
2940
3041if ($existingLeases.count -ne 0 ) {
3142 LogDebug " Found $ ( $existingLeases.count ) leases, will delete them first."
3243
3344 foreach ($lease in $existingLeases.value ) {
3445 LogDebug " Deleting lease: $ ( $lease.leaseId ) "
35- Delete- RetentionLease - Organization $Organization - Project $Project - LeaseId $lease.leaseId - Base64EncodedAuthToken $Base64EncodedAuthToken
46+ Delete- RetentionLease - Organization $Organization - Project $Project - LeaseId $lease.leaseId - Base64EncodedAuthToken $encodedAuthToken
3647 }
3748
3849}
3950
4051LogDebug " Creating new lease on run: $RunId "
41- $lease = Add-RetentionLease - Organization $Organization - Project $Project - DefinitionId $DefinitionId - RunId $RunId - OwnerId $OwnerId - DaysValid $DaysValid - Base64EncodedAuthToken $Base64EncodedAuthToken
52+ $lease = Add-RetentionLease - Organization $Organization - Project $Project - DefinitionId $DefinitionId - RunId $RunId - OwnerId $OwnerId - DaysValid $DaysValid - Base64EncodedAuthToken $encodedAuthToken
4253LogDebug " Lease ID is: $ ( $lease.value.leaseId ) "
0 commit comments