Poznámka:
Přístup k této stránce vyžaduje autorizaci. Můžete se zkusit přihlásit nebo změnit adresáře.
Přístup k této stránce vyžaduje autorizaci. Můžete zkusit změnit adresáře.
Sdílený přístupový podpis (SAS) vám umožňuje udělit omezený přístup ke kontejnerům a blobům ve vašem úložišti. Při vytváření sdíleného přístupového podpisu (SAS) zadáte jeho omezení, včetně určení, ke kterým prostředkům Azure Storage má klient povolený přístup, jaká oprávnění k těmto prostředkům má, a jak dlouho je tento podpis platný.
Každý SAS je podepsaný klíčem. Smlouvu typu SAS můžete podepsat dvěma způsoby:
- S klíčem vytvořeným pomocí přihlašovacích údajů 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. To learn more, see Create a user delegation SAS.
- S klíčem účtu úložiště. Both a service SAS and an account SAS are signed with the storage account key. Klient, který vytvoří SAS služby, musí mít buď přímý přístup k klíči účtu, nebo musí mít přiřazené oprávnění Microsoft.Storage/storageAccounts/listkeys/action . To learn more, see Create a service SAS or Create an account SAS.
Poznámka:
A user delegation SAS offers superior security to a SAS that is signed with the storage account key. Microsoft doporučuje používat SAS s delegováním uživatele, pokud je to možné. Další informace najdete v tématu Udělení omezeného přístupu k datům pomocí sdílených přístupových podpisů (SAS).
This article shows how to use Microsoft Entra credentials to create a user delegation SAS for a container or blob with the Azure CLI.
Informace o delegování uživatele pomocí SAS
Token SAS pro přístup ke kontejneru nebo objektu blob může být zabezpečený pomocí přihlašovacích údajů Microsoft Entra nebo klíče účtu. SAS zabezpečený uživatelskými přihlašovacími údaji Microsoft Entra se nazývá SAS s uživatelskou delegací, protože token OAuth 2.0 použitý k podepsání SAS je vyžádán jménem uživatele.
Microsoft doporučuje používat přihlašovací údaje Microsoft Entra, pokud je to možné jako osvědčený postup zabezpečení, a ne používat klíč účtu, který může být snadněji ohrožen. Když návrh vaší aplikace vyžaduje sdílené přístupové podpisy (shared access signatures), použijte přihlašovací údaje Microsoft Entra k vytvoření delegovaných podpisů SAS od uživatele pro zvýšení zabezpečení. Další informace o SAS delegování uživatele viz téma Vytvoření SAS delegování uživatele.
Upozornění
Any client that possesses a valid SAS can access data in your storage account as permitted by that SAS. Je důležité chránit SAS před škodlivým nebo nezamýšleným použitím. Při distribuci sdíleného přístupového podpisu použijte vlastní uvážení a vytvořte plán pro odvolání ohroženého sdíleného přístupového podpisu.
Další informace o sdílených přístupových podpisech najdete v tématu Udělení omezeného přístupu k prostředkům Azure Storage pomocí sdílených přístupových podpisů (SAS).
Install the latest version of the Azure CLI
To use the Azure CLI to secure a SAS with Microsoft Entra credentials, first make sure that you have installed the latest version of Azure CLI. For more information about installing the Azure CLI, see Install the Azure CLI.
To create a user delegation SAS using the Azure CLI, make sure that you have installed version 2.0.78 or later. To check your installed version, use the az --version command.
Sign in with Microsoft Entra credentials
Sign in to the Azure CLI with your Microsoft Entra credentials. For more information, see Sign in with the Azure CLI.
Assign permissions with Azure RBAC
To create a user delegation SAS from Azure PowerShell, the Microsoft Entra account used to sign into Azure CLI must be assigned a role that includes the Microsoft.Storage/storageAccounts/blobServices/generateUserDelegationKey action. This permission enables that Microsoft Entra account to request the user delegation key. The user delegation key is used to sign the user delegation SAS. The role providing the Microsoft.Storage/storageAccounts/blobServices/generateUserDelegationKey action must be assigned at the level of the storage account, the resource group, or the subscription.
If you do not have sufficient permissions to assign Azure roles to a Microsoft Entra security principal, you may need to ask the account owner or administrator to assign the necessary permissions.
The following example assigns the Storage Blob Data Contributor role, which includes the Microsoft.Storage/storageAccounts/blobServices/generateUserDelegationKey action. The role is scoped at the level of the storage account.
Nezapomeňte nahradit zástupné hodnoty v hranatých závorkách vlastními hodnotami:
az role assignment create \
--role "Storage Blob Data Contributor" \
--assignee <email> \
--scope "/subscriptions/<subscription>/resourceGroups/<resource-group>/providers/Microsoft.Storage/storageAccounts/<storage-account>"
For more information about the built-in roles that include the Microsoft.Storage/storageAccounts/blobServices/generateUserDelegationKey action, see Azure built-in roles.
Use Microsoft Entra credentials to secure a SAS
When you create a user delegation SAS with the Azure CLI, the user delegation key that is used to sign the SAS is created for you implicitly. The start time and expiry time that you specify for the SAS are also used as the start time and expiry time for the user delegation key.
Because the maximum interval over which the user delegation key is valid is 7 days from the start date, you should specify an expiry time for the SAS that is within 7 days of the start time. The SAS is invalid after the user delegation key expires, so a SAS with an expiry time of greater than 7 days will still only be valid for 7 days.
When creating a user delegation SAS, the --auth-mode login and --as-user parameters are required. Specify login for the --auth-mode parameter so that requests made to Azure Storage are authorized with your Microsoft Entra credentials. Specify the --as-user parameter to indicate that the SAS returned should be a user delegation SAS.
Create a user delegation SAS for a container
To create a user delegation SAS for a container with the Azure CLI, call the az storage container generate-sas command.
Supported permissions for a user delegation SAS on a container include Add, Create, Delete, List, Read, and Write. Permissions can be specified singly or combined. For more information about these permissions, see Create a user delegation SAS.
The following example returns a user delegation SAS token for a container. Nezapomeňte nahradit zástupné hodnoty v závorkách vlastními hodnotami:
az storage container generate-sas \
--account-name <storage-account> \
--name <container> \
--permissions acdlrw \
--expiry <date-time> \
--auth-mode login \
--as-user
The user delegation SAS token returned will be similar to:
se=2019-07-27&sp=r&sv=2018-11-09&sr=c&skoid=<skoid>&sktid=<sktid>&skt=2019-07-26T18%3A01%3A22Z&ske=2019-07-27T00%3A00%3A00Z&sks=b&skv=2018-11-09&sig=<signature>
Poznámka:
The SAS token returned by Blob Storage does not include the delimiter character ('?') for the URL query string. Pokud k adrese URL prostředku připojujete token SAS, nezapomeňte také připojit znak oddělovače.
Create a user delegation SAS for a blob
To create a user delegation SAS for a blob with the Azure CLI, call the az storage blob generate-sas command.
Supported permissions for a user delegation SAS on a blob include Add, Create, Delete, Read, and Write. Permissions can be specified singly or combined. For more information about these permissions, see Create a user delegation SAS.
The following syntax returns a user delegation SAS for a blob. The example specifies the --full-uri parameter, which returns the blob URI with the SAS token appended. Nezapomeňte nahradit zástupné hodnoty v závorkách vlastními hodnotami:
az storage blob generate-sas \
--account-name <storage-account> \
--container-name <container> \
--name <blob> \
--permissions acdrw \
--expiry <date-time> \
--auth-mode login \
--as-user \
--full-uri
The user delegation SAS URI returned will be similar to:
https://storagesamples.blob.core.windows.net/sample-container/blob1.txt?se=2019-08-03&sp=rw&sv=2018-11-09&sr=b&skoid=<skoid>&sktid=<sktid>&skt=2019-08-02T2
2%3A32%3A01Z&ske=2019-08-03T00%3A00%3A00Z&sks=b&skv=2018-11-09&sig=<signature>
Poznámka:
The SAS token returned by Azure CLI does not include the delimiter character ('?') for the URL query string. Pokud k adrese URL prostředku připojujete token SAS, nezapomeňte před připojením tokenu SAS k adrese URL prostředku připojit znak oddělovače.
A user delegation SAS does not support defining permissions with a stored access policy.
Revoke a user delegation SAS
To revoke a user delegation SAS from the Azure CLI, call the az storage account revoke-delegation-keys command. This command revokes all of the user delegation keys associated with the specified storage account. Any shared access signatures associated with those keys are invalidated.
Nezapomeňte nahradit zástupné hodnoty v hranatých závorkách vlastními hodnotami:
az storage account revoke-delegation-keys \
--name <storage-account> \
--resource-group <resource-group>
Důležité
Both the user delegation key and Azure role assignments are cached by Azure Storage, so there may be a delay between when you initiate the process of revocation and when an existing user delegation SAS becomes invalid.