Skip to content

Commit

Permalink
[Storage] Fix 2 sas issue (#15648)
Browse files Browse the repository at this point in the history
  • Loading branch information
blueww authored Aug 11, 2021
1 parent 4ad1464 commit 4024ada
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
6 changes: 6 additions & 0 deletions src/Storage/Storage.Management/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
- Additional information about change #1
-->
## Upcoming Release
* Generate blob sas token with new API version
- `New-AzStorageBlobSASToken`
- `New-AzStorageContainerSASToken`
- `New-AzStorageAccountSASToken`
* Fixed blob copy failure with OAuth credentail when client and server has time difference [#15644]
- `Copy-AzStorageBlob`
* Fixed remove datalakegen2 item fail with readonly SAS token
- `Remove-AzDataLakeGen2Item`
* Revised destination existing check in move datalakegen2 item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ public string Policy

protected override bool UseTrack2Sdk()
{
if (SasTokenHelper.IsTrack2Permission(this.Permission))
{
return true;
}
return base.UseTrack2Sdk();
return true;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ public string Policy
public override int? ConcurrentTaskCount { get; set; }
protected override bool UseTrack2Sdk()
{
if (SasTokenHelper.IsTrack2Permission(this.Permission))
{
return true;
}
return base.UseTrack2Sdk();
return true;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ public class NewAzureStorageAccountSasTokenCommand : StorageCloudBlobCmdletBase

protected override bool UseTrack2Sdk()
{
if (SasTokenHelper.IsTrack2Permission(this.Permission))
{
return true;
}
return base.UseTrack2Sdk();
return true;
}

/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions src/Storage/Storage/Common/StorageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ internal static class StorageExtensions
{
private const int CopySASLifeTimeInMinutes = 7 * 24 * 60;

// The Oauth delegate SAS expire time must be in 7 days.
// As client and server has time difference, to make it more stable, the time will be 1 hour less than 7 days.
private const int CopySASLifeTimeInMinutesOauth = 7 * 24 * 60 - 60;

internal static Uri GenerateUriWithCredentials(
this CloudFile file)
{
Expand Down Expand Up @@ -208,6 +212,10 @@ private static string GetBlobSasToken(CloudBlob blob)

// SAS life time is at least 10 minutes.
TimeSpan sasLifeTime = TimeSpan.FromMinutes(CopySASLifeTimeInMinutes);
if (blob.ServiceClient.Credentials.IsToken)
{
sasLifeTime = TimeSpan.FromMinutes(CopySASLifeTimeInMinutesOauth);
}

SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
{
Expand Down Expand Up @@ -253,6 +261,10 @@ private static string GetBlobSasToken(BlobBaseClient blob, AzureStorageContext c

// SAS life time is at least 10 minutes.
TimeSpan sasLifeTime = TimeSpan.FromMinutes(CopySASLifeTimeInMinutes);
if (context.StorageAccount.Credentials.IsToken)
{
sasLifeTime = TimeSpan.FromMinutes(CopySASLifeTimeInMinutesOauth);
}

BlobSasBuilder sasBuilder = new BlobSasBuilder
{
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/Storage/Common/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public static string GetVersionIdFromBlobUri(Uri BlobUri)
{
if (block.StartsWith(snapshotQueryParameter))
{
return DateTimeOffset.Parse(block.Replace(snapshotQueryParameter, "")).ToUniversalTime();
return DateTimeOffset.Parse(System.Web.HttpUtility.UrlDecode(block.Replace(snapshotQueryParameter, ""))).ToUniversalTime();
}
}
return null;
Expand Down

0 comments on commit 4024ada

Please sign in to comment.