Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
96b6c77
Add cmdlet to create Account SAS token.
EmmaZhu Oct 23, 2015
369ba96
Merge branch 'dev' of https://github.com/wastoresh/azure-powershell i…
EmmaZhu Nov 5, 2015
e886fab
Resolve a build issue.
EmmaZhu Nov 5, 2015
11a8813
Fix an issue of cannot indicate starttime and expirytime in New-Azure…
EmmaZhu Nov 6, 2015
2ee5fa5
Resolve a build issue.
EmmaZhu Nov 9, 2015
430d30a
Fix issue that doesn't throw out exceptions when the starting copying…
EmmaZhu Feb 2, 2016
7a2ccb0
Merge branch 'accountsas' of https://github.com/wastoresh/azure-power…
blueww Feb 3, 2016
2b2f318
RDTask 5684669:[PSH] Support Protocal/IPAcl in Blob/File/Table/Queue SAS
blueww Feb 15, 2016
9ea5cb2
Merge branch 'dev' of https://github.com/wastoresh/azure-powershell i…
blueww Feb 16, 2016
34d24a4
Merge branch 'accountsas' of https://github.com/wastoresh/azure-power…
blueww Feb 16, 2016
8fbed7b
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
EmmaZhu Feb 16, 2016
1da2298
Merge branch 'dev' of https://github.com/wastoresh/azure-powershell i…
blueww Feb 16, 2016
0957564
RDTask 5684669:[PSH] Support Protocal/IPAcl in Blob/File/Table/Queue …
blueww Feb 17, 2016
83fce2c
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
blueww Feb 18, 2016
ba626a2
fix a indentation from code review
blueww Feb 19, 2016
e4a3b55
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
blueww Feb 22, 2016
4ee7514
RDBug 5795841:[PSH] Failed to upload zero size of file to Azure File:…
blueww Feb 22, 2016
83f197f
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
blueww Feb 23, 2016
bfeebb8
Change the PR as comments from Hovsep
blueww Feb 23, 2016
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
10 changes: 10 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
* Set-AzureLogicAppAccessKey
* Set-AzureLogicApp
* Stop-AzureLogicAppRun
* Azure Storage
* Added cmdlet to generate SAS token against storage account
- New-AzureStorageAccountSASToken
* Added IPAddressOrRange/Protocol support in cmdlets to generate SAS token against blob, container, file, share, table, queue
- New-AzureStorageBlobSASToken
- New-AzureStorageContainerSASToken
- New-AzureStorageFileSASToken
- New-AzureStorageShareSASToken
- New-AzureStorageQueueSASToken
- New-AzureStorageTableSASToken

## 2016.02.04 version 1.2.1
* Fix installer issue - remove PSGallery modules on install
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,16 @@ public Task<string> StartCopyAsync(CloudBlob blob, Uri source, AccessCondition s
throw new NotImplementedException();
}

/// <summary>
/// Get the SAS token for an account.
/// </summary>
/// <param name="sharedAccessAccountPolicy">Shared access policy to generate the SAS token.</param>
/// <returns>Account SAS token.</returns>
public string GetStorageAccountSASToken(SharedAccessAccountPolicy sharedAccessAccountPolicy)
{
throw new NotImplementedException();
}

/// <summary>
/// The storage context
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet
using Microsoft.WindowsAzure.Commands.Storage.Common;
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage;

