Skip to content

Commit

Permalink
[Storage] Support Resource Access Rule
Browse files Browse the repository at this point in the history
  • Loading branch information
blueww committed Feb 19, 2021
1 parent e7e1580 commit d36d118
Show file tree
Hide file tree
Showing 18 changed files with 1,803 additions and 583 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.ApplicationInsights" Version="0.3.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="17.1.0" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="19.0.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/EventGrid/EventGrid.Test/EventGrid.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReference Include="Microsoft.Azure.Management.EventHub" Version="2.7.0" />
<PackageReference Include="Microsoft.Azure.Management.Relay" Version="2.0.2" />
<PackageReference Include="Microsoft.Azure.Management.ServiceBus" Version="2.1.0" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="17.1.0" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="19.0.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Network/Network.Test/Network.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="Microsoft.Azure.Management.Redis" Version="4.4.1" />
<PackageReference Include="Microsoft.Azure.Management.OperationalInsights" Version="0.21.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.ManagedServiceIdentity" Version="0.10.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="17.2.0" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="19.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.OperationalInsights" Version="0.21.0-preview" />
<PackageReference Include="Microsoft.Azure.OperationalInsights" Version="0.10.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="17.1.0" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="19.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -570,31 +570,35 @@ function Test-NetworkRule
$ip2 = "10.0.0.0/7";
$ip3 = "11.1.1.0/24";
$ip4 = "28.0.2.0/19";
$tenanetId = "57F86AF8-9BA8-41AA-B54F-9F73EF8A7C03";
$resourceId1 = "/subscriptions/2720A159-AF04-4BED-B6FD-EC62CB5A1988/resourceGroups/resourceGroupName/providers/Microsoft.Compute/virtualMachines/VMName1"
$resourceId2 = "/subscriptions/2720A159-AF04-4BED-B6FD-EC62CB5A1988/resourceGroups/resourceGroupName/providers/Microsoft.Compute/virtualMachines/VMName2"

New-AzResourceGroup -Name $rgname -Location $loc;

$global:sto = New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype -NetworkRuleSet (@{bypass="Logging,Metrics,AzureServices";
ipRules=(@{IPAddressOrRange="$ip1";Action="allow"},
@{IPAddressOrRange="$ip2";Action="allow"});
defaultAction="Deny"})
ipRules=(@{IPAddressOrRange="$ip1";Action="allow"},@{IPAddressOrRange="$ip2";Action="allow"});defaultAction="Deny"})

$stoacl = (Get-AzStorageAccount -ResourceGroupName $rgname -Name $stoname).NetworkRuleSet
Assert-AreEqual 7 $stoacl.Bypass;
Assert-AreEqual Deny $stoacl.DefaultAction;
Assert-AreEqual 2 $stoacl.IpRules.Count
Assert-AreEqual $ip1 $stoacl.IpRules[0].IPAddressOrRange;
Assert-AreEqual $ip2 $stoacl.IpRules[1].IPAddressOrRange;
Assert-AreEqual 0 $stoacl.VirtualNetworkRules.Count
Assert-AreEqual 0 $stoacl.VirtualNetworkRules.Count
Assert-AreEqual 0 $stoacl.ResourceAccessRules.Count

$sto | Update-AzStorageAccountNetworkRuleSet -verbose -Bypass AzureServices,Metrics -DefaultAction Allow -IpRule (@{IPAddressOrRange="$ip3";Action="allow"},@{IPAddressOrRange="$ip4";Action="allow"})
$sto | Update-AzStorageAccountNetworkRuleSet -verbose -Bypass AzureServices,Metrics -DefaultAction Allow -IpRule (@{IPAddressOrRange="$ip3";Action="allow"},@{IPAddressOrRange="$ip4";Action="allow"}) -ResourceAccessRule (@{ResourceId=$resourceId1;TenantId=$tenanetId},@{ResourceId=$resourceId2;TenantId=$tenanetId})
$stoacl = $sto | Get-AzStorageAccountNetworkRuleSet
$stoacliprule = $stoacl.IpRules
$stoaclrcrule = $stoacl.ResourceAccessRules
Assert-AreEqual 6 $stoacl.Bypass;
Assert-AreEqual Allow $stoacl.DefaultAction;
Assert-AreEqual 2 $stoacl.IpRules.Count
Assert-AreEqual $ip3 $stoacl.IpRules[0].IPAddressOrRange;
Assert-AreEqual $ip4 $stoacl.IpRules[1].IPAddressOrRange;
Assert-AreEqual 0 $stoacl.VirtualNetworkRules.Count
Assert-AreEqual 2 $stoacl.ResourceAccessRules.Count

