Skip to content

Commit 1460bc8

Browse files
author
Filiz Topatan
committed
Make blueprint object optional for blueprint assignment done with an assignment JSON file./n Parse assignment object to determine the assignment type to decide if we should go through the code path of owner role assignment for Blueprint SPN. Only go through the role assignment if the assignment has system assigned identity defined.
1 parent ed28cba commit 1460bc8

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/Blueprint/Blueprint/Cmdlets/BlueprintAssignment/BlueprintAssignmentCmdletBase.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,21 @@ protected void ThrowIfAssignmentNotExist(string scope, string name)
240240
throw new Exception(string.Format(Resources.AssignmentNotExist, name, scope));
241241
}
242242
}
243+
244+
/// <summary>
245+
/// Checks if an assignment uses user assigned identity.
246+
/// </summary>
247+
/// <param name="identity"></param>
248+
/// <returns></returns>
249+
protected bool IsUserAssignedIdentity(ManagedServiceIdentity identity)
250+
{
251+
if (String.IsNullOrEmpty(identity?.Type))
252+
{
253+
throw new Exception(Resources.IdentityTypeNotProvided);
254+
}
255+
256+
return identity.Type.Equals(ManagedServiceIdentityType.UserAssigned, StringComparison.OrdinalIgnoreCase);
257+
258+
}
243259
}
244260
}

src/Blueprint/Blueprint/Cmdlets/BlueprintAssignment/NewAzureRMBlueprintAssignment.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class NewAzureRmBlueprintAssignment : BlueprintAssignmentCmdletBase
3838
[ValidateNotNullOrEmpty]
3939
public string Name { get; set; }
4040

41-
[Parameter(ParameterSetName = ParameterSetNames.CreateBlueprintAssignmentByFile, Mandatory = true, HelpMessage = BlueprintConstants.ParameterHelpMessages.BlueprintObject)]
41+
[Parameter(ParameterSetName = ParameterSetNames.CreateBlueprintAssignmentByFile, Mandatory = false, HelpMessage = BlueprintConstants.ParameterHelpMessages.BlueprintObject)]
4242
[Parameter(ParameterSetName = ParameterSetNames.CreateBlueprintAssignment, Mandatory = true, ValueFromPipeline = true, HelpMessage = BlueprintConstants.ParameterHelpMessages.BlueprintObject)]
4343
[ValidateNotNull]
4444
public PSBlueprintBase Blueprint { get; set; }
@@ -151,8 +151,15 @@ public override void ExecuteCmdlet()
151151
// Register Blueprint RP
152152
RegisterBlueprintRp(subscription);
153153

154-
if (!this.IsParameterBound(c => c.UserAssignedIdentity))
154+
if (!IsUserAssignedIdentity(assignmentObject.Identity))
155155
{
156+
// If user assigned identity is defined as the identity in the assignment
157+
// we consider the user assigned MSI, otherwise system assigned MSI.
158+
//
159+
// Assign owner permission to Blueprint SPN only if assignment is being done using
160+
// System assigned identity.
161+
// This is a no-op for user assigned identity.
162+
156163
var spnObjectId = GetBlueprintSpn(scope, Name);
157164
AssignOwnerPermission(subscription, spnObjectId);
158165
}

src/Blueprint/Blueprint/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Blueprint/Blueprint/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@
159159
<data name="DeleteBlueprintFolderContentsProcessString" xml:space="preserve">
160160
<value>Folder '{0}' already exists. This operation will replace contents of the folder with specified blueprint and its artifacts. Would you like to continue?</value>
161161
</data>
162+
<data name="IdentityTypeNotProvided" xml:space="preserve">
163+
<value>Can't determine the identity to be used with the assignment. Make sure the assignment file contains Identity property and identity Type property.</value>
164+
</data>
162165
<data name="OverwriteExistingOutputFileContinueMessage" xml:space="preserve">
163166
<value>Overwriting the output file.</value>
164167
</data>

0 commit comments

Comments
 (0)