Skip to content

Commit 8b6e600

Browse files
authored
[Storage] Support Encryption Scope in create account/container/blob SAS token (#17453)
* [Storage] Support Encryption Scope in create SAS * fix CI failure
1 parent 2a5badc commit 8b6e600

14 files changed

+122
-43
lines changed

build.proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
<!-- Delete powershell runtime files -->
200200
<PropertyGroup>
201201
<RuntimeDllsIncludeList>Microsoft.Powershell.*.dll,System*.dll,Microsoft.VisualBasic.dll,Microsoft.CSharp.dll,Microsoft.CodeAnalysis.dll,Microsoft.CodeAnalysis.CSharp.dll</RuntimeDllsIncludeList>
202-
<RuntimeDllsExcludeList>System.Security.Cryptography.ProtectedData.dll,System.Configuration.ConfigurationManager.dll,System.Runtime.CompilerServices.Unsafe.dll,System.IO.FileSystem.AccessControl.dll,System.Buffers.dll,System.Text.Encodings.Web.dll,System.CodeDom.dll,System.Management.dll,System.Text.Json.dll,System.Threading.Tasks.Extensions.dll</RuntimeDllsExcludeList>
202+
<RuntimeDllsExcludeList>System.Security.Cryptography.ProtectedData.dll,System.Configuration.ConfigurationManager.dll,System.Runtime.CompilerServices.Unsafe.dll,System.IO.FileSystem.AccessControl.dll,System.Buffers.dll,System.Text.Encodings.Web.dll,System.CodeDom.dll,System.Management.dll,System.Text.Json.dll,System.Threading.Tasks.Extensions.dll,System.IO.Hashing.dll</RuntimeDllsExcludeList>
203203
</PropertyGroup>
204204
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;Get-ChildItem -Path $(RepoArtifacts)/$(Configuration) -Recurse -Include $(RuntimeDllsIncludeList) -Exclude $(RuntimeDllsExcludeList) | Where-Object {$_.FullName -notlike '*PreloadAssemblies*' -and $_.FullName -notlike '*NetCoreAssemblies*' -and $_.FullName -notlike '*AzSharedAlcAssemblies*' -and $_.FullName -notlike '*ModuleAlcAssemblies*'} | Remove-Item -Force&quot;"/>
205205
<Exec Command="$(PowerShellCoreCommandPrefix) &quot;Get-ChildItem -Path $(RepoArtifacts)/$(Configuration) -Recurse -Include 'runtimes' | Remove-Item -Recurse -Force&quot;" Condition="'$(CodeSign)' == 'true'" />

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,12 @@ function Test-Blob
332332
Update-AzStorageBlobServiceProperty -ResourceGroupName $ResourceGroupName -Name $StorageAccountName -IsVersioningEnabled $true
333333
$containerNamevlw = "vlwcontainer"
334334
# create container with ImmutableStorageWithVersioning
335-
New-AzRmStorageContainer -ResourceGroupName $ResourceGroupName -Name $StorageAccountName -Name $containerNamevlw -EnableImmutableStorageWithVersioning
335+
New-AzRmStorageContainer -ResourceGroupName $ResourceGroupName -StorageAccountName $StorageAccountName -Name $containerNamevlw -EnableImmutableStorageWithVersioning
336336
# upload a blob
337+
$objectName = "testblob"
337338
Set-AzStorageBlobContent -File $localSrcFile -Container $containerNamevlw -Blob $objectName -Force -Context $storageContext
338339
# manage ImmutabilityPolicy
339-
$policy = Set-AzStorageBlobImmutabilityPolicy -Container $containerNamevlw -Blob $objectName -ExpiriesOn (Get-Date).AddDays(1) -PolicyMode Unlocked -Context $storageContext
340+
$policy = Set-AzStorageBlobImmutabilityPolicy -Container $containerNamevlw -Blob $objectName -ExpiresOn (Get-Date).AddDays(1) -PolicyMode Unlocked -Context $storageContext
340341
$blob = Get-AzStorageBlob -Container $containerNamevlw -Blob $objectName -Context $storageContext
341342
Remove-AzStorageBlobImmutabilityPolicy -Container $containerNamevlw -Blob $objectName -Context $storageContext
342343
$blob = Get-AzStorageBlob -Container $containerNamevlw -Blob $objectName -Context $storageContext

src/Storage/Storage.Management.Test/Storage.Management.Test.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Azure.Storage.Blobs" Version="12.10.0" />
15-
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.8.0" />
16-
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.8.0" />
17-
<PackageReference Include="Azure.Storage.Queues" Version="12.8.0" />
14+
<PackageReference Include="Azure.Storage.Blobs" Version="12.11.0" />
15+
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.9.0" />
16+
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.9.0" />
17+
<PackageReference Include="Azure.Storage.Queues" Version="12.9.0" />
1818
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="23.1.0" />
1919
</ItemGroup>
2020

src/Storage/Storage.Management/Az.Storage.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ RequiredAssemblies = 'Microsoft.Azure.Management.Storage.dll',
6969
'Microsoft.Azure.KeyVault.Core.dll', 'Azure.Storage.Blobs.dll',
7070
'Azure.Storage.Common.dll', 'Azure.Storage.Files.DataLake.dll',
7171
'Azure.Storage.Queues.dll', 'Azure.Storage.Files.Shares.dll',
72-
'Azure.Data.Tables.dll'
72+
'Azure.Data.Tables.dll', 'System.IO.Hashing.dll'
7373

7474
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
7575
# ScriptsToProcess = @()

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
- `New-AzStorageContext`
2424
* Fixed copy blob failure on Premium Storage account, or account enabled hierarchical namespace
2525
- `Copy-AzStorageBlob`
26+
* Supported create account SAS token, container SAS token, blob SAS token with EncrptionScope
27+
- `New-AzStorageAccountSASToken`
28+
- `New-AzStorageContainerSASToken`
29+
- `New-AzStorageBlobSASToken`
2630

2731
## Version 4.3.0
2832
* Supported download blob from managed disk account with Sas Uri and bearer token

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Creates an account-level SAS token.
1616
```
1717
New-AzStorageAccountSASToken -Service <SharedAccessAccountServices>
1818
-ResourceType <SharedAccessAccountResourceTypes> [-Permission <String>] [-Protocol <SharedAccessProtocol>]
19-
[-IPAddressOrRange <String>] [-StartTime <DateTime>] [-ExpiryTime <DateTime>] [-Context <IStorageContext>]
20-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
19+
[-IPAddressOrRange <String>] [-StartTime <DateTime>] [-ExpiryTime <DateTime>] [-EncryptionScope <String>]
20+
[-Context <IStorageContext>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2121
```
2222

2323
## DESCRIPTION
@@ -33,12 +33,12 @@ PS C:\> New-AzStorageAccountSASToken -Service Blob,File,Table,Queue -ResourceTyp
3333

3434
This command creates an account-level SAS token with full permission.
3535

36-
### Example 2: Create an account-level SAS token for a range of IP addresses
36+
### Example 2: Create an account-level SAS token for a range of IP addresses and EncryptionScope
3737
```
38-
PS C:\> New-AzStorageAccountSASToken -Service Blob,File,Table,Queue -ResourceType Service,Container,Object -Permission "racwdlup" -Protocol HttpsOnly -IPAddressOrRange 168.1.5.60-168.1.5.70
38+
PS C:\> New-AzStorageAccountSASToken -Service Blob,File,Table,Queue -ResourceType Service,Container,Object -Permission "racwdlup" -Protocol HttpsOnly -IPAddressOrRange 168.1.5.60-168.1.5.70 -EncryptionScope scopename
3939
```
4040

41-
This command creates an account-level SAS token for HTTPS-only requests from the specified range of IP addresses.
41+
This command creates an account-level SAS token for HTTPS-only requests from the specified range of IP addresses, with a specific EncryptionScope.
4242

4343
### Example 3: Create an account-level SAS token valid for 24 hours
4444
```
@@ -80,6 +80,21 @@ Accept pipeline input: False
8080
Accept wildcard characters: False
8181
```
8282
83+
### -EncryptionScope
84+
Encryption scope to use when sending requests authorized with this SAS URI.
85+
86+
```yaml
87+
Type: System.String
88+
Parameter Sets: (All)
89+
Aliases:
90+
91+
Required: False
92+
Position: Named
93+
Default value: None
94+
Accept pipeline input: False
95+
Accept wildcard characters: False
96+
```
97+
8398
### -ExpiryTime
8499
Specifies the time at which the shared access signature becomes invalid.
85100
@@ -209,7 +224,7 @@ Accept wildcard characters: False
209224
```
210225
211226
### CommonParameters
212-
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).
227+
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).
213228
214229
## INPUTS
215230

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,32 @@ Generates a SAS token for an Azure storage blob.
1717
```
1818
New-AzStorageBlobSASToken [-Container] <String> [-Blob] <String> [-Permission <String>]
1919
[-Protocol <SharedAccessProtocol>] [-IPAddressOrRange <String>] [-StartTime <DateTime>]
20-
[-ExpiryTime <DateTime>] [-FullUri] [-Context <IStorageContext>] [-DefaultProfile <IAzureContextContainer>]
21-
[-WhatIf] [-Confirm] [<CommonParameters>]
20+
[-ExpiryTime <DateTime>] [-FullUri] [-EncryptionScope <String>] [-Context <IStorageContext>]
21+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2222
```
2323

2424
### BlobPipelineWithPolicy
2525
```
2626
New-AzStorageBlobSASToken -CloudBlob <CloudBlob> [-BlobBaseClient <BlobBaseClient>] -Policy <String>
2727
[-Protocol <SharedAccessProtocol>] [-IPAddressOrRange <String>] [-StartTime <DateTime>]
28-
[-ExpiryTime <DateTime>] [-FullUri] [-Context <IStorageContext>] [-DefaultProfile <IAzureContextContainer>]
29-
[-WhatIf] [-Confirm] [<CommonParameters>]
28+
[-ExpiryTime <DateTime>] [-FullUri] [-EncryptionScope <String>] [-Context <IStorageContext>]
29+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
3030
```
3131

3232
### BlobPipelineWithPermission
3333
```
3434
New-AzStorageBlobSASToken -CloudBlob <CloudBlob> [-BlobBaseClient <BlobBaseClient>] [-Permission <String>]
3535
[-Protocol <SharedAccessProtocol>] [-IPAddressOrRange <String>] [-StartTime <DateTime>]
36-
[-ExpiryTime <DateTime>] [-FullUri] [-Context <IStorageContext>] [-DefaultProfile <IAzureContextContainer>]
37-
[-WhatIf] [-Confirm] [<CommonParameters>]
36+
[-ExpiryTime <DateTime>] [-FullUri] [-EncryptionScope <String>] [-Context <IStorageContext>]
37+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
3838
```
3939

4040
### BlobNameWithPolicy
4141
```
4242
New-AzStorageBlobSASToken [-Container] <String> [-Blob] <String> -Policy <String>
4343
[-Protocol <SharedAccessProtocol>] [-IPAddressOrRange <String>] [-StartTime <DateTime>]
44-
[-ExpiryTime <DateTime>] [-FullUri] [-Context <IStorageContext>] [-DefaultProfile <IAzureContextContainer>]
45-
[-WhatIf] [-Confirm] [<CommonParameters>]
44+
[-ExpiryTime <DateTime>] [-FullUri] [-EncryptionScope <String>] [-Context <IStorageContext>]
45+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
4646
```
4747

4848
## DESCRIPTION
@@ -170,6 +170,21 @@ Accept pipeline input: False
170170
Accept wildcard characters: False
171171
```
172172
173+
### -EncryptionScope
174+
Encryption scope to use when sending requests authorized with this SAS URI.
175+
176+
```yaml
177+
Type: System.String
178+
Parameter Sets: (All)
179+
Aliases:
180+
181+
Required: False
182+
Position: Named
183+
Default value: None
184+
Accept pipeline input: False
185+
Accept wildcard characters: False
186+
```
187+
173188
### -ExpiryTime
174189
Specifies when the shared access signature expires.
175190
When the storage context is based on OAuth authentication, the expire time must be in 7 days from current time, and must not be earlier than current time.
@@ -314,7 +329,7 @@ Accept wildcard characters: False
314329
```
315330
316331
### CommonParameters
317-
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).
332+
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).
318333
319334
## INPUTS
320335

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ Generates an SAS token for an Azure storage container.
1717
```
1818
New-AzStorageContainerSASToken [-Name] <String> -Policy <String> [-Protocol <SharedAccessProtocol>]
1919
[-IPAddressOrRange <String>] [-StartTime <DateTime>] [-ExpiryTime <DateTime>] [-FullUri]
20-
[-Context <IStorageContext>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
21-
[<CommonParameters>]
20+
[-EncryptionScope <String>] [-Context <IStorageContext>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
21+
[-Confirm] [<CommonParameters>]
2222
```
2323

2424
### SasPermission
2525
```
2626
New-AzStorageContainerSASToken [-Name] <String> [-Permission <String>] [-Protocol <SharedAccessProtocol>]
2727
[-IPAddressOrRange <String>] [-StartTime <DateTime>] [-ExpiryTime <DateTime>] [-FullUri]
28-
[-Context <IStorageContext>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
29-
[<CommonParameters>]
28+
[-EncryptionScope <String>] [-Context <IStorageContext>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
29+
[-Confirm] [<CommonParameters>]
3030
```
3131

3232
## DESCRIPTION
@@ -99,6 +99,21 @@ Accept pipeline input: False
9999
Accept wildcard characters: False
100100
```
101101
102+
### -EncryptionScope
103+
Encryption scope to use when sending requests authorized with this SAS URI.
104+
105+
```yaml
106+
Type: System.String
107+
Parameter Sets: (All)
108+
Aliases:
109+
110+
Required: False
111+
Position: Named
112+
Default value: None
113+
Accept pipeline input: False
114+
Accept wildcard characters: False
115+
```
116+
102117
### -ExpiryTime
103118
Specifies the time at which the shared access signature becomes invalid.
104119
If the user sets the start time but not the expiry time, the expiry time is set to the start time plus one hour.
@@ -260,7 +275,7 @@ Accept wildcard characters: False
260275
```
261276
262277
### CommonParameters
263-
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).
278+
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).
264279
265280
## INPUTS
266281

src/Storage/Storage/Blob/Cmdlet/NewAzureStorageBlobSasToken.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ public string Policy
127127
[Parameter(Mandatory = false, HelpMessage = "Display full uri with sas token")]
128128
public SwitchParameter FullUri { get; set; }
129129

130+
[Parameter(Mandatory = false, HelpMessage = "Encryption scope to use when sending requests authorized with this SAS URI.")]
131+
[ValidateNotNullOrEmpty]
132+
public string EncryptionScope { get; set; }
133+
130134
// Overwrite the useless parameter
131135
public override int? ServerTimeoutPerRequest { get; set; }
132136
public override int? ClientTimeoutPerRequest { get; set; }
@@ -241,7 +245,7 @@ public override void ExecuteCmdlet()
241245
}
242246

243247
//Create SAS builder
244-
BlobSasBuilder sasBuilder = SasTokenHelper.SetBlobSasBuilder_FromBlob(blobClient, identifier, this.Permission, this.StartTime, this.ExpiryTime, this.IPAddressOrRange, this.Protocol);
248+
BlobSasBuilder sasBuilder = SasTokenHelper.SetBlobSasBuilder_FromBlob(blobClient, identifier, this.Permission, this.StartTime, this.ExpiryTime, this.IPAddressOrRange, this.Protocol, this.EncryptionScope);
245249

246250
//Create SAS and ourput
247251
string sasToken = SasTokenHelper.GetBlobSharedAccessSignature(Channel.StorageContext, sasBuilder, generateUserDelegationSas, ClientOptions, CmdletCancellationToken);

src/Storage/Storage/Blob/Cmdlet/NewAzureStorageContainerSasToken.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ public string Policy
8585
[Parameter(Mandatory = false, HelpMessage = "Display full uri with sas token")]
8686
public SwitchParameter FullUri { get; set; }
8787

88+
[Parameter(Mandatory = false, HelpMessage = "Encryption scope to use when sending requests authorized with this SAS URI.")]
89+
[ValidateNotNullOrEmpty]
90+
public string EncryptionScope { get; set; }
91+
8892
// Overwrite the useless parameter
8993
public override int? ServerTimeoutPerRequest { get; set; }
9094
public override int? ClientTimeoutPerRequest { get; set; }
@@ -181,7 +185,7 @@ public override void ExecuteCmdlet()
181185
}
182186

183187
//Create SAS builder
184-
BlobSasBuilder sasBuilder = SasTokenHelper.SetBlobSasBuilder_FromContainer(container, identifier, this.Permission, this.StartTime, this.ExpiryTime, this.IPAddressOrRange, this.Protocol);
188+
BlobSasBuilder sasBuilder = SasTokenHelper.SetBlobSasBuilder_FromContainer(container, identifier, this.Permission, this.StartTime, this.ExpiryTime, this.IPAddressOrRange, this.Protocol, this.EncryptionScope);
185189

186190
//Create SAS and output it
187191
string sasToken = SasTokenHelper.GetBlobSharedAccessSignature(Channel.StorageContext, sasBuilder, generateUserDelegationSas, ClientOptions, CmdletCancellationToken);

0 commit comments

Comments
 (0)