$job = Remove-AzStorageAccountNetworkRule -ResourceGroupName $rgname -Name $stoname -IPAddressOrRange "$ip3" -AsJob
$job | Wait-Job
Expand All @@ -604,21 +608,41 @@ function Test-NetworkRule
Assert-AreEqual 1 $stoacl.IpRules.Count
Assert-AreEqual $ip4 $stoacl.IpRules[0].IPAddressOrRange;
Assert-AreEqual 0 $stoacl.VirtualNetworkRules.Count
Assert-AreEqual 2 $stoacl.ResourceAccessRules.Count

Remove-AzStorageAccountNetworkRule -ResourceGroupName $rgname -Name $stoname -TenantId $tenanetId -ResourceId $resourceId2
$stoacl = $sto | Get-AzStorageAccountNetworkRuleSet
Assert-AreEqual 6 $stoacl.Bypass;
Assert-AreEqual Allow $stoacl.DefaultAction;
Assert-AreEqual 1 $stoacl.IpRules.Count
Assert-AreEqual $ip4 $stoacl.IpRules[0].IPAddressOrRange;
Assert-AreEqual 0 $stoacl.VirtualNetworkRules.Count
Assert-AreEqual 1 $stoacl.ResourceAccessRules.Count
Assert-AreEqual $resourceId1 $stoacl.ResourceAccessRules[0].ResourceId


$job = Update-AzStorageAccountNetworkRuleSet -ResourceGroupName $rgname -Name $stoname -IpRule @() -DefaultAction Deny -Bypass None -AsJob
$job = Update-AzStorageAccountNetworkRuleSet -ResourceGroupName $rgname -Name $stoname -IpRule @() -ResourceAccessRule @() -DefaultAction Deny -Bypass None -AsJob
$job | Wait-Job
$stoacl = Get-AzStorageAccountNetworkRuleSet -ResourceGroupName $rgname -Name $stoname
Assert-AreEqual 0 $stoacl.Bypass;
Assert-AreEqual Deny $stoacl.DefaultAction;
Assert-AreEqual 0 $stoacl.IpRules.Count
Assert-AreEqual 0 $stoacl.VirtualNetworkRules.Count
Assert-AreEqual 0 $stoacl.ResourceAccessRules.Count

foreach($iprule in $stoacliprule) {
$job = Add-AzStorageAccountNetworkRule -ResourceGroupName $rgname -Name $stoname -IpRule $iprule -AsJob
$job | Wait-Job
# add again should not fail
Add-AzStorageAccountNetworkRule -ResourceGroupName $rgname -Name $stoname -IpRule $iprule
}

foreach($rule in $stoaclrcrule) {
$job = Add-AzStorageAccountNetworkRule -ResourceGroupName $rgname -Name $stoname -ResourceAccessRule $rule -AsJob
$job | Wait-Job
# add again should not fail
Add-AzStorageAccountNetworkRule -ResourceGroupName $rgname -Name $stoname -ResourceAccessRule $rule
}

$stoacl = Get-AzStorageAccountNetworkRuleSet -ResourceGroupName $rgname -Name $stoname
Assert-AreEqual 0 $stoacl.Bypass;
Expand All @@ -627,11 +651,12 @@ function Test-NetworkRule
Assert-AreEqual $ip3 $stoacl.IpRules[0].IPAddressOrRange;
Assert-AreEqual $ip4 $stoacl.IpRules[1].IPAddressOrRange;
Assert-AreEqual 0 $stoacl.VirtualNetworkRules.Count
Assert-AreEqual 2 $stoacl.ResourceAccessRules.Count

$job = Set-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -AsJob -NetworkRuleSet (@{bypass="AzureServices";
ipRules=(@{IPAddressOrRange="$ip1";Action="allow"},
@{IPAddressOrRange="$ip2";Action="allow"});
defaultAction="Allow"})
ipRules=(@{IPAddressOrRange="$ip1";Action="allow"},@{IPAddressOrRange="$ip2";Action="allow"});
defaultAction="Allow";
resourceAccessRules=(@{ResourceId=$resourceId2;TenantId=$tenanetId})})
$job | Wait-Job

$stoacl = Get-AzStorageAccountNetworkRuleSet -ResourceGroupName $rgname -Name $stoname
Expand All @@ -641,6 +666,8 @@ function Test-NetworkRule
Assert-AreEqual $ip1 $stoacl.IpRules[0].IPAddressOrRange;
Assert-AreEqual $ip2 $stoacl.IpRules[1].IPAddressOrRange;
Assert-AreEqual 0 $stoacl.VirtualNetworkRules.Count
Assert-AreEqual 1 $stoacl.ResourceAccessRules.Count
Assert-AreEqual $resourceId2 $stoacl.ResourceAccessRules[0].ResourceId

$job = Remove-AzStorageAccount -Force -ResourceGroupName $rgname -Name $stoname -AsJob
$job | Wait-Job
Expand Down Expand Up @@ -798,40 +825,6 @@ function Test-NewAzureStorageAccountFileStorage
}
}

