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

Updated SasBuilder to correctly order raw string permissions #13433

Merged

Conversation

seanmcc-msft
Copy link
Member

@seanmcc-msft seanmcc-msft commented Jul 14, 2020

I updated BlobSasBuilder, ShareSasBuilder, DataLakeSasBuilder, and QueueSasBuilder to validate and re-order raw string permissions when the SetPermissions() method is called with a string.

@ghost ghost added the Storage Storage Service (Queues, Blobs, Files) label Jul 14, 2020
@blueww
Copy link
Member

blueww commented Jul 14, 2020

@seanmcc-msft
Thanks for the quick fix!
When can this release, can it release 1-2 days before 7/27 (code complete of 8/4 PSH)?
If not, I will try to use my own code to handle the raw permission convert first in PSH.

And a minor suggestion:
Sometimes user might want to generate SAS with permission that still not supported by release XSCL. (like for some SDK test framework, they will generate account SAS from Powershell with XSCL at first step, then user the SAS in all following test which contains not released features.)
So if we can still keep the capacity to allow user into a permission string without validation, it can help on this scenario. (Like add an optional parameter to allow user input raw permission string without validation.)

Anyway, this might not be a common customer scenario, just a minor suggestion.

// Check that each permission is a real SAS permission.
if (!validPermissionsSet.Contains(permission))
{
throw new ArgumentException($"{permission} is not a valid SAS permission");
Copy link
Member

@tg-msft tg-msft Jul 14, 2020

Choose a reason for hiding this comment

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

This is a nontrivial change. We've always allowed customers to do whatever they want with the raw permissions, but now you're forcing them to be a set of known values. Why not let the service reject unknown values? Why aren't we putting this behind something like an optional bool normalize = false param? Are we doing this consistently across languages?

Copy link
Member Author

@seanmcc-msft seanmcc-msft Jul 14, 2020

Choose a reason for hiding this comment

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

The service doesn't return a useful error message if you include an invalid permission - just "Unauthorized". The user has no way of knowing that they did wrong. Also, how do I re-order the permissions if the user provides permissions that don't exist?

Response if you include an invalid SAS permission:

HTTP/1.1 403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
Content-Length: 408
Content-Type: application/xml
Server: Microsoft-HTTPAPI/2.0
x-ms-request-id: 55282e2e-d01e-0002-0901-5a08f0000000
x-ms-error-code: AuthenticationFailed
Date: Tue, 14 Jul 2020 17:09:29 GMT

<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:55282e2e-d01e-0002-0901-5a08f0000000
Time:2020-07-14T17:09:30.2593026Z</Message><AuthenticationErrorDetail>Signature fields not well formed.</AuthenticationErrorDetail></Error>

@gapra-msft, @xiafu-msft, do we allow users to pass invalid raw SAS permissions in in Java and Python?

Copy link
Member Author

Choose a reason for hiding this comment

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

@tg-msft, my bad, I accidentally edited your comment and then reverted it back.

Copy link
Member

Choose a reason for hiding this comment

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

Can we get a bug filed against the service to return a better error message for an unknown permission? It should be fine to explain why a SAS permission is invalid per the service API rather than relative to a resource.

And yes, you can't order permissions you don't know about which is why I'm suggesting moving this validation + reordering logic behind an optional normalize flag. We normally don't validate anything on clients so we should make it optional if we're providing this as a convenience. This would also enable @blueww's scenario from above.

+@XiaoningLiu for JS as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in next iteration.

Copy link
Contributor

Choose a reason for hiding this comment

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

@tg-msft Java does not allow to pass raw permissions verbatim - they're always validated and ordered before generating sas. Python seems to accept union of *SasPermission (which validates and orders) and raw string, so user can pass raw string without any validation there.

Copy link
Member

Choose a reason for hiding this comment

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

So it sounds like Java is the outlier with no option to skip validation and we don't know about JS yet. Is it worth filing an issue for Java? I could see waiting to add this until someone asks because it wouldn't be a breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel that if I were implementing that from scratch I'd chose Java's approach as it reduces # of ways customer can get it wrong (it takes care of the ordering). So I'd rather change .NET and Python in next major rev. I think we should hold with changing Java until someone explicitly asks for that (not sure why would they want to do that).

Copy link
Member

@tg-msft tg-msft left a comment

Choose a reason for hiding this comment

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

Looks good

Comment on lines 1387 to 1389
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public void SetPermissions(string rawPermissions) { }
public void SetPermissions(string rawPermissions, bool normalize = false) { }
Copy link
Member

Choose a reason for hiding this comment

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

Nit - we mostly use the [EditorBrowsable(Never)] for hiding overloads with optional params. We'd typically solve this case with an extra overload.

@seanmcc-msft seanmcc-msft merged commit 96e4e5f into Azure:master Jul 16, 2020
@seanmcc-msft seanmcc-msft deleted the feature/storage/rawPermissions branch July 16, 2020 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants