Skip to content

Commit 627911c

Browse files
committed
Threat Detection new API + data masking changes
1. Adding Threat Detection new Set() and Get() API 2. Data masking - add PrivilegedUsers parameter and deprecate PrivilegedLogins parameter
1 parent ae57582 commit 627911c

File tree

39 files changed

+31566
-8474
lines changed

39 files changed

+31566
-8474
lines changed

ChangeLog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
* Azure Redis Cache
1+
* Azure SQL Database: new cmdlets for managing database threat detection policies:
2+
* Get-AzureRmSqlDatabaseThreatDetectionPolicy
3+
* Set-AzureRmSqlDatabaseThreatDetectionPolicy
4+
5+
* Azure Redis Cache
26
* Set-AzureRedisCache - Premium and vNet support for redis cache
37
* New-AzureRedisCache - Premium and vNet support for redis cache
48

restore.config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<add key="https://www.nuget.org/api/v2/" value="https://www.nuget.org/api/v2/" />
5+
<add key="LocalFeed" value="C:\code\azure-powershell\tools\LocalFeed" />
6+
</packageSources>
7+
<disabledPackageSources />
8+
</configuration>

src/ResourceManager/Sql/AzureRM.Sql.psd1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ AliasesToExport = @(
8282
'Get-AzureRmSqlDatabaseServerAuditingPolicy',
8383
'Remove-AzureRmSqlDatabaseServerAuditing',
8484
'Set-AzureRmSqlDatabaseServerAuditingPolicy',
85-
'Use-AzureRmSqlDatabaseServerAuditingPolicy'
85+
'Use-AzureRmSqlDatabaseServerAuditingPolicy',
86+
'Set-AzureRmSqlDatabaseThreatDetectionPolicy',
87+
'Get-AzureRmSqlDatabaseThreatDetectionPolicy'
8688
)
8789

8890
# List of all modules packaged with this module

src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
<Private>True</Private>
7474
</Reference>
7575
<Reference Include="Microsoft.Azure.Management.Sql">
76-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.39.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
77-
</Reference>
76+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.0.41.0-prerelease\lib\net40\Microsoft.Azure.Management.Sql.dll</HintPath>
77+
</Reference>
7878
<Reference Include="Microsoft.Azure.Management.Storage">
7979
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Storage.2.4.0-preview\lib\net40\Microsoft.Azure.Management.Storage.dll</HintPath>
8080
</Reference>
@@ -189,11 +189,15 @@
189189
<DesignTime>True</DesignTime>
190190
<DependentUpon>Resources.resx</DependentUpon>
191191
</Compile>
192+
<Compile Include="ScenarioTests\ThreatDetectionTests.cs" />
192193
<Compile Include="ScenarioTests\DatabaseActivationTests.cs" />
193194
<Compile Include="ScenarioTests\DatabaseBackupTests.cs" />
194195
<Compile Include="ScenarioTests\DatabaseReplicationTests.cs" />
195196
<Compile Include="ScenarioTests\DatabaseCrudTests.cs" />
196197
<Compile Include="ScenarioTests\DataMaskingTests.cs" />
198+
<None Include="ScenarioTests\ThreatDetectionTests.ps1">
199+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
200+
</None>
197201
<None Include="ScenarioTests\DatabaseReplicationTests.ps1">
198202
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
199203
</None>
@@ -445,7 +449,7 @@
445449
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DataMaskingTests\TestDatabaseDataMaskingNumberRuleLifecycle.json">
446450
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
447451
</None>
448-
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DataMaskingTests\TestDatabaseDataMaskingPrivilegedLoginsChanges.json">
452+
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DataMaskingTests\TestDatabaseDataMaskingPrivilegedUsersChanges.json">
449453
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
450454
</None>
451455
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.DataMaskingTests\TestDatabaseDataMaskingRuleCreationFailures.json">

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/Common.ps1

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ function Get-SqlAuditingTestEnvironmentParameters ($testSuffix)
2525
}
2626
}
2727

28+
<#
29+
.SYNOPSIS
30+
Gets the values of the parameters used at the threat detection tests
31+
#>
32+
function Get-SqlThreatDetectionTestEnvironmentParameters ($testSuffix)
33+
{
34+
return @{ rgname = "sql-td-cmdlet-test-rg" +$testSuffix;
35+
serverName = "sql-td-cmdlet-server" +$testSuffix;
36+
databaseName = "sql-td-cmdlet-db" + $testSuffix;
37+
storageAccount = "tdcmdlets" +$testSuffix
38+
}
39+
}
40+
2841
<#
2942
.SYNOPSIS
3043
Gets the values of the parameters used by the data masking tests
@@ -78,6 +91,30 @@ function Create-TestEnvironmentWithStorageV2 ($testSuffix)
7891
New-AzureRmStorageAccount -Name $params.storageAccount -Location "West US" -ResourceGroupName $params.rgname -Type "Standard_GRS"
7992
}
8093

94+
<#
95+
.SYNOPSIS
96+
Creates the test environment needed to perform the Sql threat detection tests, while using storage V2 as the used storage account
97+
#>
98+
function Create-ThreatDetectionTestEnvironmentWithStorageV2 ($testSuffix, $serverVersion = "12.0")
99+
{
100+
$params = Get-SqlThreatDetectionTestEnvironmentParameters $testSuffix
101+
New-AzureRmResourceGroup -Name $params.rgname -Location "Australia East" -Force
102+
103+
if ($serverVersion -eq "12.0")
104+
{
105+
# Sawa server
106+
New-AzureRmResourceGroupDeployment -ResourceGroupName $params.rgname -TemplateFile ".\Templates\sql-ddm-test-env-setup.json" -serverName $params.serverName -databaseName $params.databaseName -EnvLocation "Australia East" -Force
107+
}
108+
109+
if ($serverVersion -eq "2.0")
110+
{
111+
# Sterling server
112+
New-AzureRmResourceGroupDeployment -ResourceGroupName $params.rgname -TemplateFile ".\Templates\sql-audit-test-env-setup.json" -serverName $params.serverName -databaseName $params.databaseName -EnvLocation "Australia East" -Force
113+
}
114+
115+
New-AzureRmStorageAccount -Name $params.storageAccount -Location "Australia East" -ResourceGroupName $params.rgname -Type "Standard_GRS"
116+
}
117+
81118
<#
82119
.SYNOPSIS
83120
Creates the test environment needed to perform the Sql data masking tests
@@ -214,8 +251,24 @@ function Remove-TestEnvironment ($testSuffix)
214251
{
215252
try
216253
{
217-
$params = Get-SqlAuditingTestEnvironmentParameters $testSuffix
218-
Azure\Remove-AzureRmStorageAccount -StorageAccountName $params.storageAccount
254+
$params = Get-SqlAuditingTestEnvironmentParameters $testSuffix
255+
Azure\Remove-AzureRmStorageAccount -StorageAccountName $params.storageAccount
256+
}
257+
catch
258+
{
259+
}
260+
}
261+
262+
<#
263+
.SYNOPSIS
264+
Removes the test environment that was needed to perform the Sql threat detection tests
265+
#>
266+
function Remove-ThreatDetectionTestEnvironment ($testSuffix)
267+
{
268+
try
269+
{
270+
$params = Get-SqlThreatDetectionTestEnvironmentParameters $testSuffix
271+
Azure\Remove-AzureRmStorageAccount -StorageAccountName $params.storageAccount
219272
}
220273
catch
221274
{

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DataMaskingTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public class DataMaskingTests : SqlTestsBase
2222
{
2323
[Fact]
2424
[Trait(Category.AcceptanceType, Category.BVT)]
25-
public void TestDatabaseDataMaskingPrivilegedLoginsChanges()
25+
public void TestDatabaseDataMaskingPrivilegedUsersChanges()
2626
{
27-
RunPowerShellTest("Test-DatabaseDataMaskingPrivilegedLoginsChanges");
27+
RunPowerShellTest("Test-DatabaseDataMaskingPrivilegedUsersChanges");
2828
}
2929

3030
[Fact]

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/DataMaskingTests.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
.SYNOPSIS
1717
Tests changes of the privileged logins property of a data masking policy
1818
#>
19-
function Test-DatabaseDataMaskingPrivilegedLoginsChanges
19+
function Test-DatabaseDataMaskingPrivilegedUsersChanges
2020
{
2121

2222
# Setup
@@ -33,40 +33,40 @@ function Test-DatabaseDataMaskingPrivilegedLoginsChanges
3333

3434

3535
# Test adding a privileged login
36-
Set-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -PrivilegedLogins "public" -DataMaskingState "Enabled"
36+
Set-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -PrivilegedUsers "public" -DataMaskingState "Enabled"
3737
$policy = Get-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName
3838

3939
# Assert
40-
Assert-AreEqual "public;" $policy.PrivilegedLogins
40+
Assert-AreEqual "public;" $policy.PrivilegedUsers
4141
Assert-AreEqual "Enabled" $policy.DataMaskingState
4242

4343
# Test removing a privileged login while having enabled policy
44-
Set-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -PrivilegedLogins ""
44+
Set-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -PrivilegedUsers ""
4545
$policy = Get-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName
4646

4747
# Assert
48-
Assert-AreEqual "" $policy.PrivilegedLogins
48+
Assert-AreEqual "" $policy.PrivilegedUsers
4949

5050
# Test disabling a policy
5151
Set-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -DataMaskingState "Disabled"
5252
$policy = Get-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName
5353

5454
# Assert
55-
Assert-AreEqual "" $policy.PrivilegedLogins
55+
Assert-AreEqual "" $policy.PrivilegedUsers
5656

5757
# Test adding a privileged login while being disabled
58-
Set-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -PrivilegedLogins "public"
58+
Set-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -PrivilegedUsers "public"
5959
$policy = Get-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName
6060

6161
# Assert
62-
Assert-AreEqual "" $policy.PrivilegedLogins
62+
Assert-AreEqual "" $policy.PrivilegedUsers
6363

6464
# Test removing a privileged login while being disabled
65-
Set-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -PrivilegedLogins ""
65+
Set-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName -PrivilegedUsers ""
6666
$policy = Get-AzureRmSqlDatabaseDataMaskingPolicy -ResourceGroupName $params.rgname -ServerName $params.serverName -DatabaseName $params.databaseName
6767

6868
# Assert
69-
Assert-AreEqual "" $policy.PrivilegedLogins
69+
Assert-AreEqual "" $policy.PrivilegedUsers
7070
}
7171
finally
7272
{
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.ScenarioTest.SqlTests;
16+
using Microsoft.Azure.Test;
17+
using Microsoft.Azure.Test.HttpRecorder;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using Xunit;
20+
21+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
22+
{
23+
public class ThreatDetectionTests : SqlTestsBase
24+
{
25+
protected Management.Storage.StorageManagementClient GetStorageV2Client()
26+
{
27+
var client = TestBase.GetServiceClient<Management.Storage.StorageManagementClient>(new CSMTestEnvironmentFactory());
28+
if (HttpMockServer.Mode == HttpRecorderMode.Playback)
29+
{
30+
client.LongRunningOperationInitialTimeout = 0;
31+
client.LongRunningOperationRetryTimeout = 0;
32+
}
33+
return client;
34+
}
35+
36+
protected override void SetupManagementClients()
37+
{
38+
var sqlCSMClient = GetSqlClient();
39+
var storageClient = GetStorageClient();
40+
var storageV2Client = GetStorageV2Client();
41+
var resourcesClient = GetResourcesClient();
42+
var authorizationClient = GetAuthorizationManagementClient();
43+
helper.SetupSomeOfManagementClients(sqlCSMClient, storageClient, storageV2Client, resourcesClient, authorizationClient);
44+
}
45+
46+
[Fact]
47+
[Trait(Category.AcceptanceType, Category.Sql)]
48+
public void ThreatDetectionDatabaseGetDefualtPolicy()
49+
{
50+
RunPowerShellTest("Test-ThreatDetectionDatabaseGetDefualtPolicy");
51+
}
52+
53+
[Fact]
54+
[Trait(Category.AcceptanceType, Category.Sql)]
55+
public void ThreatDetectionDatabaseUpdatePolicy()
56+
{
57+
RunPowerShellTest("Test-ThreatDetectionDatabaseUpdatePolicy");
58+
}
59+
60+
[Fact]
61+
[Trait(Category.AcceptanceType, Category.Sql)]
62+
public void DisablingThreatDetection()
63+
{
64+
RunPowerShellTest("Test-DisablingThreatDetection");
65+
}
66+
67+
[Fact]
68+
[Trait(Category.AcceptanceType, Category.Sql)]
69+
public void InvalidArgumentsThreatDetection()
70+
{
71+
RunPowerShellTest("Test-InvalidArgumentsThreatDetection");
72+
}
73+
74+
[Fact]
75+
[Trait(Category.AcceptanceType, Category.Sql)]
76+
public void ThreatDetectionOnSawaServer()
77+
{
78+
RunPowerShellTest("Test-ThreatDetectionOnSawaServer");
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)