You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/storage/common/sas-expiration-policy.md
+29-11Lines changed: 29 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,11 @@ author: jimmart-dev
7
7
8
8
ms.service: storage
9
9
ms.topic: how-to
10
-
ms.date: 10/25/2022
10
+
ms.date: 12/12/2022
11
11
ms.author: jammart
12
12
ms.reviewer: nachakra
13
13
ms.subservice: common
14
+
ms.custom: engagement-fy23
14
15
---
15
16
16
17
# Configure an expiration policy for shared access signatures
@@ -35,23 +36,34 @@ When a SAS expiration policy is in effect for the storage account, the signed st
35
36
36
37
When you configure a SAS expiration policy on a storage account, the policy applies to each type of SAS that is signed with the account key. The types of shared access signatures that are signed with the account key are the service SAS and the account SAS.
37
38
38
-
> [!NOTE]
39
-
> Before you can configure a SAS expiration policy, you may need to rotate each of your account access keys at least once.
39
+
### Do I need to rotate the account access keys first?
40
+
41
+
Before you can configure a SAS expiration policy, you might need to rotate each of your account access keys at least once. If the **keyCreationTime** property of the storage account has a null value for either of the account access keys (key1 and key2), you will need to rotate them. To determine whether the **keyCreationTime** property is null, see [Get the creation time of the account access keys for a storage account](storage-account-get-info.md#get-the-creation-time-of-the-account-access-keys-for-a-storage-account). If you attempt to configure a SAS expiration policy and the keys need to be rotated first, the operation will fail.
42
+
43
+
### How to configure a SAS expiration policy
40
44
41
-
### [Azure portal](#tab/azure-portal)
45
+
You can configure a SAS expiration policy using the Azure portal, PowerShell, or Azure CLI.
46
+
47
+
#### [Azure portal](#tab/azure-portal)
42
48
43
49
To configure a SAS expiration policy in the Azure portal, follow these steps:
44
50
45
51
1. Navigate to your storage account in the Azure portal.
46
52
1. Under **Settings**, select **Configuration**.
47
-
1. Locate the setting for **Allow recommended upper limit for shared access signature (SAS) expiry interval**, and set it to **Enabled**. If the setting appears disabled, then you need to rotate both account access keys before you can set a recommended upper limit for SAS expiry interval.
48
-
1. Specify the recommended interval for any new shared access signatures that are created on resources in this storage account.
53
+
1. Locate the setting for **Allow recommended upper limit for shared access signature (SAS) expiry interval**, and set it to **Enabled**.
54
+
55
+
> [!NOTE]
56
+
> If the setting is grayed out and you see the message shown in the image below, then [you will need to rotate both account access keys](#do-i-need-to-rotate-the-account-access-keys-first) before you can set the **Recommended upper limit for SAS expiry interval** values:
57
+
>
58
+
> :::image type="content" source="media/sas-expiration-policy/configure-sas-expiration-policy-portal-grayed-out.png" alt-text="Screenshot showing the option to configure a SAS expiration policy is grayed out in the Azure portal." lightbox="media/sas-expiration-policy/configure-sas-expiration-policy-portal-grayed-out.png":::
49
59
50
-
:::image type="content" source="media/sas-expiration-policy/configure-sas-expiration-policy-portal.png" alt-text="Screenshot showing how to configure a SAS expiration policy in the Azure portal":::
60
+
1. Specify the time values under **Recommended upper limit for SAS expiry interval** for the recommended interval for any new shared access signatures that are created on resources in this storage account.
51
61
52
-
1. Select the **Save** button to save your changes.
62
+
:::image type="content" source="media/sas-expiration-policy/configure-sas-expiration-policy-portal.png" alt-text="Screenshot showing how to configure a SAS expiration policy in the Azure portal." lightbox="media/sas-expiration-policy/configure-sas-expiration-policy-portal.png":::
53
63
54
-
### [PowerShell](#tab/azure-powershell)
64
+
1. Select **Save** to save your changes.
65
+
66
+
#### [PowerShell](#tab/azure-powershell)
55
67
56
68
To configure a SAS expiration policy, use the [Set-AzStorageAccount](/powershell/module/az.storage/set-azstorageaccount) command, and then set the `-SasExpirationPeriod` parameter to the number of days, hours, minutes, and seconds that a SAS token can be active from the time that a SAS is signed. The string that you provide the `-SasExpirationPeriod` parameter uses the following format: `<days>.<hours>:<minutes>:<seconds>`. For example, if you wanted the SAS to expire 1 day, 12 hours, 5 minutes, and 6 seconds after it is signed, then you would use the string `1.12:05:06`.
> You can also set the SAS expiration policy as you create a storage account by setting the `-SasExpirationPeriod` parameter of the [New-AzStorageAccount](/powershell/module/az.storage/new-azstorageaccount) command.
66
78
67
-
To verify that the policy has been applied, use the `SasPolicy` property of the [PSStorageAccount](/dotnet/api/microsoft.azure.commands.management.storage.models.psstorageaccount) returned to the `$account` variable in the previous command.
79
+
> [!NOTE]
80
+
> If you get an error message indicating that the creation time for a key has not been set, [rotate the account access keys](#do-i-need-to-rotate-the-account-access-keys-first) and try again.
81
+
82
+
To verify that the policy has been applied, check the storage account's SasPolicy property.
68
83
69
84
```powershell
70
85
$account.SasPolicy
@@ -75,7 +90,7 @@ The SAS expiration period appears in the console output.
To configure a SAS expiration policy, use the [az storage account update](/cli/azure/storage/account#az-storage-account-update) command, and then set the `--key-exp-days` parameter to the number of days, hours, minutes, and seconds that a SAS token can be active from the time that a SAS is signed. The string that you provide the `--key-exp-days` parameter uses the following format: `<days>.<hours>:<minutes>:<seconds>`. For example, if you wanted the SAS to expire 1 day, 12 hours, 5 minutes, and 6 seconds after it is signed, then you would use the string `1.12:05:06`.
81
96
@@ -89,6 +104,9 @@ az storage account update \
89
104
> [!TIP]
90
105
> You can also set the SAS expiration policy as you create a storage account by setting the `--key-exp-days` parameter of the [az storage account create](/cli/azure/storage/account#az-storage-account-create) command.
91
106
107
+
> [!NOTE]
108
+
> If you get an error message indicating that the creation time for a key has not been set, [rotate the account access keys](#do-i-need-to-rotate-the-account-access-keys-first) and try again.
109
+
92
110
To verify that the policy has been applied, call the [az storage account show](/cli/azure/storage/account#az-storage-account-show) command, and use the string `{SasPolicy:sasPolicy}` for the `-query` parameter.
## Get the creation time of the account access keys for a storage account
176
+
177
+
If the **keyCreationTime** property of one or both of the account access keys for a storage account is null, then you will need to rotate the keys before you can configure a key expiration policy or a SAS expiration policy. You can check the **keyCreationTime** for a storage account by using the Azure portal, PowerShell, or Azure CLI.
178
+
179
+
# [Azure portal](#tab/portal)
180
+
181
+
To display the creation time of the account access keys for a storage account in the Azure portal, follow these steps:
182
+
183
+
1. Navigate to your storage account in the Azure portal.
184
+
1. On the **Overview** page, in the **Essentials** section, select the **JSON View** link.
185
+
1. On the **Resource JSON** page, select the most recent **API version**.
186
+
1. In the JSON under *properties* you will see the *keyCreationTime* for *key1* and *key2*.
187
+
188
+
:::image type="content" source="media/storage-account-get-info/key-creation-time-portal.png" alt-text="Screenshot of the JSON View of a storage account showing one account access key with null values and another with a date and time stamp." lightbox="media/storage-account-get-info/key-creation-time-portal.png":::
189
+
190
+
# [PowerShell](#tab/powershell)
191
+
192
+
To return the creation time of the account access keys for a storage account with PowerShell, make sure you have installed the [Az.Storage](https://www.powershellgallery.com/packages/Az.Storage) module. Next, call the [Get-AzStorageAccount](/powershell/module/az.storage/get-azstorageaccount) command to get the **keyCreationTime** property, which includes the creation time for both keys. In the sample code below we get the **keyCreationTime** for both keys and test whether each value is null:
193
+
194
+
```azurepowershell
195
+
$rgName = <resource-group>
196
+
$accountName = <storage-account>
197
+
198
+
# Get the keyCreationTime property of the storage account
Write-Host 'keyCreationTime.key1 is null = ' ($keyCreationTime.key1 -eq $null)
204
+
Write-Host 'keyCreationTime.key2 is null = ' ($keyCreationTime.key2 -eq $null)
205
+
206
+
```
207
+
208
+
# [Azure CLI](#tab/azure-cli)
209
+
210
+
To return the creation time of the account access keys for a storage account with Azure CLI, call the [az storage account show](/cli/azure/storage/account#az-storage-account-show) command and query the **keyCreationTime**:
211
+
212
+
```azurecli
213
+
az storage account show \
214
+
--name <storage-account> \
215
+
--resource-group <resource-group> \
216
+
--query keyCreationTime
217
+
```
218
+
219
+
---
220
+
221
+
You can also get the keyCreationTime for a storage account by calling the [Storage Accounts - Get Properties](/rest/api/storagerp/storage-accounts/get-properties) operation in the REST API.
0 commit comments