Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] Fix 2 Blob SAS issue #15648

Merged
merged 1 commit into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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