Skip to content

Fix Get-AzureStorageContainer with Account SAS failure #5420

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

Merged
merged 3 commits into from
Feb 7, 2018

Conversation

blueww
Copy link
Member

@blueww blueww commented Feb 1, 2018

Description

Get-AzureStorageContainer not work when use storage context created from SAS credential. #5053

This is because we will get container ACL after list/get container finish, but get container ACL only work with Account Key credential. We have catch 404 before for permission issue, but currently server report 403 for permission issue. So the fix is also catch 403 when get container ACL failure. So we can just return the container object to customer when get container ACL failed with permission issue. We will also write a warning message when customer get container with SAS credential to remind them get container ACL will fail.


This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.
  • The pull request does not introduce breaking changes (unless a major version change occurs in the assembly and module).

Testing Guidelines

  • Pull request includes test coverage for the included changes.
  • PowerShell scripts used in tests should do any necessary setup as part of the test or suite setup, and should not use hard-coded values for locations or existing resources.

Cmdlet Signature Guidelines

  • New cmdlets that make changes or have side effects should implement ShouldProcess and have SupportShouldProcess=true specified in the cmdlet attribute. You can find more information on ShouldProcess here.
  • Cmdlet specifies OutputType attribute if any output is produced - if the cmdlet produces no output, it should implement a PassThru parameter.

Cmdlet Parameter Guidelines

  • Parameter types should not expose types from the management library - complex parameter types should be defined in the module.
  • Complex parameter types are discouraged - a parameter type should be simple types as often as possible. If complex types are used, they should be shallow and easily creatable from a constructor or another cmdlet.
  • Cmdlet parameter sets should be mutually exclusive - each parameter set must have at least one mandatory parameter not in other parameter sets.

@blueww
Copy link
Member Author

blueww commented Feb 2, 2018

@@ -233,11 +240,11 @@ internal void PackCloudBlobContainerWithAcl(IEnumerable<Tuple<CloudBlobContainer
}
catch (StorageException e)
{
if (!e.IsNotFoundException())
if (!e.IsNotFoundException() && !e.IsFordiddenException())
Copy link
Member

Choose a reason for hiding this comment

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

@blueww we should change how exceptions are being thrown here so that the properties of the exception are preserved. This means only catching the exceptions that throw a 403 or 404. We should also put the warning you're adding above in here rather than having it before the check. You can change the message slightly so it applies to both 403 and 404 scenarios. It should look something like the following:

catch (StorageException e) when (e.IsNotFoundException() || e.IsForbiddenException())
{
    WriteWarning("Denied permission to query the permission of the specified container.");
}

Copy link
Member Author

@blueww blueww Feb 5, 2018

Choose a reason for hiding this comment

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

@cormacpayne

If change as you required, will get following error. This is because query container ACL is executed in aync task. So we can't write warning in it. We also can't write warning after track the task (in main thread), since the task might not finish when we try to write warning.

As currently, only SAS credential can make list container success, but query container ACL fail, (and I don't see it will be change recently), so it should be safe to check the credential is SAS, and write warning. how do you think?

BTW,I have modified the catch exception as you required.

Get-AzureStorageContainer : The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods, and they can only be called from within the same thread. Validate
that the cmdlet makes these calls correctly, or contact Microsoft Customer Support Services.
At line:1 char:1

  • Get-AzureStorageContainer -Context $ctxsas
  •  + CategoryInfo          : CloseError: (:) [Get-AzureStorageContainer], PSInvalidOperationException
     + FullyQualifiedErrorId : PSInvalidOperationException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.GetAzureStorageContainerCommand
    

@blueww
Copy link
Member Author

blueww commented Feb 6, 2018

@markcowl@cormacpayne
I have discussed with Mark in a meeting this morning, and we agree to write warning only when run the cmdlet with alias "Get-AzureStorageContainerACL", since it specify to get container ACL. And we also agreed on write the warning before run get ACL task.

I have changed the code according. Please check.
I am OK for the change in this or next release.

@cormacpayne cormacpayne changed the base branch from preview to release-2018-02-09 February 6, 2018 23:45
@cormacpayne
Copy link
Member

@markcowl markcowl dismissed cormacpayne’s stale review February 6, 2018 23:59

Talked with Cormac, he is ok

@markcowl markcowl merged commit 2fb2085 into Azure:release-2018-02-09 Feb 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants