Skip to content

Commit 30c4452

Browse files
authored
Merge pull request #6895 from chlahav/preview
Introducing Azure Security Center module
2 parents 2586f08 + 085826e commit 30c4452

File tree

175 files changed

+17276
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

175 files changed

+17276
-2
lines changed

src/ResourceManager/Security/Commands.Security.Test/Commands.Security.Test.csproj

Lines changed: 283 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 System.Reflection;
16+
using System.Runtime.CompilerServices;
17+
using System.Runtime.InteropServices;
18+
19+
// General Information about an assembly is controlled through the following
20+
// set of attributes. Change these attribute values to modify the information
21+
// associated with an assembly.
22+
[assembly: AssemblyTitle("Commands.Security.Test")]
23+
[assembly: AssemblyDescription("")]
24+
[assembly: AssemblyConfiguration("")]
25+
[assembly: AssemblyCompany("")]
26+
[assembly: AssemblyProduct("Commands.Security.Test")]
27+
[assembly: AssemblyCopyright("Copyright © 2018")]
28+
[assembly: AssemblyTrademark("")]
29+
[assembly: AssemblyCulture("")]
30+
31+
// Setting ComVisible to false makes the types in this assembly not visible
32+
// to COM components. If you need to access a type in this assembly from
33+
// COM, set the ComVisible attribute to true on that type.
34+
[assembly: ComVisible(false)]
35+
36+
// The following GUID is for the ID of the typelib if this project is exposed to COM
37+
[assembly: Guid("9f866d20-059a-4dab-af42-18e37f503e30")]
38+
39+
// Version information for an assembly consists of the following four values:
40+
//
41+
// Major Version
42+
// Minor Version
43+
// Build Number
44+
// Revision
45+
//
46+
// You can specify all the values or you can default the Build and Revision Numbers
47+
// by using the '*' as shown below:
48+
// [assembly: AssemblyVersion("1.0.*")]
49+
[assembly: AssemblyVersion("1.0.0.0")]
50+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
<#
16+
.SYNOPSIS
17+
Gets test resource group name
18+
#>
19+
function Get-TestResourceGroupName
20+
{
21+
"myService1"
22+
}
23+
24+
<#
25+
.SYNOPSIS
26+
Gets test resource group name
27+
#>
28+
function Extract-ResourceLocation{
29+
param(
30+
[string]$ResourceId
31+
)
32+
$match = [Regex]::Match($ResourceId, "locations/(.*?)/")
33+
34+
return $match.Captures.Groups[1].Value
35+
}
36+
37+
<#
38+
.SYNOPSIS
39+
Gets test resource group name
40+
#>
41+
function Extract-ResourceGroup{
42+
param(
43+
[string]$ResourceId
44+
)
45+
$match = [Regex]::Match($ResourceId, "resourceGroups/(.*?)/")
46+
47+
return $match.Captures.Groups[1].Value
48+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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;
16+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Xunit;
19+
20+
namespace Microsoft.Azure.Commands.Security.Test.ScenarioTests
21+
{
22+
public class SecurityAlertTests
23+
{
24+
private readonly XunitTracingInterceptor _logger;
25+
26+
public SecurityAlertTests(Xunit.Abstractions.ITestOutputHelper output)
27+
{
28+
_logger = new XunitTracingInterceptor(output);
29+
XunitTracingInterceptor.AddToContext(_logger);
30+
TestExecutionHelpers.SetUpSessionAndProfile();
31+
}
32+
33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.CheckIn)]
35+
public void GetSubscriptionScope()
36+
{
37+
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmSecurityAlert-SubscriptionScope");
38+
}
39+
40+
[Fact]
41+
[Trait(Category.AcceptanceType, Category.CheckIn)]
42+
public void GetResourceGroupScope()
43+
{
44+
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmSecurityAlert-ResourceGroupScope");
45+
}
46+
47+
[Fact]
48+
[Trait(Category.AcceptanceType, Category.CheckIn)]
49+
public void GetResourceGroupLevelResource()
50+
{
51+
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmSecurityAlert-ResourceGroupLevelResource");
52+
}
53+
54+
[Fact]
55+
[Trait(Category.AcceptanceType, Category.CheckIn)]
56+
public void GetSubscriptionLevelResource()
57+
{
58+
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmSecurityAlert-SubscriptionLevelResource");
59+
}
60+
61+
[Fact]
62+
[Trait(Category.AcceptanceType, Category.CheckIn)]
63+
public void GetResourceId()
64+
{
65+
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzureRmSecurityAlert-ResourceId");
66+
}
67+
68+
[Fact]
69+
[Trait(Category.AcceptanceType, Category.CheckIn)]
70+
public void SetResourceGroupLevelResource()
71+
{
72+
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzureRmSecurityAlert-ResourceGroupLevelResource");
73+
}
74+
75+
[Fact]
76+
[Trait(Category.AcceptanceType, Category.CheckIn)]
77+
public void SetSubscriptionLevelResource()
78+
{
79+
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzureRmSecurityAlert-SubscriptionLevelResource");
80+
}
81+
82+
[Fact]
83+
[Trait(Category.AcceptanceType, Category.CheckIn)]
84+
public void SetResourceId()
85+
{
86+
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzureRmSecurityAlert-ResourceId");
87+
}
88+
}
89+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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+
<#
16+
.SYNOPSIS
17+
Get security alerts on a subscription and its resources
18+
#>
19+
function Get-AzureRmSecurityAlert-SubscriptionScope
20+
{
21+
$alerts = Get-AzureRmSecurityAlert
22+
Validate-Alerts $alerts
23+
}
24+
25+
<#
26+
.SYNOPSIS
27+
Get security alerts on a resource group and its resources
28+
#>
29+
function Get-AzureRmSecurityAlert-ResourceGroupScope
30+
{
31+
$rgName = Get-TestResourceGroupName
32+
33+
$alerts = Get-AzureRmSecurityAlert -ResourceGroupName $rgName
34+
Validate-Alerts $alerts
35+
}
36+
37+
<#
38+
.SYNOPSIS
39+
Get a security alert on a resource group level
40+
#>
41+
function Get-AzureRmSecurityAlert-ResourceGroupLevelResource
42+
{
43+
$alerts = Get-AzureRmSecurityAlert
44+
45+
$alert = $alerts | where { $_.Id -like "*resourceGroups*" } | Select -First 1
46+
$location = Extract-ResourceLocation -ResourceId $alert.Id
47+
$rgName = Extract-ResourceGroup -ResourceId $alert.Id
48+
49+
$fetchedAlert = Get-AzureRmSecurityAlert -ResourceGroupName $rgName -Location $location -Name $alert.Name
50+
Validate-Alert $fetchedAlert
51+
}
52+
53+
<#
54+
.SYNOPSIS
55+
Get a security alert on a subscription level
56+
#>
57+
function Get-AzureRmSecurityAlert-SubscriptionLevelResource
58+
{
59+
$alerts = Get-AzureRmSecurityAlert
60+
$alert = $alerts | where { $_.Id -notlike "*resourceGroups*" } | Select -First 1
61+
$location = Extract-ResourceLocation -ResourceId $alert.Id
62+
63+
$fetchedAlert = Get-AzureRmSecurityAlert -Location $location -Name $alert.Name
64+
Validate-Alert $fetchedAlert
65+
}
66+
67+
<#
68+
.SYNOPSIS
69+
Get a security alert by a resource ID
70+
#>
71+
function Get-AzureRmSecurityAlert-ResourceId
72+
{
73+
$alerts = Get-AzureRmSecurityAlert
74+
$alert = $alerts | Select -First 1
75+
76+
$alerts = Get-AzureRmSecurityAlert -ResourceId $alert.Id
77+
Validate-Alerts $alerts
78+
}
79+
80+
<#
81+
.SYNOPSIS
82+
Change resource group security alert state
83+
#>
84+
function Set-AzureRmSecurityAlert-ResourceGroupLevelResource
85+
{
86+
$alerts = Get-AzureRmSecurityAlert
87+
88+
$alert = $alerts | where { $_.Id -like "*resourceGroups*" } | Select -First 1
89+
$location = Extract-ResourceLocation -ResourceId $alert.Id
90+
$rgName = Extract-ResourceGroup -ResourceId $alert.Id
91+
92+
Set-AzureRmSecurityAlert -ResourceGroupName $rgName -Location $location -Name $alert.Name -ActionType "Activate"
93+
94+
$fetchedAlert = Get-AzureRmSecurityAlert -ResourceGroupName $rgName -Location $location -Name $alert.Name
95+
96+
Validate-AlertActivity -alert $fetchedAlert
97+
}
98+
99+
<#
100+
.SYNOPSIS
101+
Change subscription security alert state
102+
#>
103+
function Set-AzureRmSecurityAlert-SubscriptionLevelResource
104+
{
105+
$alerts = Get-AzureRmSecurityAlert
106+
$alert = $alerts | where { $_.Id -notlike "*resourceGroups*" } | Select -First 1
107+
$location = Extract-ResourceLocation -ResourceId $alert.Id
108+
109+
Set-AzureRmSecurityAlert -Location $location -Name $alert.Name -ActionType "Activate"
110+
111+
$fetchedAlert = Get-AzureRmSecurityAlert -Location $location -Name $alert.Name
112+
113+
Validate-AlertActivity -alert $fetchedAlert
114+
}
115+
116+
<#
117+
.SYNOPSIS
118+
Change resource group security alert state by a resource ID
119+
#>
120+
function Set-AzureRmSecurityAlert-ResourceId
121+
{
122+
$alerts = Get-AzureRmSecurityAlert
123+
$alert = $alerts | Select -First 1
124+
125+
Set-AzureRmSecurityAlert -ResourceId $alert.Id -ActionType "Activate"
126+
127+
$fetchedAlert = Get-AzureRmSecurityAlert -ResourceId $alert.Id
128+
129+
Validate-AlertActivity -alert $fetchedAlert
130+
}
131+
132+
<#
133+
.SYNOPSIS
134+
Validates a list of security alerts
135+
#>
136+
function Validate-Alerts
137+
{
138+
param($alerts)
139+
140+
Assert-True { $alerts.Count -gt 0 }
141+
142+
Foreach($alert in $alerts)
143+
{
144+
Validate-Alert $alert
145+
}
146+
}
147+
148+
<#
149+
.SYNOPSIS
150+
Validates a single alert
151+
#>
152+
function Validate-Alert
153+
{
154+
param($alert)
155+
156+
Assert-NotNull $alert
157+
}
158+
159+
160+
<#
161+
.SYNOPSIS
162+
Validates a single alert
163+
#>
164+
function Validate-AlertActivity
165+
{
166+
param($alert)
167+
168+
Assert-NotNull $alert
169+
Assert-True { $alert.State -eq "Active" }
170+
}

0 commit comments

Comments
 (0)