Примечание
Для доступа к этой странице требуется авторизация. Вы можете попробовать войти или изменить каталоги.
Для доступа к этой странице требуется авторизация. Вы можете попробовать изменить каталоги.
A shared access signature (SAS) enables you to grant limited access to containers and blobs in your storage account. При создании SAS необходимо указать его ограничения, включая ресурсы службы хранилища Azure, к которым разрешен доступ клиенту, разрешения, предоставленные для доступа к этим ресурсам, а также срок действия SAS.
Каждый SAS подписывается ключом. Подписать документ SAS можно одним из двух способов:
- С помощью ключа, созданного с помощью учетных данных Microsoft Entra. A SAS that is signed with Microsoft Entra credentials is a user delegation SAS. A client that creates a user delegation SAS must be assigned an Azure RBAC role that includes the Microsoft.Storage/storageAccounts/blobServices/generateUserDelegationKey action. Чтобы узнать больше, см. статью «Создание SAS делегирования пользователей».
- With the storage account key. Both a service SAS and an account SAS are signed with the storage account key. The client that creates a service SAS must either have direct access to the account key or be assigned the Microsoft.Storage/storageAccounts/listkeys/action permission. Дополнительные сведения см. в статье "Создание SAS службы" или "Создание SAS учетной записи".
Примечание.
A user delegation SAS offers superior security to a SAS that is signed with the storage account key. Майкрософт рекомендует по возможности использовать SAS с делегированием пользователей. Дополнительные сведения см. в статье Предоставление ограниченного доступа к данным с помощью подписанных URL-адресов (SAS).
This article shows how to use the storage account key to create an account SAS with the Azure Storage client library for Python.
Сведения о SAS учетной записи
An account SAS is created at the level of the storage account. Создав учетную запись SAS, вы можете:
- Delegate access to service-level operations that aren't currently available with a service-specific SAS, such as Get Blob Service Properties, Set Blob Service Properties and Get Blob Service Stats.
- Delegate access to more than one service in a storage account at a time. Например, можно делегировать доступ к ресурсам как в Azure Blob Storage, так и в Azure Files с помощью учетной записи SAS.
Хранимые политики доступа не поддерживаются для SAS учетной записи.
Создание SAS учетной записи
An account SAS is signed with the account access key. The following code example shows how to call the generate_account_sas method to get the account SAS token string.
def create_account_sas(self, account_name: str, account_key: str):
# Create an account SAS that's valid for one day
start_time = datetime.datetime.now(datetime.timezone.utc)
expiry_time = start_time + datetime.timedelta(days=1)
# Define the SAS token permissions
sas_permissions=AccountSasPermissions(read=True)
# Define the SAS token resource types
# For this example, we grant access to service-level APIs
sas_resource_types=ResourceTypes(service=True)
sas_token = generate_account_sas(
account_name=account_name,
account_key=account_key,
resource_types=sas_resource_types,
permission=sas_permissions,
expiry=expiry_time,
start=start_time
)
return sas_token
Valid parameters for the ResourceTypes constructor are:
-
service: default is
False
; set toTrue
to grant access to service-level APIs. -
container: default is
False
; set toTrue
to grant access to container-level APIs. -
object: default is
False
; set toTrue
to grant access to object-level APIs for blobs, queue messages, and files.
For available permissions, see AccountSasPermissions.
Использование учетной записи SAS из приложения
To use the account SAS to access service-level APIs for the Blob service, create a BlobServiceClient object using the account SAS and the Blob Storage endpoint for your storage account.
# The SAS token string can be appended to the account URL with a ? delimiter
# or passed as the credential argument to the client constructor
account_sas_url = f"{blob_service_client.url}?{sas_token}"
# Create a BlobServiceClient object
blob_service_client_sas = BlobServiceClient(account_url=account_sas_url)
You can also use an account SAS to authorize and work with a ContainerClient object or BlobClient object, if those resource types are granted access as part of the signature values.
Ресурсы
To learn more about creating an account SAS using the Azure Blob Storage client library for Python, see the following resources.