Set-AzureRmSqlServerThreatDetectionPolicy with a storage in different subscription
Description
Hi,
I notice that with Set-AzureRmSqlServerThreatDetectionPolicy we can't use a storage account located in a different subscription. Altought, it's possible with Set-AzureRmSqlServerAuditing where there are a StorageAccountSubscriptionId arguments. It's really missing
Script/Steps for Reproduction
Just try to setup SQL threat detection with Set-AzureRmSqlServerThreatDetectionPolicy by using a storage account in a different subscription.
Set-AzureRmSqlServerThreatDetectionPolicy -ResourceGroupName $RG -ServerName $sql -EmailAdmins $false -RetentionInDays "90" -StorageAccountName storageinothersub
Module Version
Get-Module -Name AzureRM -ListAvailable
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 6.4.0 AzureRM
Script 6.0.1 AzureRM
Script 5.7.0 AzureRM
Script 5.4.1 AzureRM
Script 5.1.1 AzureRM
Environment Data
$PSVersionTable
Name Value
---- -----
PSVersion 5.1.17134.165
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.165
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Debug Output
Set-AzureRmSqlServerThreatDetectionPolicy : Cannot find a storage account with the name 'storageinothersub'. It either does not exist, associated with a different subscription or you do not have the appropriate credentials to access
it.
At line:1 char:1
+ Set-AzureRmSqlServerThreatDetectionPolicy -ResourceGroupName $RG ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureRmSqlS...DetectionPolicy], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Sql.ThreatDetection.Cmdlet.SetAzureSqlServerThreatDetection
@alex-3sr You might want to consider removing some older versions of the modules from yoru box - it looks like you have 5 versiosn simultaneously installed.
I think the real solution here is to use a resource id for the storage account - would this work for your scenario?
@markcowl , yes using ResourceId is clearly enough For my point of view, using same arguments from Set-AzureRmSqlServerAuditing is better, cause we usually set theses 2 settings at same time, and so it could be more clear. But BTW, if it do the job, it's ok for me ;) Thanks
Ps : Yes, i need clean up some older version :)
@jaredmoo Can you take alook?
@ayeletshpigelman Can you take a look at this?
It is by design since the user doesn't supply the storage key. We allow enabling ADS policy without storage account using Enable-AzSqlServerAdvancedDataSecurity command. Moreover, I will add an option to run Set-AzureRmSqlServerThreatDetectionPolicy without storage account since it is supported in the backend.