Skip to content

Commit 9dfdc84

Browse files
Combine SAS articles for containers and blobs
1 parent 05db9e6 commit 9dfdc84

File tree

2 files changed

+73
-13
lines changed

2 files changed

+73
-13
lines changed

articles/storage/blobs/sas-service-create-python.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
11
---
2-
title: Create a service SAS for a blob with Python
2+
title: Create a service SAS for a container or blob with Python
33
titleSuffix: Azure Storage
4-
description: Learn how to create a service shared access signature (SAS) for a blob using the Azure Blob Storage client library for Python.
4+
description: Learn how to create a service shared access signature (SAS) for a container or blob using the Azure Blob Storage client library for Python.
55
author: pauljewellmsft
66

77
ms.service: azure-blob-storage
88
ms.topic: how-to
9-
ms.date: 08/05/2024
9+
ms.date: 09/06/2024
1010
ms.author: pauljewell
1111
ms.reviewer: nachakra
1212
ms.devlang: python
1313
ms.custom: devx-track-python, devguide-python, engagement-fy23
1414
---
1515

16-
# Create a service SAS for a blob with Python
16+
# Create a service SAS for a container or blob with Python
1717

1818
[!INCLUDE [storage-dev-guide-selector-service-sas](../../../includes/storage-dev-guides/storage-dev-guide-selector-service-sas.md)]
1919

2020
[!INCLUDE [storage-auth-sas-intro-include](../../../includes/storage-auth-sas-intro-include.md)]
2121

22-
This article shows how to use the storage account key to create a service SAS for a blob with the Blob Storage client library for Python.
22+
This article shows how to use the storage account key to create a service SAS for a container or blob with the Blob Storage client library for Python.
2323

2424
## About the service SAS
2525

2626
A service SAS is signed with the storage account access key. A service SAS delegates access to a resource in a single Azure Storage service, such as Blob Storage.
2727

2828
You can also use a stored access policy to define the permissions and duration of the SAS. If the name of an existing stored access policy is provided, that policy is associated with the SAS. To learn more about stored access policies, see [Define a stored access policy](/rest/api/storageservices/define-stored-access-policy). If no stored access policy is provided, the code examples in this article show how to define permissions and duration for the SAS.
2929