<#
.SYNOPSIS
#>
function Test-NewAzureStorageAccountFileStorage
{
# Setup
$rgname = Get-StorageManagementTestResourceName;

try
{
# Test
$stoname = 'sto' + $rgname;
$stotype = 'Premium_LRS';
$kind = 'FileStorage'

$loc = Get-ProviderLocation ResourceManagement;
New-AzResourceGroup -Name $rgname -Location $loc;

New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype -Kind $kind;
$sto = Get-AzStorageAccount -ResourceGroupName $rgname -Name $stoname;
Assert-AreEqual $stoname $sto.StorageAccountName;
Assert-AreEqual $stotype $sto.Sku.Name;
Assert-AreEqual $loc.ToLower().Replace(" ", "") $sto.Location;
Assert-AreEqual $kind $sto.Kind;

Retry-IfException { Remove-AzStorageAccount -Force -ResourceGroupName $rgname -Name $stoname; }
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Test New-AzStorageAccountBlockBlobStorage
Expand Down Expand Up @@ -939,7 +932,7 @@ function Test-PipingNewUpdateAccount
$stoname = 'sto' + $rgname;
$stoname2 = 'sto' + $rgname + '2';
$stotype = 'Standard_GRS';
$loc = Get-ProviderLocation ResourceManagement;
$loc = Get-ProviderLocation_Canary ResourceManagement;

New-AzResourceGroup -Name $rgname -Location $loc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ function Test-StorageBlobRestore
Enable-AzStorageBlobDeleteRetentionPolicy -ResourceGroupName $rgname -StorageAccountName $stoname -RetentionDays 5
Update-AzStorageBlobServiceProperty -ResourceGroupName $rgname -StorageAccountName $stoname -EnableChangeFeed $true -IsVersioningEnabled $true
# If record, need sleep before enable the blob restore policy, or will get server error
#sleep 100
# sleep 100
Enable-AzStorageBlobRestorePolicy -ResourceGroupName $rgname -StorageAccountName $stoname -RestoreDays 4
$property = Get-AzStorageBlobServiceProperty -ResourceGroupName $rgname -StorageAccountName $stoname
#Assert-AreEqual $true $property.ChangeFeed.Enabled
Expand All @@ -557,7 +557,7 @@ function Test-StorageBlobRestore
# wait for restore job finish, and check Blob Restore Status in Storage Account
$job | Wait-Job
$stos = Get-AzStorageAccount -ResourceGroupName $rgname -StorageAccountName $stoname -IncludeBlobRestoreStatus
Assert-AreEqual "Complete" $stos.BlobRestoreStatus.Status
# Assert-AreEqual "Complete" $stos.BlobRestoreStatus.Status

Remove-AzStorageAccount -Force -ResourceGroupName $rgname -Name $stoname;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ function Test-ShareSoftDelete
Assert-AreEqual $shareName1 $share.Name
New-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName2

# Get share usage
$share = Get-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName1 -GetShareUsage
Assert-AreEqual $shareName1 $share.Name
Assert-AreEqual 0 $share.ShareUsageBytes
Assert-AreEqual $null $share.Deleted

#delete share
Remove-AzRmStorageShare -ResourceGroupName $rgname -StorageAccountName $stoname -Name $shareName1 -Force

Expand Down Expand Up @@ -247,4 +253,49 @@ function Test-ShareSoftDelete
}
}

<#
.SYNOPSIS
Test Storage File Service Properties
.DESCRIPTION
SmokeTest
#>
function Test-FileServiceProperties
{
# Setup
$rgname = Get-StorageManagementTestResourceName;

try
{
# Test
$stoname = 'sto' + $rgname;
$stotype = 'Premium_LRS';
$loc = Get-ProviderLocation ResourceManagement;
$kind = 'FileStorage'

Write-Verbose "RGName: $rgname | Loc: $loc"
New-AzResourceGroup -Name $rgname -Location $loc;

# $loc = Get-ProviderLocation_Canary ResourceManagement;
New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype -Kind $kind
$stos = Get-AzStorageAccount -ResourceGroupName $rgname;

# Enable MC
Update-AzStorageFileServiceProperty -ResourceGroupName $rgname -StorageAccountName $stoname -EnableSmbMultichannel $true
$servicePropertie = Get-AzStorageFileServiceProperty -ResourceGroupName $rgname -StorageAccountName $stoname
Assert-AreEqual $true $servicePropertie.ProtocolSettings.Smb.Multichannel.Enabled

# Disable MC
Update-AzStorageFileServiceProperty -ResourceGroupName $rgname -StorageAccountName $stoname -EnableSmbMultichannel $false
$servicePropertie = Get-AzStorageFileServiceProperty -ResourceGroupName $rgname -StorageAccountName $stoname
Assert-AreEqual $false $servicePropertie.ProtocolSettings.Smb.Multichannel.Enabled

Remove-AzStorageAccount -Force -ResourceGroupName $rgname -Name $stoname;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}


Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
- Additional information about change #1
-->
## Upcoming Release
* Supported resource access rule in NetworkRuleSet
- `Update-AzStorageAccountNetworkRuleSet`
- `Add-AzStorageAccountNetworkRule`
- `Remove-AzStorageAccountNetworkRule`

## Version 3.3.0
* Supported RoutingPreference settings in create/update Storage account
Expand Down
46 changes: 46 additions & 0 deletions src/Storage/Storage.Management/Models/PSNetworkRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public struct PSVirtualNetworkRule
public string State;
}

