Skip to content

Commit d85c4e2

Browse files
danieljurekazure-sdk
authored andcommitted
Review feedback and pair with Ben
1 parent 514a874 commit d85c4e2

File tree

4 files changed

+23
-52
lines changed

4 files changed

+23
-52
lines changed

eng/common/TestResources/New-TestResources.ps1

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,10 @@ param (
9292
[Parameter()]
9393
[switch] $SuppressVsoCommands = ($null -eq $env:SYSTEM_TEAMPROJECTID),
9494

95-
# Default behavior is to use -UserAuth
95+
# Default behavior is to use logged in credentials
9696
[Parameter()]
9797
[switch] $ServicePrincipalAuth,
9898

99-
[Parameter()]
100-
[switch] $FederatedAuth,
101-
102-
10399
# Captures any arguments not declared here (no parameter errors)
104100
# This enables backwards compatibility with old script versions in
105101
# hotfix branches if and when the dynamic subscription configuration
@@ -110,19 +106,9 @@ param (
110106

111107
. $PSScriptRoot/SubConfig-Helpers.ps1
112108

113-
if ($FederatedAuth -and $ServicePrincipalAuth) {
114-
Write-Error "Only one of 'FederatedAuth' and 'ServicePrincipalAuth' can be set."
115-
exit 1
116-
}
117-
118-
$UserAuth = $true
119-
if ($ServicePrincipalAuth) {
120-
$UserAuth = $false
121-
}
122-
123-
if ($FederatedAuth) {
124-
# Clear secrets if FederatedAuth is set. This prevents secrets from being
125-
# passed to pre- and post-scripts.
109+
if (!$ServicePrincipalAuth) {
110+
# Clear secrets if not using Service Principal auth. This prevents secrets
111+
# from being passed to pre- and post-scripts.
126112
$PSBoundParameters['TestApplicationSecret'] = $TestApplicationSecret = ''
127113
$PSBoundParameters['ProvisionerApplicationSecret'] = $ProvisionerApplicationSecret = ''
128114
}
@@ -299,7 +285,7 @@ function BuildDeploymentOutputs([string]$serviceName, [object]$azContext, [objec
299285
"AZURE_SERVICE_DIRECTORY" = $serviceName.ToUpperInvariant();
300286
}
301287

302-
if (!$FederatedAuth) {
288+
if ($ServicePrincipalAuth) {
303289
$deploymentOutputs["${serviceDirectoryPrefix}CLIENT_ID"] = $TestApplicationId;
304290
$deploymentOutputs["${serviceDirectoryPrefix}CLIENT_SECRET"] = $TestApplicationSecret;
305291
$deploymentOutputs["${serviceDirectoryPrefix}TENANT_ID"] = $azContext.Tenant.Id;
@@ -543,9 +529,8 @@ try {
543529
}
544530
}
545531

546-
# If a provisioner service principal was provided (and not using Federated
547-
# Auth), log into it to perform the pre- and post-scripts and deployments.
548-
if ($ProvisionerApplicationId -and !$FederatedAuth) {
532+
# If a provisioner service principal was provided log into it to perform the pre- and post-scripts and deployments.
533+
if ($ProvisionerApplicationId -and $ServicePrincipalAuth) {
549534
$null = Disable-AzContextAutosave -Scope Process
550535

551536
Log "Logging into service principal '$ProvisionerApplicationId'."
@@ -640,9 +625,9 @@ try {
640625
}
641626
}
642627

643-
if (!$CI -and !$FederatedAuth -and $UserAuth) {
628+
if (!$CI -and !$ServicePrincipalAuth) {
644629
if ($TestApplicationId) {
645-
Write-Warning "The specified TestApplicationId '$TestApplicationId' will be ignored when UserAuth is set."
630+
Write-Warning "The specified TestApplicationId '$TestApplicationId' will be ignored when -ServicePrincipalAutth is not set."
646631
}
647632

648633
$userAccount = (Get-AzADUser -UserPrincipalName (Get-AzContext).Account)
@@ -712,7 +697,7 @@ try {
712697
# Make sure pre- and post-scripts are passed formerly required arguments.
713698
$PSBoundParameters['TestApplicationId'] = $TestApplicationId
714699
$PSBoundParameters['TestApplicationOid'] = $TestApplicationOid
715-
if (!$FederatedAuth) {
700+
if ($ServicePrincipalAuth) {
716701
$PSBoundParameters['TestApplicationSecret'] = $TestApplicationSecret
717702
}
718703

@@ -732,7 +717,7 @@ try {
732717
# considered a critical failure, as the test application may have subscription-level permissions and not require
733718
# the explicit grant.
734719
if (!$resourceGroupRoleAssigned) {
735-
$idSlug = if ($UserAuth) { "User '$userAccountName' ('$TestApplicationId')" } else { "Test Application '$TestApplicationId'"};
720+
$idSlug = if (!$ServicePrincipalAuth) { "User '$userAccountName' ('$TestApplicationId')" } else { "Test Application '$TestApplicationId'"};
736721
Log "Attempting to assign the 'Owner' role for '$ResourceGroupName' to the $idSlug"
737722
$ownerAssignment = New-AzRoleAssignment `
738723
-RoleDefinitionName "Owner" `
@@ -762,7 +747,7 @@ try {
762747
if ($TenantId) {
763748
$templateParameters.Add('tenantId', $TenantId)
764749
}
765-
if ($TestApplicationSecret -and !$FederatedAuth) {
750+
if ($TestApplicationSecret -and $ServicePrincipalAuth) {
766751
$templateParameters.Add('testApplicationSecret', $TestApplicationSecret)
767752
}
768753

@@ -1044,30 +1029,15 @@ The environment file will be named for the test resources template that it was
10441029
generated for. For ARM templates, it will be test-resources.json.env. For
10451030
Bicep templates, test-resources.bicep.env.
10461031
1047-
.PARAMETER UserAuth
1048-
Create the resource group and deploy the template using the signed in user's credentials.
1049-
No service principal will be created or used.
1050-
1051-
The environment file will be named for the test resources template that it was
1052-
generated for. For ARM templates, it will be test-resources.json.env. For
1053-
Bicep templates, test-resources.bicep.env.
1054-
10551032
.PARAMETER SuppressVsoCommands
10561033
By default, the -CI parameter will print out secrets to logs with Azure Pipelines log
10571034
commands that cause them to be redacted. For CI environments that don't support this (like
10581035
stress test clusters), this flag can be set to $false to avoid printing out these secrets to the logs.
10591036
10601037
.PARAMETER ServicePrincipalAuth
1061-
Use the signed in user's credentials to create a service principal for
1062-
provisioning. This is useful for some local development scenarios.
1063-
1064-
.PARAMETER FederatedAuth
1065-
Use signed in user's credentials for provisioninig. No service principal will be
1066-
created. This is used in CI where the execution context already has a signed in
1067-
user.
1068-
1069-
In cases where provisioner or test applications are specified, secrets for those
1070-
apps will not be exported or made available to pre- or post- scripts.
1038+
Use the provisioner SP credentials to deploy, and pass the test SP credentials
1039+
to tests. If provisioner and test SP are not set, provision an SP with user
1040+
credentials and pass the new SP to tests.
10711041
10721042
.EXAMPLE
10731043
Connect-AzAccount -Subscription 'REPLACE_WITH_SUBSCRIPTION_ID'

eng/common/TestResources/Remove-TestResources.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ param (
5656
[ValidateSet('test', 'perf')]
5757
[string] $ResourceType = 'test',
5858

59+
[Parameter(ParameterSetName = 'Default+Provisioner')]
60+
[Parameter(ParameterSetName = 'ResourceGroup+Provisioner')]
5961
[Parameter()]
60-
[switch] $FederatedAuth,
62+
[switch] $ServicePrincipalAuth,
6163

6264
[Parameter()]
6365
[switch] $Force,
@@ -113,7 +115,7 @@ function Retry([scriptblock] $Action, [int] $Attempts = 5) {
113115
}
114116
}
115117

116-
if ($ProvisionerApplicationId -and !$FederatedAuth) {
118+
if ($ProvisionerApplicationId -and $ServicePrincipalAuth) {
117119
$null = Disable-AzContextAutosave -Scope Process
118120

119121
Log "Logging into service principal '$ProvisionerApplicationId'"
@@ -308,9 +310,8 @@ Run script in CI mode. Infers various environment variable names based on CI con
308310
.PARAMETER Force
309311
Force removal of resource group without asking for user confirmation
310312
311-
.PARAMETER FederatedAuth
312-
Use signed in user's credentials for provisioninig. This is used in CI where
313-
the execution context already has a signed in user.
313+
.PARAMETER ServicePrincipalAuth
314+
Log in with provided Provisioner application credentials.
314315
315316
.EXAMPLE
316317
Remove-TestResources.ps1 keyvault -Force

eng/common/TestResources/deploy-test-resources.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ steps:
6969
@subscriptionConfiguration `
7070
-AdditionalParameters ${{ parameters.ArmTemplateParameters }} `
7171
-CI `
72-
-UseFederatedAuth `
7372
-Force `
7473
-Verbose | Out-Null
7574
@@ -92,6 +91,7 @@ steps:
9291
@subscriptionConfiguration `
9392
-AdditionalParameters ${{ parameters.ArmTemplateParameters }} `
9493
-CI `
94+
-ServicePrincipalAuth `
9595
-Force `
9696
-Verbose | Out-Null
9797
displayName: Deploy test resources

eng/common/TestResources/remove-test-resources.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ steps:
4646
-ServiceDirectory "${{ parameters.ServiceDirectory }}" `
4747
-CI `
4848
-Force `
49-
-UseFederatedAuth `
5049
-Verbose
5150
5251
- ${{ else }}:
@@ -61,6 +60,7 @@ steps:
6160
@subscriptionConfiguration `
6261
-ResourceType '${{ parameters.ResourceType }}' `
6362
-ServiceDirectory "${{ parameters.ServiceDirectory }}" `
63+
-ServicePrincipalAuth `
6464
-CI `
6565
-Force `
6666
-Verbose

0 commit comments

Comments
 (0)