Skip to content

Commit 33da488

Browse files
authored
Merge pull request Azure#6272 from cormacpayne/update-new-sp
Revert default role assignment for New-AzureRmADServicePrincipal
2 parents f0e0cbf + 25fb72a commit 33da488

File tree

18 files changed

+5952
-359
lines changed

18 files changed

+5952
-359
lines changed

ChangeLog.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
## 6.1.0 - May 2018
1+
## 6.1.1 - May 2018
2+
#### AzureRM.Resources
3+
* Revert change to `New-AzureRmADServicePrincipal` that gave service principals `Contributor` permissions over the current subscription if no values were provided for the `Role` or `Scope` parameters
4+
- If no values are provided for `Role` or `Scope`, the service principal is created with no permissions
5+
- If a `Role` is provided, but no `Scope`, the service principal is created with the specified `Role` permissions over the current subscription
6+
- If a `Scope` is provided, but no `Role`, the service principal is created with `Contributor` permissions over the specified `Scope`
7+
- If both `Role` and `Scope` are provided, the service principal is created with the specified `Role` permissions over the specified `Scope`
8+
9+
## 6.1.0 - May 2018
210
#### AzureRM.Profile
311
* Fix issue where running 'Clear-AzureRmContext' would keep an empty context with the name of the previous default context, which prevented the user from creating a new context with the old name
412

src/Common/Commands.Common/AzurePowerShell.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public class AzurePowerShell
2626

2727
public const string AssemblyCopyright = "Copyright © Microsoft";
2828

29-
public const string AssemblyVersion = "6.0.0";
29+
public const string AssemblyVersion = "6.1.1";
3030

31-
public const string AssemblyFileVersion = "6.0.0";
31+
public const string AssemblyFileVersion = "6.1.1";
3232

3333
public const string ProfileFile = "AzureProfile.json";
3434

src/ResourceManager/Resources/AzureRM.Resources.psd1

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# RootModule = ''
1313