30-
## Create a service SAS for a blob
30+
## Create a service SAS
31+
32+
You can create a service SAS for a container or blob, based on the needs of your app.
33+
34+
### [Container](#tab/container)
35+
36+
You can create a service SAS to delegate limited access to a container resource using the following method:
37+
38+
- [generate_container_sas](/python/api/azure-storage-blob/azure.storage.blob#azure-storage-blob-generate-blob-sas)
39+
40+
The storage account access key used to sign the SAS is passed to the method as the `account_key` argument. Allowed permissions are passed to the method as the `permission` argument, and are defined in the [ContainerSasPermissions](/python/api/azure-storage-blob/azure.storage.blob.containersaspermissions) class.
41+
42+
The following code example shows how to create a service SAS with read permissions for a container resource:
43+
44+
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob_devguide_create_sas.py" id="Snippet_create_service_sas_container":::
45+
46+
### [Blob](#tab/blob)
3147

3248
You can create a service SAS to delegate limited access to a blob resource using the following method:
3349

@@ -39,12 +55,26 @@ The following code example shows how to create a service SAS with read permissio
3955

4056
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob_devguide_create_sas.py" id="Snippet_create_service_sas_blob":::
4157

58+
---
59+
4260
## Use a service SAS to authorize a client object
4361

62+
You can use a service SAS to authorize a client object to perform operations on a container or blob based on the permissions granted by the SAS.
63+
64+
### [Container](#tab/container)
65+
66+
The following code example shows how to use the service SAS created in the earlier example to authorize a [ContainerClient](/python/api/azure-storage-blob/azure.storage.blob.containerclient) object. This client object can be used to perform operations on the container resource based on the permissions granted by the SAS.
67+
68+
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob_devguide_create_sas.py" id="Snippet_use_service_sas_container":::
69+
70+
### [Blob](#tab/blob)
71+
4472
The following code example shows how to use the service SAS created in the earlier example to authorize a [BlobClient](/python/api/azure-storage-blob/azure.storage.blob.blobclient) object. This client object can be used to perform operations on the blob resource based on the permissions granted by the SAS.
4573

4674
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob_devguide_create_sas.py" id="Snippet_use_service_sas_blob":::
4775

76+
---
77+
4878
## Resources
4979

5080
To learn more about using the Azure Blob Storage client library for Python, see the following resources.

articles/storage/blobs/storage-blob-user-delegation-sas-create-python.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,51 @@
11
---
2-
title: Create a user delegation SAS for a blob with Python
2+
title: Create a user delegation SAS for a container or blob with Python
33
titleSuffix: Azure Storage
4-
description: Learn how to create a user delegation SAS for a blob with Microsoft Entra credentials by using the Python client library for Blob Storage.
4+
description: Learn how to create a user delegation SAS for a container or blob with Microsoft Entra credentials by using the Python client library for Blob Storage.
55
services: storage
66
author: pauljewellmsft
77
ms.author: pauljewell
88
ms.service: azure-blob-storage
99
ms.topic: how-to
10-
ms.date: 08/05/2024
10+
ms.date: 09/06/2024
1111
ms.reviewer: dineshm
1212
ms.devlang: python
1313
ms.custom: devx-track-python, devguide-python
1414
---
1515

16-
# Create a user delegation SAS for a blob with Python
16+
# Create a user delegation SAS for a container or blob with Python
1717

1818
[!INCLUDE [storage-dev-guide-selector-user-delegation-sas](../../../includes/storage-dev-guides/storage-dev-guide-selector-user-delegation-sas.md)]
1919

2020
[!INCLUDE [storage-auth-sas-intro-include](../../../includes/storage-auth-sas-intro-include.md)]
2121

22-
This article shows how to use Microsoft Entra credentials to create a user delegation SAS for a blob using the [Azure Storage client library for Python](/python/api/overview/azure/storage).
22+
This article shows how to use Microsoft Entra credentials to create a user delegation SAS for a container or blob using the [Azure Storage client library for Python](/python/api/overview/azure/storage).
2323

2424
[!INCLUDE [storage-auth-user-delegation-include](../../../includes/storage-auth-user-delegation-include.md)]
2525

2626
## Assign Azure roles for access to data
2727

28-
When a Microsoft Entra security principal attempts to access blob data, that security principal must have permissions to the resource. Whether the security principal is a managed identity in Azure or a Microsoft Entra user account running code in the development environment, the security principal must be assigned an Azure role that grants access to blob data. For information about assigning permissions via Azure RBAC, see [Assign an Azure role for access to blob data](assign-azure-role-data-access.md).
28+
When a Microsoft Entra security principal attempts to access data, that security principal must have permissions to the resource. Whether the security principal is a managed identity in Azure or a Microsoft Entra user account running code in the development environment, the security principal must be assigned an Azure role that grants access to data. For information about assigning permissions via Azure RBAC, see [Assign an Azure role for access to blob data](assign-azure-role-data-access.md).
2929

3030
[!INCLUDE [storage-dev-guide-user-delegation-sas-python](../../../includes/storage-dev-guides/storage-dev-guide-user-delegation-sas-python.md)]
3131

32-
## Create a user delegation SAS for a blob
32+
## Create a user delegation SAS
33+
34+
You can create a user delegation SAS for a container or blob, based on the needs of your app.
35+
36+
### [Container](#tab/container)
37+
38+
Once you've obtained the user delegation key, you can create a user delegation SAS. You can create a user delegation SAS to delegate limited access to a container resource using the following method:
39+
40+
- [generate_container_sas](/python/api/azure-storage-blob/azure.storage.blob#azure-storage-blob-generate-container-sas)
41+
42+
The user delegation key to sign the SAS is passed to the method as the `user_delegation_key` argument. Allowed permissions are passed to the method as the `permission` argument, and are defined in the [ContainerSasPermissions](/python/api/azure-storage-blob/azure.storage.blob.containersaspermissions) class.
43+
44+
The following code example shows how to create a user delegation SAS for a container:
45+
46+
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob_devguide_create_sas.py" id="Snippet_create_user_delegation_sas_container":::
47+
48+
### [Blob](#tab/blob)
3349

3450
Once you've obtained the user delegation key, you can create a user delegation SAS. You can create a user delegation SAS to delegate limited access to a blob resource using the following method:
3551

@@ -41,12 +57,26 @@ The following code example shows how to create a user delegation SAS for a blob:
4157

4258
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob_devguide_create_sas.py" id="Snippet_create_user_delegation_sas_blob":::
4359

60+
---
61+
4462
## Use a user delegation SAS to authorize a client object
4563

64+
You can use a user delegation SAS to authorize a client object to perform operations on a container or blob based on the permissions granted by the SAS.
65+
66+
### [Container](#tab/container)
67+
68+
The following code example shows how to use the user delegation SAS created in the earlier example to authorize a [ContainerClient](/python/api/azure-storage-blob/azure.storage.blob.containerclient) object. This client object can be used to perform operations on the container resource based on the permissions granted by the SAS.
69+
70+
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob_devguide_create_sas.py" id="Snippet_use_user_delegation_sas_container":::
71+
72+
### [Blob](#tab/blob)
73+
4674
The following code example shows how to use the user delegation SAS created in the earlier example to authorize a [BlobClient](/python/api/azure-storage-blob/azure.storage.blob.blobclient) object. This client object can be used to perform operations on the blob resource based on the permissions granted by the SAS.
4775

4876
:::code language="python" source="~/azure-storage-snippets/blobs/howto/python/blob-devguide-py/blob_devguide_create_sas.py" id="Snippet_use_user_delegation_sas_blob":::
4977

78+
---
79+
5080
## Resources
5181

5282
To learn more about creating a user delegation SAS using the Azure Blob Storage client library for Python, see the following resources.

0 commit comments

Comments
 (0)