Skip to content

Commit dce4192

Browse files
authored
[Storage] Support Encryption Scope dataplane (#11676)
1 parent aa6a038 commit dce4192

File tree

11 files changed

+587
-23
lines changed

11 files changed

+587
-23
lines changed

src/Storage/Storage.Management.Test/ScenarioTests/StorageDataPlaneTests.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,17 @@ function Test-Blob
277277
$immutabilityPolicy = Get-AzRmStorageContainerImmutabilityPolicy -ResourceGroupName $ResourceGroupName -StorageAccountName $StorageAccountName -ContainerName $containerName
278278
Remove-AzRmStorageContainerImmutabilityPolicy -ResourceGroupName $ResourceGroupName -StorageAccountName $StorageAccountName -ContainerName $containerName -Etag $immutabilityPolicy.Etag
279279

280+
# Encryption Scope Test
281+
$scopename = "testscope"
282+
$containerName2 = "testscopecontainer"
283+
New-AzStorageEncryptionScope -ResourceGroupName $ResourceGroupName -StorageAccountName $storageAccountName -EncryptionScopeName $scopename -StorageEncryption
284+
$container = New-AzStorageContainer -Name $containerName2 -Context $storageContext -DefaultEncryptionScope $scopeName2 -PreventEncryptionScopeOverride $true
285+
Assert-AreEqual $scopename $container.BlobContainerProperties.DefaultEncryptionScope
286+
Assert-AreEqual $true $container.BlobContainerProperties.PreventEncryptionScopeOverride
287+
$blob = Set-AzStorageBlobContent -Context $storageContext -File $localSrcFile -Container $containerName -Blob encryscopetest -EncryptionScope $scopename
288+
Assert-AreEqual $scopename $blob.BlobProperties.EncryptionScope
289+
Remove-AzStorageContainer -Name $containerName2 -Force -Context $storageContext
290+
280291
# Clean Storage Account
281292
Remove-AzStorageContainer -Name $containerName -Force -Context $storageContext
282293

src/Storage/Storage.Management/Blob/NewAzureStorageContainer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public class NewAzureStorageContainerCommand : StorageBlobBaseCmdlet
102102
[Parameter(HelpMessage = "Default the container to use specified encryption scope for all writes.",
103103
Mandatory = true,
104104
ParameterSetName = AccountObjectEncryptionScopeParameterSet)]
105+
[ValidateNotNullOrEmpty]
105106
public string DefaultEncryptionScope { get; set; }
106107

107108
[Parameter(HelpMessage = "Block override of encryption scope from the container default.",

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Supported create container and upload blob with Encryption Scope setting
22+
- `New-AzStorageContainer`
23+
- `Set-AzStorageBlobContent`
2124
* Add RestorePolicy.LastEnabledTime to cmdlet output
2225
- `Get-AzStorageBlobServiceProperty`
2326
- `Enable-AzStorageBlobRestorePolicy`
2427
* Fixed #9880: Change NetWorkRule DefaultAction value defination to align with swagger.
25-
- Update-AzStorageAccountNetworkRuleSet
26-
- Get-AzStorageAccountNetworkRuleSet
28+
- `Update-AzStorageAccountNetworkRuleSet`
29+
- `Get-AzStorageAccountNetworkRuleSet`
2730
* Fixed #11624: Skip duplicated rules when add NetworkRules, to avoid server failure
2831
- `Add-AzStorageAccountNetworkRule`
2932

src/Storage/Storage.Management/help/New-AzRmStorageContainer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ Accept wildcard characters: False
250250
```
251251
252252
### CommonParameters
253-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
253+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
254254
255255
## INPUTS
256256

src/Storage/Storage.Management/help/New-AzStorageContainer.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@ Creates an Azure storage container.
1313

1414
## SYNTAX
1515

16+
### ContainerName (Default)
1617
```
1718
New-AzStorageContainer [-Name] <String> [[-Permission] <BlobContainerPublicAccessType>]
1819
[-Context <IStorageContext>] [-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
1920
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [<CommonParameters>]
2021
```
2122

23+
### EncryptionScope
24+
```
25+
New-AzStorageContainer [-Name] <String> [[-Permission] <BlobContainerPublicAccessType>]
26+
-DefaultEncryptionScope <String> -PreventEncryptionScopeOverride <Boolean> [-Context <IStorageContext>]
27+
[-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
28+
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [<CommonParameters>]
29+
```
30+
2231
## DESCRIPTION
2332
The **New-AzStorageContainer** cmdlet creates an Azure storage container.
2433

@@ -39,6 +48,19 @@ PS C:\>"container1 container2 container3".split() | New-AzStorageContainer -Perm
3948
This example creates multiple storage containers.
4049
It uses the **Split** method of the .NET **String** class and then passes the names on the pipeline.
4150

51+
### Example 3: Create an Azure storage container with Encryption Scope
52+
```
53+
PS C:\> $container = New-AzStorageContainer -Name "mycontainer" -DefaultEncryptionScope "myencryptscope" -PreventEncryptionScopeOverride $true
54+
55+
PS C:\> $container.BlobContainerProperties.DefaultEncryptionScope
56+
myencryptscope
57+
58+
PS C:\> $container.BlobContainerProperties.PreventEncryptionScopeOverride
59+
True
60+
```
61+
62+
This command creates a storage container, with default Encryption Scope as myencryptscope, and prevert blob upload with different Encryption Scope to this container.
63+
4264
## PARAMETERS
4365

4466
### -ClientTimeoutPerRequest
@@ -92,6 +114,21 @@ Accept pipeline input: True (ByPropertyName, ByValue)
92114
Accept wildcard characters: False
93115
```
94116
117+
### -DefaultEncryptionScope
118+
Default the container to use specified encryption scope for all writes.
119+
120+
```yaml
121+
Type: System.String
122+
Parameter Sets: EncryptionScope
123+
Aliases:
124+
125+
Required: True
126+
Position: Named
127+
Default value: None
128+
Accept pipeline input: False
129+
Accept wildcard characters: False
130+
```
131+
95132
### -DefaultProfile
96133
The credentials, account, tenant, and subscription used for communication with Azure.
97134
@@ -150,6 +187,21 @@ Accept pipeline input: False
150187
Accept wildcard characters: False
151188
```
152189
190+
### -PreventEncryptionScopeOverride
191+
Block override of encryption scope from the container default.
192+
193+
```yaml
194+
Type: System.Boolean
195+
Parameter Sets: EncryptionScope
196+
Aliases:
197+
198+
Required: True
199+
Position: Named
200+
Default value: None
201+
Accept pipeline input: False
202+
Accept wildcard characters: False
203+
```
204+
153205
### -ServerTimeoutPerRequest
154206
Specifies the service side time-out interval, in seconds, for a request.
155207
If the specified interval elapses before the service processes the request, the storage service returns an error.
@@ -167,7 +219,7 @@ Accept wildcard characters: False
167219
```
168220
169221
### CommonParameters
170-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
222+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
171223
172224
## INPUTS
173225

src/Storage/Storage.Management/help/Set-AzStorageBlobContent.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,29 @@ Uploads a local file to an Azure Storage blob.
1717
```
1818
Set-AzStorageBlobContent [-File] <String> [-Container] <String> [-Blob <String>] [-BlobType <String>]
1919
[-Properties <Hashtable>] [-Metadata <Hashtable>] [-PremiumPageBlobTier <PremiumPageBlobTier>]
20-
[-StandardBlobTier <String>] [-Force] [-AsJob] [-Context <IStorageContext>] [-ServerTimeoutPerRequest <Int32>]
21-
[-ClientTimeoutPerRequest <Int32>] [-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>]
22-
[-WhatIf] [-Confirm] [<CommonParameters>]
20+
[-StandardBlobTier <String>] [-EncryptionScope <String>] [-Force] [-AsJob] [-Context <IStorageContext>]
21+
[-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
22+
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [-WhatIf] [-Confirm]
23+
[<CommonParameters>]
2324
```
2425

2526
### ContainerPipeline
2627
```
2728
Set-AzStorageBlobContent [-File] <String> [-Blob <String>] -CloudBlobContainer <CloudBlobContainer>
2829
[-BlobType <String>] [-Properties <Hashtable>] [-Metadata <Hashtable>]
29-
[-PremiumPageBlobTier <PremiumPageBlobTier>] [-StandardBlobTier <String>] [-Force] [-AsJob]
30-
[-Context <IStorageContext>] [-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
30+
[-PremiumPageBlobTier <PremiumPageBlobTier>] [-StandardBlobTier <String>] [-EncryptionScope <String>] [-Force]
31+
[-AsJob] [-Context <IStorageContext>] [-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
3132
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [-WhatIf] [-Confirm]
3233
[<CommonParameters>]
3334
```
3435

3536
### BlobPipeline
3637
```
3738
Set-AzStorageBlobContent [-File] <String> -CloudBlob <CloudBlob> [-BlobType <String>] [-Properties <Hashtable>]
38-
[-Metadata <Hashtable>] [-PremiumPageBlobTier <PremiumPageBlobTier>] [-StandardBlobTier <String>] [-Force]
39-
[-AsJob] [-Context <IStorageContext>] [-ServerTimeoutPerRequest <Int32>] [-ClientTimeoutPerRequest <Int32>]
40-
[-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>] [-WhatIf] [-Confirm]
41-
[<CommonParameters>]
39+
[-Metadata <Hashtable>] [-PremiumPageBlobTier <PremiumPageBlobTier>] [-StandardBlobTier <String>]
40+
[-EncryptionScope <String>] [-Force] [-AsJob] [-Context <IStorageContext>] [-ServerTimeoutPerRequest <Int32>]
41+
[-ClientTimeoutPerRequest <Int32>] [-DefaultProfile <IAzureContextContainer>] [-ConcurrentTaskCount <Int32>]
42+
[-WhatIf] [-Confirm] [<CommonParameters>]
4243
```
4344

4445
## DESCRIPTION
@@ -97,6 +98,16 @@ PS C:\> Set-AzStorageBlobContent -File "ContosoPlanning" -Container "ContosoUplo
9798

9899
This command uploads the file that is named ContosoPlanning to the container named ContosoUploads with specified blob properties, and set StandardBlobTier as Cool.
99100

101+
### Example 7: Upload a file to a blob with Encryption Scope
102+
```
103+
PS C:\> $blob = Set-AzStorageBlobContent -File "mylocalfile" -Container "mycontainer" -Blob "myblob" -EncryptionScope "myencryptscope"
104+
105+
PS C:\> $blob.BlobProperties.EncryptionScope
106+
myencryptscope
107+
```
108+
109+
This command uploads a file to a blob with Encryption Scope.
110+
100111
## PARAMETERS
101112

102113
### -AsJob
@@ -267,6 +278,21 @@ Accept pipeline input: False
267278
Accept wildcard characters: False
268279
```
269280
281+
### -EncryptionScope
282+
Encryption scope to be used when making requests to the blob.
283+
284+
```yaml
285+
Type: System.String
286+
Parameter Sets: (All)
287+
Aliases:
288+
289+
Required: False
290+
Position: Named
291+
Default value: None
292+
Accept pipeline input: False
293+
Accept wildcard characters: False
294+
```
295+
270296
### -File
271297
Specifies a local file path for a file to upload as blob content.
272298
@@ -331,7 +357,7 @@ Page Blob Tier
331357
Type: Microsoft.Azure.Storage.Blob.PremiumPageBlobTier
332358
Parameter Sets: (All)
333359
Aliases:
334-
Accepted values: Unknown, P4, P6, P10, P20, P30, P40, P50, P60
360+
Accepted values: Unknown, P4, P6, P10, P20, P30, P40, P50, P60, P70, P80
335361

336362
Required: False
337363
Position: Named
@@ -380,6 +406,7 @@ See detail in https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-
380406
Type: System.String
381407
Parameter Sets: (All)
382408
Aliases:
409+
Accepted values: Hot, Cool, Archive
383410

384411
Required: False
385412
Position: Named
@@ -420,7 +447,7 @@ Accept wildcard characters: False
420447
```
421448
422449
### CommonParameters
423-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
450+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
424451
425452
## INPUTS
426453

src/Storage/Storage/Blob/Cmdlet/NewAzureStorageContainer.cs

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,27 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet
2222
using System.Management.Automation;
2323
using System.Security.Permissions;
2424
using System.Threading.Tasks;
25+
using global::Azure.Storage.Blobs;
26+
using global::Azure.Storage.Blobs.Models;
27+
using global::Azure;
2528

2629
/// <summary>
2730
/// create a new azure container
2831
/// </summary>
29-
[Cmdlet("New", Azure.Commands.ResourceManager.Common.AzureRMConstants.AzurePrefix + "StorageContainer"),OutputType(typeof(AzureStorageContainer))]
32+
[Cmdlet("New", Azure.Commands.ResourceManager.Common.AzureRMConstants.AzurePrefix + "StorageContainer", DefaultParameterSetName = ContainerNameParameterSet),OutputType(typeof(AzureStorageContainer))]
3033
[Alias("New-" + Azure.Commands.ResourceManager.Common.AzureRMConstants.AzurePrefix + "DatalakeGen2FileSystem")]
3134
public class NewAzureStorageContainerCommand : StorageCloudBlobCmdletBase
3235
{
36+
/// <summary>
37+
/// Container Name parameter
38+
/// </summary>
39+
private const string ContainerNameParameterSet = "ContainerName";
40+
41+
/// <summary>
42+
/// Container create with EncryptionScope parameter
43+
/// </summary>
44+
private const string EncryptionScopeParameterSet = "EncryptionScope";
45+
3346
[Alias("N", "Container")]
3447
[Parameter(Position = 0, Mandatory = true, HelpMessage = "Container name",
3548
ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
@@ -47,6 +60,29 @@ public BlobContainerPublicAccessType? Permission
4760
}
4861
private BlobContainerPublicAccessType accessLevel = BlobContainerPublicAccessType.Off;
4962

63+
[Parameter(HelpMessage = "Default the container to use specified encryption scope for all writes.",
64+
Mandatory = true,
65+
ParameterSetName = EncryptionScopeParameterSet)]
66+
[ValidateNotNullOrEmpty]
67+
public string DefaultEncryptionScope { get; set; }
68+
69+
[Parameter(HelpMessage = "Prevent override of encryption scope from the container default.",
70+
Mandatory = true,
71+
ParameterSetName = EncryptionScopeParameterSet)]
72+
[ValidateNotNullOrEmpty]
73+
public bool PreventEncryptionScopeOverride
74+
{
75+
get
76+
{
77+
return preventEncryptionScopeOverride is null ? false : preventEncryptionScopeOverride.Value;
78+
}
79+
set
80+
{
81+
preventEncryptionScopeOverride = value;
82+
}
83+
}
84+
private bool? preventEncryptionScopeOverride;
85+
5086
/// <summary>
5187
/// Initializes a new instance of the NewAzureStorageContainerCommand class.
5288
/// </summary>
@@ -77,18 +113,37 @@ internal async Task CreateAzureContainer(long taskId, IStorageBlobManagement loc
77113

78114
BlobRequestOptions requestOptions = RequestOptions;
79115
CloudBlobContainer container = localChannel.GetContainerReference(name);
116+
BlobContainerClient containerClient = AzureStorageContainer.GetTrack2BlobContainerClient(container, localChannel.StorageContext);
80117

81-
BlobContainerPermissions permissions = new BlobContainerPermissions();
82-
83-
permissions.PublicAccess = accesslevel;
118+
PublicAccessType containerPublicAccess = PublicAccessType.None;
119+
if (accesslevel == BlobContainerPublicAccessType.Blob)
120+
{
121+
containerPublicAccess = PublicAccessType.Blob;
122+
}
123+
else if (accesslevel == BlobContainerPublicAccessType.Container)
124+
{
125+
containerPublicAccess = PublicAccessType.BlobContainer;
126+
}
84127

85-
bool created = await localChannel.CreateContainerIfNotExistsAsync(container, permissions.PublicAccess, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
128+
BlobContainerEncryptionScopeOptions encryptionScopeOption = null;
129+
if (this.DefaultEncryptionScope != null)
130+
{
131+
encryptionScopeOption = new BlobContainerEncryptionScopeOptions()
132+
{
133+
// parameterset can ensure the 2 parameters must be set together.
134+
DefaultEncryptionScope = this.DefaultEncryptionScope,
135+
PreventEncryptionScopeOverride = this.preventEncryptionScopeOverride.Value
136+
};
137+
}
86138

87-
if (!created)
139+
Response<BlobContainerInfo> responds = await containerClient.CreateIfNotExistsAsync(containerPublicAccess, null, encryptionScopeOption, CmdletCancellationToken).ConfigureAwait(false);
140+
if (responds == null || responds.Value == null) // Container already exist so not created again
88141
{
89142
throw new ResourceAlreadyExistException(String.Format(Resources.ContainerAlreadyExists, name));
90143
}
91144

145+
BlobContainerPermissions permissions = new BlobContainerPermissions() { PublicAccess = accesslevel };
146+
container.FetchAttributes();
92147
WriteCloudContainerObject(taskId, localChannel, container, permissions);
93148
}
94149

0 commit comments

Comments
 (0)