Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added retries to federated token fetching #19902

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tasks/AzureCloudPowerShellDeploymentV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 240,
"Patch": 2
"Patch": 4
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCloudPowerShellDeploymentV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 240,
"Patch": 2
"Patch": 4
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCloudPowerShellDeploymentV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 2,
"Minor": 240,
"Patch": 2
"Patch": 4
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCloudPowerShellDeploymentV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 2,
"Minor": 240,
"Patch": 2
"Patch": 4
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 240,
"Patch": 4
"Patch": 6
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 1,
"Minor": 240,
"Patch": 4
"Patch": 6
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 240,
"Patch": 6
"Patch": 8
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 240,
"Patch": 6
"Patch": 8
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 3,
"Minor": 240,
"Patch": 6
"Patch": 8
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 3,
"Minor": 240,
"Patch": 6
"Patch": 8
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 4,
"Minor": 240,
"Patch": 6
"Patch": 8
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 4,
"Minor": 240,
"Patch": 6
"Patch": 8
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV5/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 5,
"Minor": 240,
"Patch": 6
"Patch": 8
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV5/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 5,
"Minor": 240,
"Patch": 6
"Patch": 8
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV6/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 6,
"Minor": 240,
"Patch": 8
"Patch": 10
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureFileCopyV6/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 6,
"Minor": 240,
"Patch": 8
"Patch": 10
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 2,
"Minor": 240,
"Patch": 3
"Patch": 4
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 2,
"Minor": 240,
"Patch": 3
"Patch": 4
},
"demands": [
"azureps"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 3,
"Minor": 240,
"Patch": 3
"Patch": 4
},
"releaseNotes": "Added support for Fail on standard error and ErrorActionPreference",
"demands": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV3/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 3,
"Minor": 240,
"Patch": 3
"Patch": 4
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"demands": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV4/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 240,
"Patch": 4
"Patch": 6
},
"releaseNotes": "Added support for Az Module and cross platform agents.",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV4/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 4,
"Minor": 240,
"Patch": 4
"Patch": 6
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV5/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 5,
"Minor": 240,
"Patch": 4
"Patch": 6
},
"releaseNotes": "Added support for Az Module and cross platform agents.",
"groups": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzurePowerShellV5/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 5,
"Minor": 240,
"Patch": 4
"Patch": 6
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"groups": [
Expand Down
43 changes: 26 additions & 17 deletions Tasks/Common/VstsAzureHelpers_/Utility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,29 @@ function Get-VstsFederatedToken {
$hub = Get-VstsTaskVariable -Name 'System.HostType' -Require
$projectId = Get-VstsTaskVariable -Name 'System.TeamProjectId' -Require

$tokenResponse = $taskHttpClient.CreateOidcTokenAsync(
$projectId,
$hub,
$planId,
$jobId,
$connectedServiceNameARM,
$null
).Result
$federatedToken = $tokenResponse.OidcToken
if ($null -eq $federatedToken) {
Write-Verbose "Failed to create OIDC token."
throw (New-Object System.Exception(Get-VstsLocString -Key AZ_CouldNotGenerateOidcToken))
}
return $federatedToken
$timeToWait = 4000
for (($retryAttempt = 1), ($retryLimit = 3); $retryAttempt -le $retryLimit; $retryAttempt++) {
$tokenResponse = $taskHttpClient.CreateOidcTokenAsync(
$projectId,
$hub,
$planId,
$jobId,
$connectedServiceNameARM,
$null
).Result
$federatedToken = $tokenResponse.OidcToken
if ($null -ne $federatedToken) {
return $federatedToken
}

if ($retryAttempt -lt $retryLimit) {
Write-Verbose "Failed to fetch federated token. Remaining retries count = '$($retryLimit - $retryAttempt)'"
Start-Sleep -m $timeToWait * $retryAttempt
}
}

Write-Verbose "Failed to create OIDC token."
throw (New-Object System.Exception(Get-VstsLocString -Key AZ_CouldNotGenerateOidcToken))
}

function Set-UserAgent {
Expand Down Expand Up @@ -591,7 +600,7 @@ function Add-AzureStackAzureRmEnvironment {
AzureKeyVaultServiceEndpointResourceId = $AzureKeyVaultServiceEndpointResourceId
EnableAdfsAuthentication = $aadAuthorityEndpoint.TrimEnd("/").EndsWith("/adfs", [System.StringComparison]::OrdinalIgnoreCase)
}

if ($featureFlags.retireAzureRM)
{
$azureEnvironmentParams.StorageEndpoint = $StorageEndpointSuffix
Expand All @@ -607,7 +616,7 @@ function Add-AzureStackAzureRmEnvironment {

if($null -ne $armEnv) {
Write-Verbose "Updating Az environment $name" -Verbose

if (CmdletHasMember -cmdlet Remove-AzEnvironment -memberName Force) {
Remove-AzEnvironment -Name $name -Force | Out-Null
}
Expand All @@ -625,7 +634,7 @@ function Add-AzureStackAzureRmEnvironment {

if($null -ne $armEnv) {
Write-Verbose "Updating AzureRm environment $name" -Verbose

if (CmdletHasMember -cmdlet Remove-AzureRmEnvironment -memberName Force) {
Remove-AzureRmEnvironment -Name $name -Force | Out-Null
}
Expand Down
2 changes: 1 addition & 1 deletion Tasks/SqlAzureDacpacDeploymentV1/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 240,
"Patch": 4
"Patch": 6
},
"demands": [
"sqlpackage"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/SqlAzureDacpacDeploymentV1/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 1,
"Minor": 240,
"Patch": 4
"Patch": 6
},
"demands": [
"sqlpackage"
Expand Down
4 changes: 2 additions & 2 deletions _generated/AzureFileCopyV2.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|2.240.6
Node20_229_2|2.240.7
Default|2.240.8
Node20_229_2|2.240.9
6 changes: 3 additions & 3 deletions _generated/AzureFileCopyV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 240,
"Patch": 6
"Patch": 8
},
"demands": [
"azureps"
Expand Down Expand Up @@ -374,7 +374,7 @@
"ExpiredServicePrincipal": "Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired."
},
"_buildConfigMapping": {
"Default": "2.240.6",
"Node20_229_2": "2.240.7"
"Default": "2.240.8",
"Node20_229_2": "2.240.9"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureFileCopyV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 240,
"Patch": 6
"Patch": 8
},
"demands": [
"azureps"
Expand Down Expand Up @@ -374,7 +374,7 @@
"ExpiredServicePrincipal": "ms-resource:loc.messages.ExpiredServicePrincipal"
},
"_buildConfigMapping": {
"Default": "2.240.6",
"Node20_229_2": "2.240.7"
"Default": "2.240.8",
"Node20_229_2": "2.240.9"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureFileCopyV2_Node20/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 240,
"Patch": 7
"Patch": 9
},
"demands": [
"azureps"
Expand Down Expand Up @@ -378,7 +378,7 @@
"ExpiredServicePrincipal": "Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired."
},
"_buildConfigMapping": {
"Default": "2.240.6",
"Node20_229_2": "2.240.7"
"Default": "2.240.8",
"Node20_229_2": "2.240.9"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureFileCopyV2_Node20/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"version": {
"Major": 2,
"Minor": 240,
"Patch": 7
"Patch": 9
},
"demands": [
"azureps"
Expand Down Expand Up @@ -378,7 +378,7 @@
"ExpiredServicePrincipal": "ms-resource:loc.messages.ExpiredServicePrincipal"
},
"_buildConfigMapping": {
"Default": "2.240.6",
"Node20_229_2": "2.240.7"
"Default": "2.240.8",
"Node20_229_2": "2.240.9"
}
}
4 changes: 2 additions & 2 deletions _generated/AzureFileCopyV3.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|3.240.6
Node20_229_2|3.240.7
Default|3.240.8
Node20_229_2|3.240.9
Loading
Loading