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 AZURESUBSCRIPTION_CLIENT_ID and AZURESUBSCRIPTION_TENANT_ID env vars #19818

Merged
merged 2 commits into from
Apr 26, 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
19 changes: 13 additions & 6 deletions Tasks/AzureCLIV2/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export class azureclitask {
var connectedService: string = tl.getInput("connectedServiceNameARM", true);
await this.loginAzureRM(connectedService);

process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = connectedService;

let errLinesCount: number = 0;
let aggregatedErrorLines: string[] = [];
tool.on('errline', (errorLine: string) => {
Expand Down Expand Up @@ -125,7 +123,12 @@ export class azureclitask {
this.logoutAzure();
}

process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = '';
if (process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID && process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID !== "")
{
process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = '';
process.env.AZURESUBSCRIPTION_CLIENT_ID = '';
process.env.AZURESUBSCRIPTION_TENANT_ID = '';
}
}
}

Expand All @@ -151,9 +154,13 @@ export class azureclitask {
//login using OpenID Connect federation
Utility.throwIfError(tl.execSync("az", args), tl.loc("LoginFailed"));

this.servicePrincipalId = servicePrincipalId;
this.federatedToken = federatedToken;
this.tenantId = tenantId;
this.servicePrincipalId = servicePrincipalId;
this.federatedToken = federatedToken;
this.tenantId = tenantId;

process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = connectedService;
process.env.AZURESUBSCRIPTION_CLIENT_ID = servicePrincipalId;
process.env.AZURESUBSCRIPTION_TENANT_ID = tenantId;
}
else if (authScheme.toLowerCase() == "serviceprincipal") {
let authType: string = tl.getEndpointAuthorizationParameter(connectedService, 'authenticationType', true);
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLIV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 239,
"Patch": 0
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureCLIV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 239,
"Patch": 0
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down
7 changes: 6 additions & 1 deletion Tasks/AzurePowerShellV5/AzurePowerShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ finally {
. "$PSScriptRoot\Utility.ps1"
Import-Module "$PSScriptRoot\ps_modules\VstsAzureHelpers_"
Remove-EndpointSecrets
$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = ''
Update-PSModulePathForHostedAgent
Disconnect-AzureAndClearContext -restrictContext 'True' -ErrorAction SilentlyContinue

if ($env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID) {
$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = ""
$env:AZURESUBSCRIPTION_CLIENT_ID = ""
$env:AZURESUBSCRIPTION_TENANT_ID = ""
}
}
6 changes: 5 additions & 1 deletion Tasks/AzurePowerShellV5/CoreAz.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ $encryptedToken = ConvertTo-SecureString $vstsAccessToken -AsPlainText -Force
Initialize-AzModule -Endpoint $endpointObject -connectedServiceNameARM $connectedServiceNameARM `
-azVersion $targetAzurePs -isPSCore $isPSCore -encryptedToken $encryptedToken

$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = $connectedServiceNameARM
if ($vstsAccessToken) {
$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = $connectedServiceNameARM
$env:AZURESUBSCRIPTION_CLIENT_ID = $endpointObject.servicePrincipalClientID
$env:AZURESUBSCRIPTION_TENANT_ID = $endpointObject.tenantId
}
2 changes: 2 additions & 0 deletions Tasks/AzurePowerShellV5/InitializeAz.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ elseif ($endpointObject.scheme -eq 'WorkloadIdentityFederation') {
}

$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = $serviceConnectionId
$env:AZURESUBSCRIPTION_CLIENT_ID = $endpointObject.servicePrincipalClientID
$env:AZURESUBSCRIPTION_TENANT_ID = $endpointObject.tenantId
}
else {
# Provide an additional, custom, credentials-related error message. Will handle localization later
Expand Down
8 changes: 7 additions & 1 deletion Tasks/AzurePowerShellV5/RemoveAzContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
. "$PSScriptRoot/ps_modules/VstsAzureHelpers_/Utility.ps1"

Update-PSModulePathForHostedAgentLinux
Disconnect-AzureAndClearContext -restrictContext 'True'
Disconnect-AzureAndClearContext -restrictContext 'True'

if ($env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID) {
$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = ""
$env:AZURESUBSCRIPTION_CLIENT_ID = ""
$env:AZURESUBSCRIPTION_TENANT_ID = ""
}
2 changes: 0 additions & 2 deletions Tasks/AzurePowerShellV5/azurepowershell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ async function run() {
.arg('-Command')
.arg(`. '${path.join(path.resolve(__dirname),'RemoveAzContext.ps1')}'`);

process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = '';

let options = <tr.IExecOptions>{
cwd: input_workingDirectory,
failOnStdErr: false,
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": 239,
"Patch": 6
"Patch": 8
},
"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": 239,
"Patch": 6
"Patch": 8
},
"releaseNotes": "ms-resource:loc.releaseNotes",
"groups": [
Expand Down
4 changes: 2 additions & 2 deletions _generated/AzureCLIV2.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|2.239.0
Node20_229_2|2.239.1
Default|2.239.2
Node20_229_2|2.239.3
19 changes: 13 additions & 6 deletions _generated/AzureCLIV2/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export class azureclitask {
var connectedService: string = tl.getInput("connectedServiceNameARM", true);
await this.loginAzureRM(connectedService);

process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = connectedService;

let errLinesCount: number = 0;
let aggregatedErrorLines: string[] = [];
tool.on('errline', (errorLine: string) => {
Expand Down Expand Up @@ -125,7 +123,12 @@ export class azureclitask {
this.logoutAzure();
}

process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = '';
if (process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID && process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID !== "")
{
process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = '';
process.env.AZURESUBSCRIPTION_CLIENT_ID = '';
process.env.AZURESUBSCRIPTION_TENANT_ID = '';
}
}
}

Expand All @@ -151,9 +154,13 @@ export class azureclitask {
//login using OpenID Connect federation
Utility.throwIfError(tl.execSync("az", args), tl.loc("LoginFailed"));

this.servicePrincipalId = servicePrincipalId;
this.federatedToken = federatedToken;
this.tenantId = tenantId;
this.servicePrincipalId = servicePrincipalId;
this.federatedToken = federatedToken;
this.tenantId = tenantId;

process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = connectedService;
process.env.AZURESUBSCRIPTION_CLIENT_ID = servicePrincipalId;
process.env.AZURESUBSCRIPTION_TENANT_ID = tenantId;
}
else if (authScheme.toLowerCase() == "serviceprincipal") {
let authType: string = tl.getEndpointAuthorizationParameter(connectedService, 'authenticationType', true);
Expand Down
6 changes: 3 additions & 3 deletions _generated/AzureCLIV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 239,
"Patch": 0
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down Expand Up @@ -204,7 +204,7 @@
"ExpiredServicePrincipalMessageWithLink": "Secret expired, update service connection at\u00A0%s See\u00A0https://aka.ms/azdo-rm-workload-identity-conversion to learn more about conversion to secret-less service connections."
},
"_buildConfigMapping": {
"Default": "2.239.0",
"Node20_229_2": "2.239.1"
"Default": "2.239.2",
"Node20_229_2": "2.239.3"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureCLIV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 239,
"Patch": 0
"Patch": 2
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down Expand Up @@ -204,7 +204,7 @@
"ExpiredServicePrincipalMessageWithLink": "ms-resource:loc.messages.ExpiredServicePrincipalMessageWithLink"
},
"_buildConfigMapping": {
"Default": "2.239.0",
"Node20_229_2": "2.239.1"
"Default": "2.239.2",
"Node20_229_2": "2.239.3"
}
}
19 changes: 13 additions & 6 deletions _generated/AzureCLIV2_Node20/azureclitask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export class azureclitask {
var connectedService: string = tl.getInput("connectedServiceNameARM", true);
await this.loginAzureRM(connectedService);

process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = connectedService;

let errLinesCount: number = 0;
let aggregatedErrorLines: string[] = [];
tool.on('errline', (errorLine: string) => {
Expand Down Expand Up @@ -125,7 +123,12 @@ export class azureclitask {
this.logoutAzure();
}

process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = '';
if (process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID && process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID !== "")
{
process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = '';
process.env.AZURESUBSCRIPTION_CLIENT_ID = '';
process.env.AZURESUBSCRIPTION_TENANT_ID = '';
}
}
}

Expand All @@ -151,9 +154,13 @@ export class azureclitask {
//login using OpenID Connect federation
Utility.throwIfError(tl.execSync("az", args), tl.loc("LoginFailed"));

this.servicePrincipalId = servicePrincipalId;
this.federatedToken = federatedToken;
this.tenantId = tenantId;
this.servicePrincipalId = servicePrincipalId;
this.federatedToken = federatedToken;
this.tenantId = tenantId;

process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = connectedService;
process.env.AZURESUBSCRIPTION_CLIENT_ID = servicePrincipalId;
process.env.AZURESUBSCRIPTION_TENANT_ID = tenantId;
}
else if (authScheme.toLowerCase() == "serviceprincipal") {
let authType: string = tl.getEndpointAuthorizationParameter(connectedService, 'authenticationType', true);
Expand Down
6 changes: 3 additions & 3 deletions _generated/AzureCLIV2_Node20/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 239,
"Patch": 1
"Patch": 3
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "Azure CLI $(scriptPath)",
Expand Down Expand Up @@ -208,7 +208,7 @@
"ExpiredServicePrincipalMessageWithLink": "Secret expired, update service connection at\u00A0%s See\u00A0https://aka.ms/azdo-rm-workload-identity-conversion to learn more about conversion to secret-less service connections."
},
"_buildConfigMapping": {
"Default": "2.239.0",
"Node20_229_2": "2.239.1"
"Default": "2.239.2",
"Node20_229_2": "2.239.3"
}
}
6 changes: 3 additions & 3 deletions _generated/AzureCLIV2_Node20/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"version": {
"Major": 2,
"Minor": 239,
"Patch": 1
"Patch": 3
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down Expand Up @@ -208,7 +208,7 @@
"ExpiredServicePrincipalMessageWithLink": "ms-resource:loc.messages.ExpiredServicePrincipalMessageWithLink"
},
"_buildConfigMapping": {
"Default": "2.239.0",
"Node20_229_2": "2.239.1"
"Default": "2.239.2",
"Node20_229_2": "2.239.3"
}
}
4 changes: 2 additions & 2 deletions _generated/AzurePowerShellV5.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|5.239.6
Node20_229_2|5.239.7
Default|5.239.8
Node20_229_2|5.239.9
7 changes: 6 additions & 1 deletion _generated/AzurePowerShellV5/AzurePowerShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ finally {
. "$PSScriptRoot\Utility.ps1"
Import-Module "$PSScriptRoot\ps_modules\VstsAzureHelpers_"
Remove-EndpointSecrets
$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = ''
Update-PSModulePathForHostedAgent
Disconnect-AzureAndClearContext -restrictContext 'True' -ErrorAction SilentlyContinue

if ($env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID) {
$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = ""
$env:AZURESUBSCRIPTION_CLIENT_ID = ""
$env:AZURESUBSCRIPTION_TENANT_ID = ""
}
}
6 changes: 5 additions & 1 deletion _generated/AzurePowerShellV5/CoreAz.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ $encryptedToken = ConvertTo-SecureString $vstsAccessToken -AsPlainText -Force
Initialize-AzModule -Endpoint $endpointObject -connectedServiceNameARM $connectedServiceNameARM `
-azVersion $targetAzurePs -isPSCore $isPSCore -encryptedToken $encryptedToken

$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = $connectedServiceNameARM
if ($vstsAccessToken) {
$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = $connectedServiceNameARM
$env:AZURESUBSCRIPTION_CLIENT_ID = $endpointObject.servicePrincipalClientID
$env:AZURESUBSCRIPTION_TENANT_ID = $endpointObject.tenantId
}
2 changes: 2 additions & 0 deletions _generated/AzurePowerShellV5/InitializeAz.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ elseif ($endpointObject.scheme -eq 'WorkloadIdentityFederation') {
}

$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = $serviceConnectionId
$env:AZURESUBSCRIPTION_CLIENT_ID = $endpointObject.servicePrincipalClientID
$env:AZURESUBSCRIPTION_TENANT_ID = $endpointObject.tenantId
}
else {
# Provide an additional, custom, credentials-related error message. Will handle localization later
Expand Down
8 changes: 7 additions & 1 deletion _generated/AzurePowerShellV5/RemoveAzContext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
. "$PSScriptRoot/ps_modules/VstsAzureHelpers_/Utility.ps1"

Update-PSModulePathForHostedAgentLinux
Disconnect-AzureAndClearContext -restrictContext 'True'
Disconnect-AzureAndClearContext -restrictContext 'True'

if ($env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID) {
$env:AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = ""
$env:AZURESUBSCRIPTION_CLIENT_ID = ""
$env:AZURESUBSCRIPTION_TENANT_ID = ""
}
2 changes: 0 additions & 2 deletions _generated/AzurePowerShellV5/azurepowershell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ async function run() {
.arg('-Command')
.arg(`. '${path.join(path.resolve(__dirname),'RemoveAzContext.ps1')}'`);

process.env.AZURESUBSCRIPTION_SERVICE_CONNECTION_ID = '';

let options = <tr.IExecOptions>{
cwd: input_workingDirectory,
failOnStdErr: false,
Expand Down
6 changes: 3 additions & 3 deletions _generated/AzurePowerShellV5/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"version": {
"Major": 5,
"Minor": 239,
"Patch": 6
"Patch": 8
},
"releaseNotes": "Added support for Az Module and cross platform agents.",
"groups": [
Expand Down Expand Up @@ -204,7 +204,7 @@
"PS_ExitCode": "PowerShell exited with code '{0}'."
},
"_buildConfigMapping": {
"Default": "5.239.6",
"Node20_229_2": "5.239.7"
"Default": "5.239.8",
"Node20_229_2": "5.239.9"
}
}
Loading