Skip to content

Commit 4024ada

Browse files
authored
[Storage] Fix 2 sas issue (#15648)
1 parent 4ad1464 commit 4024ada

File tree

6 files changed

+22
-16
lines changed

6 files changed

+22
-16
lines changed

src/Storage/Storage.Management/ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Generate blob sas token with new API version
22+
- `New-AzStorageBlobSASToken`
23+
- `New-AzStorageContainerSASToken`
24+
- `New-AzStorageAccountSASToken`
25+
* Fixed blob copy failure with OAuth credentail when client and server has time difference [#15644]
26+
- `Copy-AzStorageBlob`
2127
* Fixed remove datalakegen2 item fail with readonly SAS token
2228
- `Remove-AzDataLakeGen2Item`
2329
* Revised destination existing check in move datalakegen2 item

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,7 @@ public string Policy
134134

135135
protected override bool UseTrack2Sdk()
136136
{
137-
if (SasTokenHelper.IsTrack2Permission(this.Permission))
138-
{
139-
return true;
140-
}
141-
return base.UseTrack2Sdk();
137+
return true;
142138
}
143139

144140
/// <summary>

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,7 @@ public string Policy
9191
public override int? ConcurrentTaskCount { get; set; }
9292
protected override bool UseTrack2Sdk()
9393
{
94-
if (SasTokenHelper.IsTrack2Permission(this.Permission))
95-
{
96-
return true;
97-
}
98-
return base.UseTrack2Sdk();
94+
return true;
9995
}
10096

10197
/// <summary>

src/Storage/Storage/Common/Cmdlet/NewAzureStorageAccountSasToken.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ public class NewAzureStorageAccountSasTokenCommand : StorageCloudBlobCmdletBase
5858

5959
protected override bool UseTrack2Sdk()
6060
{
61-
if (SasTokenHelper.IsTrack2Permission(this.Permission))
62-
{
63-
return true;
64-
}
65-
return base.UseTrack2Sdk();
61+
return true;
6662
}
6763

6864
/// <summary>

src/Storage/Storage/Common/StorageExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ internal static class StorageExtensions
2626
{
2727
private const int CopySASLifeTimeInMinutes = 7 * 24 * 60;
2828

29+
// The Oauth delegate SAS expire time must be in 7 days.
30+
// As client and server has time difference, to make it more stable, the time will be 1 hour less than 7 days.
31+
private const int CopySASLifeTimeInMinutesOauth = 7 * 24 * 60 - 60;
32+
2933
internal static Uri GenerateUriWithCredentials(
3034
this CloudFile file)
3135
{
@@ -208,6 +212,10 @@ private static string GetBlobSasToken(CloudBlob blob)
208212

209213
// SAS life time is at least 10 minutes.
210214
TimeSpan sasLifeTime = TimeSpan.FromMinutes(CopySASLifeTimeInMinutes);
215+
if (blob.ServiceClient.Credentials.IsToken)
216+
{
217+
sasLifeTime = TimeSpan.FromMinutes(CopySASLifeTimeInMinutesOauth);
218+
}
211219

212220
SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
213221
{
@@ -253,6 +261,10 @@ private static string GetBlobSasToken(BlobBaseClient blob, AzureStorageContext c
253261

254262
// SAS life time is at least 10 minutes.
255263
TimeSpan sasLifeTime = TimeSpan.FromMinutes(CopySASLifeTimeInMinutes);
264+
if (context.StorageAccount.Credentials.IsToken)
265+
{
266+
sasLifeTime = TimeSpan.FromMinutes(CopySASLifeTimeInMinutesOauth);
267+
}
256268

257269
BlobSasBuilder sasBuilder = new BlobSasBuilder
258270
{

src/Storage/Storage/Common/Util.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public static string GetVersionIdFromBlobUri(Uri BlobUri)
295295
{
296296
if (block.StartsWith(snapshotQueryParameter))
297297
{
298-
return DateTimeOffset.Parse(block.Replace(snapshotQueryParameter, "")).ToUniversalTime();
298+
return DateTimeOffset.Parse(System.Web.HttpUtility.UrlDecode(block.Replace(snapshotQueryParameter, ""))).ToUniversalTime();
299299
}
300300
}
301301
return null;

0 commit comments

Comments
 (0)