Skip to content

Commit c54c766

Browse files
IliasKhaniliaskhaisra-fel
authored
[SQL] umi support for auditing (#20750)
* umi support for auditing * updated changelog * added null check * Update ChangeLog.md --------- Co-authored-by: Ilias Khan <[email protected]> Co-authored-by: Yeming Liu <[email protected]>
1 parent 2b5fb75 commit c54c766

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/Sql/Sql/Auditing/Services/AuditingEndpointsCommunicator.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,15 @@ public DiagnosticSettingsResource UpdateDiagnosticSettings(DiagnosticSettingsRes
223223
public Guid? AssignServerIdentityIfNotAssigned(string resourceGroupName, string serverName)
224224
{
225225
var server = GetCurrentSqlClient().Servers.Get(resourceGroupName, serverName);
226-
if (server.Identity == null ||
227-
server.Identity.Type != ResourceIdentityType.SystemAssigned.ToString())
226+
if (server.Identity == null)
228227
{
229228
server.Identity = ResourceIdentityHelper.GetIdentityObjectFromType(true, ResourceIdentityType.SystemAssigned.ToString(), null, null);
230229
server = GetCurrentSqlClient().Servers.CreateOrUpdate(resourceGroupName, serverName, server);
231230
}
231+
else if (server.Identity.Type != null && server.Identity.Type.Contains("UserAssigned"))
232+
{
233+
return null;
234+
}
232235

233236
return server.Identity.PrincipalId;
234237
}

src/Sql/Sql/Auditing/Services/SqlAuditAdapter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ internal virtual void PolicizeStorageInfo(AuditModelType model, ProxyResource po
352352
if (AzureCommunicator.IsStorageAccountInVNet(model.StorageAccountResourceId) || model.UseIdentity == BoolType.True)
353353
{
354354
Guid? principalId = Communicator.AssignServerIdentityIfNotAssigned(model.ResourceGroupName, model.ServerName);
355-
AzureCommunicator.AssignRoleForServerIdentityOnStorageIfNotAssigned(model.StorageAccountResourceId, principalId.Value, RoleAssignmentId);
355+
if (principalId != null)
356+
{
357+
AzureCommunicator.AssignRoleForServerIdentityOnStorageIfNotAssigned(model.StorageAccountResourceId, principalId.Value, RoleAssignmentId);
358+
}
356359
}
357360
else
358361
{

src/Sql/Sql/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020
## Upcoming Release
2121
* Added an optional parameter `HAReplicaCount` to `Restore-AzSqlDatabase`
22+
* Enabled support for UserAssignedManagedIdentity in Auditing
2223

2324
## Version 4.2.0
2425
* Added a parameter named `UseIdentity` for `Set-AzSqlServerAudit`, `Set-AzSqlDatabaseAudit`, `Set-AzSqlServerMSSupportAudit`

0 commit comments

Comments
 (0)