[Cmdlet(VerbsCommon.New, StorageNouns.BlobSas, DefaultParameterSetName = BlobNamePipelineParmeterSetWithPermission), OutputType(typeof(String))]
public class NewAzureStorageBlobSasTokenCommand : StorageCloudBlobCmdletBase
Expand Down Expand Up @@ -80,6 +81,12 @@ public string Policy
ParameterSetName = BlobPipelineParameterSetWithPermision)]
public string Permission { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")]
public SharedAccessProtocol Protocol { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an appropriate parameter type - as a user, it is unclear to me how to create this type. This needs to be a simple type, or a type that can be easily created from another cmdlet. Preferrably a simple type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves.


[Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")]
public string IPAddressOrRange { get; set; }

[Parameter(HelpMessage = "Start Time")]
public DateTime? StartTime { get; set; }

Expand Down Expand Up @@ -133,7 +140,7 @@ public override void ExecuteCmdlet()
SharedAccessBlobPolicy accessPolicy = new SharedAccessBlobPolicy();
bool shouldSetExpiryTime = SasTokenHelper.ValidateContainerAccessPolicy(Channel, blob.Container.Name, accessPolicy, accessPolicyIdentifier);
SetupAccessPolicy(accessPolicy, shouldSetExpiryTime);
string sasToken = GetBlobSharedAccessSignature(blob, accessPolicy, accessPolicyIdentifier);
string sasToken = GetBlobSharedAccessSignature(blob, accessPolicy, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange));

if (FullUri)
{
Expand All @@ -154,10 +161,10 @@ public override void ExecuteCmdlet()
/// <param name="accessPolicy">SharedAccessBlobPolicy object</param>
/// <param name="policyIdentifier">The existing policy identifier.</param>
/// <returns></returns>
private string GetBlobSharedAccessSignature(CloudBlob blob, SharedAccessBlobPolicy accessPolicy, string policyIdentifier)
private string GetBlobSharedAccessSignature(CloudBlob blob, SharedAccessBlobPolicy accessPolicy, string policyIdentifier, SharedAccessProtocol protocol, IPAddressOrRange iPAddressOrRange)
{
CloudBlobContainer container = blob.Container;
return blob.GetSharedAccessSignature(accessPolicy, policyIdentifier);
return blob.GetSharedAccessSignature(accessPolicy, null, policyIdentifier, protocol, iPAddressOrRange);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet
using Microsoft.WindowsAzure.Commands.Storage.Common;
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage;

[Cmdlet(VerbsCommon.New, StorageNouns.ContainerSas), OutputType(typeof(String))]
public class NewAzureStorageContainerSasTokenCommand : StorageCloudBlobCmdletBase
Expand Down Expand Up @@ -51,9 +52,15 @@ public string Policy
private string accessPolicyIdentifier;

[Parameter(HelpMessage = "Permissions for a container. Permissions can be any not-empty subset of \"rwdl\".",
ParameterSetName = SasPermissionParameterSet)]
ParameterSetName = SasPermissionParameterSet)]
public string Permission { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")]
public SharedAccessProtocol Protocol { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment. How do I create a SharedAccessProtocol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves.


[Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")]
public string IPAddressOrRange { get; set; }

[Parameter(HelpMessage = "Start Time")]
public DateTime? StartTime { get; set; }

Expand Down Expand Up @@ -98,7 +105,7 @@ public override void ExecuteCmdlet()
SharedAccessBlobPolicy accessPolicy = new SharedAccessBlobPolicy();
bool shouldSetExpiryTime = SasTokenHelper.ValidateContainerAccessPolicy(Channel, container.Name, accessPolicy, accessPolicyIdentifier);
SetupAccessPolicy(accessPolicy, shouldSetExpiryTime);
string sasToken = container.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier);
string sasToken = container.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange));

if (FullUri)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ private async Task StartCopyFromBlob(long taskId, IStorageBlobManagement destCha
// Opened workitem 1487579 to track this.
throw new InvalidOperationException(Resources.DestinationBlobTypeNotMatch);
}
else
{
throw;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
<Compile Include="Common\BlobToFileSystemNameResolver.cs" />
<Compile Include="Blob\Cmdlet\StartAzureStorageBlobCopy.cs" />
<Compile Include="Blob\Cmdlet\StopAzureStorageBlobCopy.cs" />
<Compile Include="Common\Cmdlet\NewAzureStorageAccountSasToken.cs" />
<Compile Include="Common\Cmdlet\SetAzureStorageCORSRule.cs" />
<Compile Include="Common\Cmdlet\GetAzureStorageCORSRule.cs" />
<Compile Include="Common\Cmdlet\GetAzureStorageServiceLogging.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.WindowsAzure.Commands.Storage.Common.Cmdlet
{
using System;
using System.Management.Automation;
using System.Security.Permissions;
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
using Microsoft.WindowsAzure.Storage;

[Cmdlet(VerbsCommon.New, StorageNouns.AccountSas), OutputType(typeof(String))]
public class NewAzureStorageAccountSasTokenCommand : StorageCloudBlobCmdletBase
{
[Parameter(Mandatory = true, HelpMessage = "Service type that this SAS token applies to.")]
public SharedAccessAccountServices Service { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I create this type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SharedAccessAccountServices , SharedAccessAccountResourceTypes , SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves.


[Parameter(Mandatory = true, HelpMessage = "Resource type that this SAS token applies to.")]
public SharedAccessAccountResourceTypes ResourceType { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do I create this type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SharedAccessAccountServices , SharedAccessAccountResourceTypes , SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves.


[Parameter(Mandatory = true, HelpMessage = "Permissions.")]
public string Permission { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")]
public SharedAccessProtocol Protocol { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SharedAccessAccountServices , SharedAccessAccountResourceTypes , SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves.


[Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")]
public string IPAddressOrRange { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Start Time")]
public DateTime? StartTime { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Expiry Time")]
public DateTime? ExpiryTime { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExpirationTime

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ExpiryTime" is standard name in azure rest API, and consistent with other new SAS token cmdlets which already exist for a long time. So we don't suggest to change that.


// Overwrite the useless parameter
public override int? ServerTimeoutPerRequest { get; set; }
public override int? ClientTimeoutPerRequest { get; set; }
public override int? ConcurrentTaskCount { get; set; }

/// <summary>
/// Initializes a new instance of the NewAzureStorageAccountSasTokenCommand class.
/// </summary>
public NewAzureStorageAccountSasTokenCommand()
: this(null)
{
}

/// <summary>
/// Initializes a new instance of the NewAzureStorageAccountSasTokenCommand class.
/// </summary>
/// <param name="channel">IStorageBlobManagement channel</param>
public NewAzureStorageAccountSasTokenCommand(IStorageBlobManagement channel)
{
Channel = channel;
EnableMultiThread = false;
}

/// <summary>
/// Execute command
/// </summary>
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public override void ExecuteCmdlet()
{
var sharedAccessPolicy = new SharedAccessAccountPolicy()
{
Permissions = SetupAccessPolicyPermission(this.Permission),
Services = Service,
ResourceTypes = ResourceType,
Protocols = Protocol,
IPAddressOrRange = Util.SetupIPAddressOrRangeForSAS(this.IPAddressOrRange)
};

DateTimeOffset? accessStartTime;
DateTimeOffset? accessEndTime;
SasTokenHelper.SetupAccessPolicyLifeTime(StartTime, ExpiryTime,
out accessStartTime, out accessEndTime, true);
sharedAccessPolicy.SharedAccessStartTime = accessStartTime;
sharedAccessPolicy.SharedAccessExpiryTime = accessEndTime;

this.WriteObject(Channel.GetStorageAccountSASToken(sharedAccessPolicy));
}

/// <summary>
/// Set up access policy permission
/// </summary>
/// <param name="policy">SharedAccessBlobPolicy object</param>
/// <param name="permission">Permisson</param>
internal SharedAccessAccountPermissions SetupAccessPolicyPermission(string permission)
{
if (string.IsNullOrEmpty(permission)) return SharedAccessAccountPermissions.None;

SharedAccessAccountPermissions accountPermission = SharedAccessAccountPermissions.None;
permission = permission.ToLower();
foreach (char op in permission)
{
switch (op)
{
case StorageNouns.Permission.Read:
case StorageNouns.Permission.Query:
accountPermission |= SharedAccessAccountPermissions.Read;
break;
case StorageNouns.Permission.Process:
accountPermission |= SharedAccessAccountPermissions.ProcessMessages;
break;
case StorageNouns.Permission.Write:
accountPermission |= SharedAccessAccountPermissions.Write;
break;
case StorageNouns.Permission.Add:
accountPermission |= SharedAccessAccountPermissions.Add;
break;
case StorageNouns.Permission.Create:
accountPermission |= SharedAccessAccountPermissions.Create;
break;
case StorageNouns.Permission.Update:
accountPermission |= SharedAccessAccountPermissions.Update;
break;
case StorageNouns.Permission.Delete:
accountPermission |= SharedAccessAccountPermissions.Delete;
break;
case StorageNouns.Permission.List:
accountPermission |= SharedAccessAccountPermissions.List;
break;
default:
throw new ArgumentException(string.Format(Resources.InvalidAccessPermission, op));
}
}

return accountPermission;
}
}
}
10 changes: 10 additions & 0 deletions src/Common/Storage/Commands.Storage/Common/StorageNouns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public static class StorageNouns
/// </summary>
public const string StorageCORSRule = "AzureStorageCORSRule";

/// <summary>
/// Azure storage account sas
/// </summary>
public const string AccountSas = "AzureStorageAccountSASToken";

/// <summary>
/// Azure storage container sas
/// </summary>
Expand Down Expand Up @@ -214,6 +219,11 @@ public static class Permission
/// Query permission
/// </summary>
public const char Query = 'q';

/// <summary>
/// Create permission.
/// </summary>
public const char Create = 'c';
}
}
}
16 changes: 16 additions & 0 deletions src/Common/Storage/Commands.Storage/Common/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,21 @@ public static CloudBlob GetBlobReference(Uri blobUri, StorageCredentials storage
blobUri));
}
}

public static IPAddressOrRange SetupIPAddressOrRangeForSAS(string inputIPACL)
{
if (string.IsNullOrEmpty(inputIPACL)) return null;

int separator = inputIPACL.IndexOf('-');

if (-1 == separator)
{
return new IPAddressOrRange(inputIPACL);
}
else
{
return new IPAddressOrRange(inputIPACL.Substring(0, separator), inputIPACL.Substring(separator + 1));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Microsoft.WindowsAzure.Commands.Storage.Common;
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
using Microsoft.WindowsAzure.Storage.File;
using Microsoft.WindowsAzure.Storage;

namespace Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet
{
Expand Down Expand Up @@ -104,6 +105,12 @@ public string Policy
ParameterSetName = CloudFileSasPermissionParameterSet)]
public string Permission { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")]
public SharedAccessProtocol Protocol { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SharedAccessAccountServices , SharedAccessAccountResourceTypes , SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves.


[Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")]
public string IPAddressOrRange { get; set; }

[Parameter(HelpMessage = "Start Time")]
public DateTime? StartTime { get; set; }

Expand All @@ -123,6 +130,11 @@ public string Policy
ParameterSetName = NameSasPolicyParmeterSet)]
public override AzureStorageContext Context { get; set; }

// Overwrite the useless parameter
public override int? ServerTimeoutPerRequest { get; set; }
public override int? ClientTimeoutPerRequest { get; set; }
public override int? ConcurrentTaskCount { get; set; }

/// <summary>
/// Execute command
/// </summary>
Expand Down Expand Up @@ -158,7 +170,7 @@ public override void ExecuteCmdlet()

SetupAccessPolicy(accessPolicy, shouldSetExpiryTime);

string sasToken = file.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier);
string sasToken = file.GetSharedAccessSignature(accessPolicy, null, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange));

if (FullUri)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Microsoft.WindowsAzure.Commands.Storage.File.Cmdlet
using Microsoft.WindowsAzure.Commands.Storage.Common;
using Microsoft.WindowsAzure.Commands.Storage.Model.Contract;
using Microsoft.WindowsAzure.Storage.File;
using Microsoft.WindowsAzure.Storage;

[Cmdlet(VerbsCommon.New, StorageNouns.ShareSas), OutputType(typeof(String))]
public class NewAzureStorageShareSasToken : AzureStorageFileCmdletBase
Expand Down Expand Up @@ -56,6 +57,12 @@ public string Policy
ParameterSetName = SasPermissionParameterSet)]
public string Permission { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Protocol can be used in the request with this SAS token.")]
public SharedAccessProtocol Protocol { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SharedAccessAccountServices , SharedAccessAccountResourceTypes , SharedAccessProtocol is an Enum, and Powershell support Enum well. Use can just tab to get the enum value, don't need to create by themselves.


[Parameter(Mandatory = false, HelpMessage = "IP, or IP range ACL (access control list) that the request would be accepted from by Azure Storage.")]
public string IPAddressOrRange { get; set; }

[Parameter(HelpMessage = "Start Time")]
public DateTime? StartTime { get; set; }

Expand Down Expand Up @@ -95,7 +102,7 @@ public override void ExecuteCmdlet()
this.ExpiryTime.HasValue);

SetupAccessPolicy(accessPolicy, shouldSetExpiryTime);
string sasToken = fileShare.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier);
string sasToken = fileShare.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange));

if (FullUri)
{
Expand Down
Loading