1414
# Version number of this module.
15-
ModuleVersion = '6.0.0'
15+
ModuleVersion = '6.0.1'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -164,21 +164,11 @@ PrivateData = @{
164164
# IconUri = ''
165165

166166
# ReleaseNotes of this module
167-
ReleaseNotes = '* Set minimum dependency of module to PowerShell 5.0
168-
* Remove obsolete parameter -AtScopeAndBelow from Get-AzureRmRoledefinition call
169-
* Include assignments to deleted Users/Groups/ServicePrincipals in Get-AzureRmRoleAssignment result
170-
* Add convenience cmdlet for creating ServicePrincipals
171-
* Add Tab completers for Scope and ResourceType
172-
* Merge Get- and Find- functionality in Get-AzureRmResource
173-
* Add AD Cmdlets:
174-
- Remove-AzureRmADGroupMember
175-
- Get-AzureRmADGroup
176-
- New-AzureRmADGroup
177-
- Remove-AzureRmADGroup
178-
- Remove-AzureRmADUser
179-
- Update-AzureRmADApplication
180-
- Update-AzureRmADServicePrincipal
181-
- Update-AzureRmADUser'
167+
ReleaseNotes = '* Revert change to `New-AzureRmADServicePrincipal` that gave service principals `Contributor` permissions over the current subscription if no values were provided for the `Role` or `Scope` parameters
168+
- If no values are provided for `Role` or `Scope`, the service principal is created with no permissions
169+
- If a `Role` is provided, but no `Scope`, the service principal is created with the specified `Role` permissions over the current subscription
170+
- If a `Scope` is provided, but no `Role`, the service principal is created with `Contributor` permissions over the specified `Scope`
171+
- If both `Role` and `Scope` are provided, the service principal is created with the specified `Role` permissions over the specified `Scope`'
182172

183173
# Prerelease string of this module
184174
# Prerelease = ''

src/ResourceManager/Resources/ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
## Current Release
2121
* Fix issue with `Properties` property of `PSResource` object(s) returned from `Get-AzureRmResource`
2222

23+
## Version 6.0.1
24+
* Revert change to `New-AzureRmADServicePrincipal` that gave service principals `Contributor` permissions over the current subscription if no values were provided for the `Role` or `Scope` parameters
25+
- If no values are provided for `Role` or `Scope`, the service principal is created with no permissions
26+
- If a `Role` is provided, but no `Scope`, the service principal is created with the specified `Role` permissions over the current subscription
27+
- If a `Scope` is provided, but no `Role`, the service principal is created with `Contributor` permissions over the specified `Scope`
28+
- If both `Role` and `Scope` are provided, the service principal is created with the specified `Role` permissions over the specified `Scope`
29+
2330
## Version 6.0.0
2431
* Set minimum dependency of module to PowerShell 5.0
2532
* Remove obsolete parameter -AtScopeAndBelow from Get-AzureRmRoledefinition call

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
[assembly: ComVisible(false)]
2626
[assembly: CLSCompliant(false)]
2727
[assembly: Guid("e8f34267-c461-4eae-b156-5f3528553d10")]
28-
[assembly: AssemblyVersion("6.0.0")]
29-
[assembly: AssemblyFileVersion("6.0.0")]
28+
[assembly: AssemblyVersion("6.0.1")]
29+
[assembly: AssemblyFileVersion("6.0.1")]
3030
#if SIGN
3131
[assembly: InternalsVisibleTo("Microsoft.Azure.Commands.Resources.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
3232
[assembly: InternalsVisibleTo("Microsoft.Azure.Commands.MachineLearning.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]

src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,15 @@
363363
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ActiveDirectoryTests\TestGetADUserWithMail.json">
364364
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
365365
</None>
366+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ActiveDirectoryTests\TestNewADServicePrincipalWithCustomScope.json">
367+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
368+
</None>
366369
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ActiveDirectoryTests\TestNewADServicePrincipalWithoutApp.json">
367370
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
368371
</None>
372+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ActiveDirectoryTests\TestNewADServicePrincipalWithReaderRole.json">
373+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
374+
</None>
369375
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestCrossResourceGroupDeploymentFromTemplateFile.json">
370376
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
371377
</None>

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ActiveDirectoryTests.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,27 @@ public void TestNewADApplication()
599599
ResourcesController.NewInstance.RunPsTest("Test-NewADApplication");
600600
}
601601

602-
[Fact(Skip = "Need AD team to re-record test")]
602+
[Fact]
603603
[Trait(Category.AcceptanceType, Category.CheckIn)]
604604
public void TestNewADServicePrincipalWithoutApp()
605605
{
606606
ResourcesController.NewInstance.RunPsTest("Test-NewADServicePrincipalWithoutApp");
607607
}
608608

609+
[Fact]
610+
[Trait(Category.AcceptanceType, Category.CheckIn)]
611+
public void TestNewADServicePrincipalWithReaderRole()
612+
{
613+
ResourcesController.NewInstance.RunPsTest("Test-NewADServicePrincipalWithReaderRole");
614+
}
615+
616+
[Fact]
617+
[Trait(Category.AcceptanceType, Category.CheckIn)]
618+
public void TestNewADServicePrincipalWithCustomScope()
619+
{
620+
ResourcesController.NewInstance.RunPsTest("Test-NewADServicePrincipalWithCustomScope");
621+
}
622+
609623
[Fact(Skip = "Not working in playback.")]
610624
[Trait(Category.AcceptanceType, Category.CheckIn)]
611625
public void TestCreateDeleteAppPasswordCredentials()

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ActiveDirectoryTests.ps1

Lines changed: 91 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ function Test-GetAllADGroups
3333
.SYNOPSIS
3434
Tests getting Active Directory groups.
3535
#>
36-
function Test-GetADGroupWithSearchString
36+
function Test-GetADGroupWithSearchString
3737
{
3838
param([string]$displayName)
39-
39+
4040
# Test
4141
# Select at most 10 groups. Groups are restricted to contain "test" to fasten the test
4242
$groups = Get-AzureRmADGroup -SearchString $displayName
@@ -68,7 +68,7 @@ Tests getting Active Directory groups.
6868
function Test-GetADGroupWithObjectId
6969
{
7070
param([string]$objectId)
71-
71+
7272
# Test
7373
$groups = Get-AzureRmADGroup -ObjectId $objectId
7474

@@ -85,7 +85,7 @@ Tests getting Active Directory group with security enabled .
8585
function Test-GetADGroupSecurityEnabled
8686
{
8787
param([string]$objectId, [string]$securityEnabled)
88-
88+
8989
# Test
9090
$groups = Get-AzureRmADGroup -ObjectId $objectId
9191

@@ -134,8 +134,8 @@ function Test-GetADGroupMemberWithGroupObjectId
134134

135135
# Test
136136
$members = Get-AzureRmADGroupMember -GroupObjectId $groupObjectId
137-
138-
# Assert
137+
138+
# Assert
139139
Assert-AreEqual $members.Count 1
140140
Assert-AreEqual $members[0].Id $userObjectId
141141
Assert-AreEqual $members[0].DisplayName $userName
@@ -148,7 +148,7 @@ Tests getting members from an Active Directory group.
148148
function Test-GetADGroupMemberWithBadGroupObjectId
149149
{
150150
# Test
151-
Assert-Throws { Get-AzureRmADGroupMember -GroupObjectId "baadc0de-baad-c0de-baad-c0debaadc0de" }
151+
Assert-Throws { Get-AzureRmADGroupMember -GroupObjectId "baadc0de-baad-c0de-baad-c0debaadc0de" }
152152
}
153153

154154
<#
@@ -160,7 +160,7 @@ function Test-GetADGroupMemberWithUserObjectId
160160
param([string]$objectId)
161161

162162
# Test
163-
Assert-Throws { Get-AzureRmADGroupMember -GroupObjectId $objectId }
163+
Assert-Throws { Get-AzureRmADGroupMember -GroupObjectId $objectId }
164164
}
165165

166166
<#
@@ -173,8 +173,8 @@ function Test-GetADGroupMemberFromEmptyGroup
173173

174174
# Test
175175
$members = Get-AzureRmADGroupMember -GroupObjectId $objectId
176-
177-
# Assert
176+
177+
# Assert
178178
Assert-Null($members)
179179
}
180180

@@ -462,7 +462,7 @@ function Test-NewADApplication
462462

463463
# Assert
464464
Assert-NotNull $application
465-
$apps = Get-AzureRmADApplication
465+
$apps = Get-AzureRmADApplication
466466
Assert-NotNull $apps
467467
Assert-True { $apps.Count -ge 0 }
468468

@@ -489,13 +489,13 @@ function Test-NewADApplication
489489
$newDisplayName = getAssetName
490490
$newHomePage = "http://" + $newDisplayName + ".com"
491491
$newIdentifierUri = "http://" + $newDisplayName
492-
492+
493493
# Update displayName and HomePage
494494
Set-AzureRmADApplication -ObjectId $application.ObjectId -DisplayName $newDisplayName -HomePage $newHomePage
495495

496-
# Update identifierUri
496+
# Update identifierUri
497497
Set-AzureRmADApplication -ApplicationId $application.ApplicationId -IdentifierUris $newIdentifierUri
498-
498+
499499
# Get application and verify updated properties
500500
$app1 = Get-AzureRmADApplication -ObjectId $application.ObjectId
501501
Assert-NotNull $app1
@@ -504,7 +504,7 @@ function Test-NewADApplication
504504
Assert-AreEqual $app1.HomePage $newHomePage
505505
Assert-AreEqual $app1.IdentifierUris[0] $newIdentifierUri
506506

507-
# Delete
507+
# Delete
508508
Remove-AzureRmADApplication -ObjectId $application.ObjectId -Force
509509
}
510510

@@ -543,16 +543,18 @@ function Test-NewADServicePrincipal
543543
Tests Creating and deleting service principal without an exisitng application.
544544
#>
545545
function Test-NewADServicePrincipalWithoutApp
546-
{
546+
{
547547
# Setup
548548
$displayName = getAssetName
549549

550550
# Test
551551
$servicePrincipal = New-AzureRmADServicePrincipal -DisplayName $displayName
552+
$role = Get-AzureRmRoleAssignment -ObjectId $servicePrincipal.Id
552553

553554
# Assert
554555
Assert-NotNull $servicePrincipal
555556
Assert-AreEqual $servicePrincipal.DisplayName $displayName
557+
Assert-Null $role
556558

557559
# GetServicePrincipal by ObjectId
558560
$sp1 = Get-AzureRmADServicePrincipal -ObjectId $servicePrincipal.Id
@@ -573,7 +575,7 @@ function Test-NewADServicePrincipalWithoutApp
573575

574576
# update SP displayName
575577
$newDisplayName = getAssetName
576-
578+
577579
Set-AzureRmADServicePrincipal -ObjectId $servicePrincipal.Id -DisplayName $newDisplayName
578580

579581
# Get SP and verify updated name
@@ -588,12 +590,78 @@ function Test-NewADServicePrincipalWithoutApp
588590
Assert-Throws { Remove-AzureRmADServicePrincipal -ObjectId $servicePrincipal.Id -Force}
589591
}
590592

593+
<#
594+
.SYNOPSIS
595+
Tests creating a service principal with reader permissions
596+
#>
597+
function Test-NewADServicePrincipalWithReaderRole
598+
{
599+
# Setup
600+
$displayName = getAssetName
601+
$roleDefinitionName = "Reader"
602+
603+
# Test
604+
$servicePrincipal = New-AzureRmADServicePrincipal -DisplayName $displayName -Role $roleDefinitionName
605+
Assert-NotNull $servicePrincipal
606+
Assert-AreEqual $servicePrincipal.DisplayName $displayName
607+
608+
try
609+
{
610+
$role = Get-AzureRmRoleAssignment -ObjectId $servicePrincipal.Id
611+
Assert-AreEqual $role.Count 1
612+
Assert-AreEqual $role.DisplayName $servicePrincipal.DisplayName
613+
Assert-AreEqual $role.ObjectId $servicePrincipal.Id
614+
Assert-AreEqual $role.RoleDefinitionName $roleDefinitionName
615+
Assert-AreEqual $role.ObjectType "ServicePrincipal"
616+
}
617+
finally
618+
{
619+
Remove-AzureRmADApplication -ApplicationId $servicePrincipal.ApplicationId -Force
620+
Remove-AzureRmRoleAssignment -ObjectId $servicePrincipal.Id -RoleDefinitionName $roleDefinitionName
621+
}
622+
}
623+
624+
<#
625+
.SYNOPSIS
626+
Tests creating a service principal with permissions over a custom scope
627+
#>
628+
function Test-NewADServicePrincipalWithCustomScope
629+
{
630+
# Setup
631+
$displayName = getAssetName
632+
$defaultRoleDefinitionName = "Contributor"
633+
$subscription = Get-AzureRmSubscription | Select -Last 1 -Wait
634+
$resourceGroup = Get-AzureRmResourceGroup | Select -Last 1 -Wait
635+
$scope = "/subscriptions/" + $subscription.Id + "/resourceGroups/" + $resourceGroup.ResourceGroupName
636+
637+
# Test
638+
$servicePrincipal = New-AzureRmADServicePrincipal -DisplayName $displayName -Scope $scope
639+
Assert-NotNull $servicePrincipal
640+
Assert-AreEqual $servicePrincipal.DisplayName $displayName
641+
642+
try
643+
{
644+
$role = Get-AzureRmRoleAssignment -ObjectId $servicePrincipal.Id
645+
Assert-AreEqual $role.Count 1
646+
Assert-AreEqual $role.DisplayName $servicePrincipal.DisplayName
647+
Assert-AreEqual $role.ObjectId $servicePrincipal.Id
648+
Assert-AreEqual $role.RoleDefinitionName $defaultRoleDefinitionName
649+
Assert-AreEqual $role.Scope $scope
650+
Assert-AreEqual $role.ObjectType "ServicePrincipal"
651+
}
652+
finally
653+
{
654+
Remove-AzureRmADApplication -ApplicationId $servicePrincipal.ApplicationId -Force
655+
Remove-AzureRmRoleAssignment -ObjectId $servicePrincipal.Id -Scope $scope -RoleDefinitionName $defaultRoleDefinitionName
656+
}
657+
}
658+
591659
<#
592660
.SYNOPSIS
593661
Tests Creating and deleting application using Password Credentials.
594662
#>
595663
function Test-CreateDeleteAppPasswordCredentials
596-
{
664+
{
597665
# Setup
598666
$displayName = getAssetName
599667
$identifierUri = "http://" + $displayName
@@ -629,7 +697,7 @@ function Test-CreateDeleteAppPasswordCredentials
629697

630698
# Remove cred by KeyId
631699
Remove-AzureRmADAppCredential -ApplicationId $application.ApplicationId -KeyId $cred.KeyId -Force
632-
$cred3 = Get-AzureRmADAppCredential -ApplicationId $application.ApplicationId
700+
$cred3 = Get-AzureRmADAppCredential -ApplicationId $application.ApplicationId
633701
Assert-NotNull $cred3
634702
Assert-AreEqual $cred3.Count 1
635703
Assert-AreEqual $cred3[0].KeyId $cred1.KeyId
@@ -642,7 +710,7 @@ function Test-CreateDeleteAppPasswordCredentials
642710
$newApplication = Get-AzureRmADApplication -DisplayNameStartWith "PowershellTestingApp"
643711
Assert-Throws { New-AzureRmADAppCredential -ApplicationId $newApplication.ApplicationId -Password "Somedummypwd"}
644712

645-
# Remove App
713+
# Remove App
646714
Remove-AzureRmADApplication -ObjectId $application.ObjectId -Force
647715
}
648716

@@ -652,7 +720,7 @@ function Test-CreateDeleteAppPasswordCredentials
652720
Tests Creating and deleting application using Service Principal Credentials.
653721
#>
654722
function Test-CreateDeleteSpPasswordCredentials
655-
{
723+
{
656724
# Setup
657725
$displayName = getAssetName
658726
$password = getAssetName
@@ -689,7 +757,7 @@ function Test-CreateDeleteSpPasswordCredentials
689757

690758
# Remove cred by KeyId
691759
Remove-AzureRmADSpCredential -ServicePrincipalName $servicePrincipal.ServicePrincipalNames[0] -KeyId $cred.KeyId -Force
692-
$cred3 = Get-AzureRmADSpCredential -ServicePrincipalName $servicePrincipal.ServicePrincipalNames[0]
760+
$cred3 = Get-AzureRmADSpCredential -ServicePrincipalName $servicePrincipal.ServicePrincipalNames[0]
693761
Assert-NotNull $cred3
694762
Assert-AreEqual $cred3.Count 1
695763
Assert-AreEqual $cred3[0].KeyId $cred1.KeyId
@@ -701,7 +769,7 @@ function Test-CreateDeleteSpPasswordCredentials
701769
}
702770
Finally
703771
{
704-
# Remove App
772+
# Remove App
705773
$app = Get-AzureRmADApplication -ApplicationId $servicePrincipal.ApplicationId
706774
Remove-AzureRmADApplication -ObjectId $app.ObjectId -Force
707775
}

0 commit comments

Comments
 (0)