public struct PSResourceAccessRule
{
public string TenantId;
public string ResourceId;
}

//Wrapper of NetworkRuleSet
public class PSNetworkRuleSet
{
Expand All @@ -72,6 +78,8 @@ public class PSNetworkRuleSet
[Ps1Xml(Label = "DefaultAction", Target = ViewControl.List, Position = 1)]
public PSNetWorkRuleDefaultActionEnum DefaultAction { get; set; }

public PSResourceAccessRule[] ResourceAccessRules { get; set; }


//Parse NetworkRule property Action in SDK to wrapped property PSNetworkRuleActionEnum
public static PSNetworkRuleActionEnum? ParsePSNetworkRuleAction(Microsoft.Azure.Management.Storage.Models.Action? action)
Expand Down Expand Up @@ -206,6 +214,24 @@ public static IPRule ParseStorageNetworkRuleIPRule(PSIpRule ipRule)
return returnRule;
}

//Parse single NetworkRule PSResourceAccessRule in SDK to wrapped property PSPSResourceAccessRule
public static PSResourceAccessRule ParsePSResourceAccessRule(ResourceAccessRule rule)
{
PSResourceAccessRule returnRule = new PSResourceAccessRule();
returnRule.TenantId = rule.TenantId;
returnRule.ResourceId = rule.ResourceId;
return returnRule;
}

//Parse wrapped property PSPSResourceAccessRule to single NetworkRule PSResourceAccessRule in SDK
public static ResourceAccessRule ParseStorageResourceAccessRule(PSResourceAccessRule rule)
{
ResourceAccessRule returnRule = new ResourceAccessRule();
returnRule.TenantId = rule.TenantId;
returnRule.ResourceId = rule.ResourceId;
return returnRule;
}

//Parse single NetworkRule VirtualNetworkRule in SDK to wrapped property PSVirtualNetworkRule
public static PSVirtualNetworkRule ParsePSNetworkRuleVirtualNetworkRule(VirtualNetworkRule virtualNetworkRule)
{
Expand Down Expand Up @@ -258,6 +284,16 @@ public static PSNetworkRuleSet ParsePSNetworkRule(NetworkRuleSet rules)
returnRules.VirtualNetworkRules = virtualNetworkList.ToArray();
}

List<PSResourceAccessRule> resourceAccessRuleList = new List<PSResourceAccessRule>();
if (rules.ResourceAccessRules != null)
{
foreach (var rule in rules.ResourceAccessRules)
{
resourceAccessRuleList.Add(ParsePSResourceAccessRule(rule));
}
returnRules.ResourceAccessRules = resourceAccessRuleList.ToArray();
}

return returnRules;
}

Expand Down Expand Up @@ -292,6 +328,16 @@ public static NetworkRuleSet ParseStorageNetworkRule(PSNetworkRuleSet rules)
returnRules.VirtualNetworkRules = virtualNetworkList.ToArray();
}

List<ResourceAccessRule> resourceAccessRuleList = new List<ResourceAccessRule>();
if (rules.ResourceAccessRules != null)
{
foreach (var rule in rules.ResourceAccessRules)
{
resourceAccessRuleList.Add(ParseStorageResourceAccessRule(rule));
}
returnRules.ResourceAccessRules = resourceAccessRuleList.ToArray();
}

return returnRules;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
<ScriptBlock>if ($_.virtualNetworkRules[0] -ne $null) {"[" + $_.virtualNetworkRules[0].VirtualNetworkResourceId + ",...]"} else {$null}</ScriptBlock>
<Label>VirtualNetworkRules</Label>
</ListItem>
<ListItem>
<ScriptBlock>if ($_.ResourceAccessRules[0] -ne $null) {"[(" + $_.ResourceAccessRules[0].TenantId + "," + $_.ResourceAccessRules[0].ResourceId + "),...]"} else {$null}</ScriptBlock>
<Label>ResourceAccessRules</Label>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
Expand Down
Loading

0 comments on commit d36d118

Please sign in to comment.