Which resource type I need to choose for SAS

Shaojun Qin 105 Reputation points
2024-04-24T09:01:30.8466667+00:00

I want to generate a SAS.

I want to ensure that the SAS can only be used to list and download blobs stored in the container.

In the "allowed resource types" session, shall I choose container or object?

And Why?

Thanks.

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,200 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sumarigo-MSFT 47,471 Reputation points Microsoft Employee Moderator
    2024-04-24T10:27:57.6666667+00:00

    @Shaojun Qin Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    Adding more information to the above response!

    Most easiest way to provide SAS access through Storage explorer tool

    Animation

    Allowed Service: Blob Allowed Resource Types: Object (Service & Container may also be required) Allowed Permissions: Read, Write, Create

    If there are other actions that allow you to browse and create/list Azure storage blob containers in the Azure Portal or from T-SQL, then the allowed permissions and allowed resource types will need to include the additional scope. More information about Blob Service operations and permissions, which details the specific information you are looking for.

    For general information about Shared Access Signatures, please see: Grant limited access to Azure Storage resources using shared access signatures (SAS)

    • Service (s): Access to service-level APIs (e.g., Get/Set Service Properties, Get Service Stats, List Containers/Queues/Tables/Shares)
    • Container (c): Access to container-level APIs (e.g., Create/Delete Container, Create/Delete Queue, Create/Delete Table, Create/Delete Share, List Blobs/Files and Directories)
    • Object (o): Access to object-level APIs for blobs, queue messages, table entities, and files(e.g. Put Blob, Query Entity, Get Messages, Create File, etc.)
    • You can combine values to provide access to more than one resource type. For example, srt=sc specifies access to service and container resources.

    If you want to generate a SAS that can only be used to list and download blobs stored in the container, you should choose "Container" as the allowed resource type in the SAS definition.

    When you choose "Container" as the allowed resource type, the SAS can be used to perform operations on the container itself, as well as on any blobs stored in the container. This means that the SAS can be used to list the blobs in the container and to download the blobs, but it cannot be used to modify or delete the blobs.

    If you choose "Object" as the allowed resource type, the SAS can be used to perform operations on individual blobs, as well as on the container itself. This means that the SAS can be used to list, download, modify, and delete the blobs in the container.

    Therefore, if you want to restrict the SAS to only allow listing and downloading of blobs, you should choose "Container" as the allowed resource type. This will ensure that the SAS can only be used to perform operations on the container itself and not on individual blobs.

    User's image

    If you provide write access to a blob, a user may choose to upload a 200 GB blob. If you've given them read access as well, they may choose to download it 10 times, incurring 2 TB in egress costs for you. Again, provide limited permissions to help mitigate the potential actions of malicious users. Use short-lived SAS to reduce this threat (but be mindful of clock skew on the end time).

    Grant the least possible privileges with the SAS. A security best practice is to provide a user with the minimum required privileges to the fewest possible resources. Use a read-only SAS when possible. If a user needs only read access to a single object, then grant them read access to that single object, and not read/write/delete access to all objects. This also helps lessen the damage if a SAS is compromised because the SAS has less power in the hands of an attacker.

    There is no direct way to identify which clients have accessed a resource. However, you can use the unique fields in the SAS, the signed IP (sip), signed start (st), and signed expiry (se) fields, to track access. For example, you can generate a SAS token with a unique expiry time that you can then correlate with the client to whom it was issued.

    For more information refer to this article: https://learn.microsoft.com/en-us/rest/api/storageservices/create-user-delegation-sas#specify-the-signed-resource-field

    Please let us know if you have any further queries. I’m happy to assist you further.    


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Azar 29,520 Reputation points MVP Volunteer Moderator
    2024-04-24T09:07:53.0733333+00:00

    Hi there Shaojun Qin

    i suggest you should choose the "container" option for the allowed resource types.

    When you choose "container" as the allowed resource type, the SAS grants access to operations performed at the container level. This means that the SAS will allow listing and downloading blobs within the specified container.

    By granting access at the container level, you streamline access control for all blobs within the container. This can be more efficient than specifying access for individual objects (blobs), especially if you have a large number of blobs within the container.

    Choosing the container level simplifies the management of access control. Instead of generating and managing SAS tokens for each individual blob, you can use a single SAS token for the entire container.

    If this helps kindly accept the answer thanks much.

    0 comments No comments

  2. Andreas Baumgarten 123.6K Reputation points MVP Volunteer Moderator
    2024-04-24T09:13:53.9966667+00:00

    Hi @Shaojun Qin ,

    based on your question of "allowed resource types - container or object":

    The difference between container and object:

    Containers means: permissions on container level -> create/manage/delete containers, shares, tables, list blobs

    objectsmeans: permission to access objects -> Put Blob, Query Entity, Get Messages, Create File, ...

    Based on your requirements " list and download blobs stored in the container" it should be objects than. In my opinion containers is a little bit to much permission as you could delete a container for instance.


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.