Skip to content

Commit 5539b2d

Browse files
Merge pull request #220092 from jimmart-dev/jammart-storage-sas-expire-policy-key-creation-time
storage sas key expire policy keyCreationTime references
2 parents ca92714 + 57d5e42 commit 5539b2d

File tree

4 files changed

+79
-12
lines changed

4 files changed

+79
-12
lines changed
9.61 KB
Loading
49.5 KB
Loading

articles/storage/common/sas-expiration-policy.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ author: jimmart-dev
77

88
ms.service: storage
99
ms.topic: how-to
10-
ms.date: 10/25/2022
10+
ms.date: 12/12/2022
1111
ms.author: jammart
1212
ms.reviewer: nachakra
1313
ms.subservice: common
14+
ms.custom: engagement-fy23
1415
---
1516

1617
# 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
3536

3637
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.
3738

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
4044

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)
4248

4349
To configure a SAS expiration policy in the Azure portal, follow these steps:
4450

4551
1. Navigate to your storage account in the Azure portal.
4652
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":::
4959
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.
5161

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":::
5363

54-
### [PowerShell](#tab/azure-powershell)
64+
1. Select **Save** to save your changes.
65+
66+
#### [PowerShell](#tab/azure-powershell)
5567

5668
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`.
5769

@@ -64,7 +76,10 @@ $account = Set-AzStorageAccount -ResourceGroupName <resource-group> `
6476
> [!TIP]
6577
> 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.
6678
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.
6883

6984
```powershell
7085
$account.SasPolicy
@@ -75,7 +90,7 @@ The SAS expiration period appears in the console output.
7590
> [!div class="mx-imgBorder"]
7691
> ![SAS expiration period](./media/storage-sas-expiration-policy/sas-policy-console-output.png)
7792
78-
### [Azure CLI](#tab/azure-cli)
93+
#### [Azure CLI](#tab/azure-cli)
7994

8095
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`.
8196

@@ -89,6 +104,9 @@ az storage account update \
89104
> [!TIP]
90105
> 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.
91106
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+
92110
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.
93111

94112
```azurecli-interactive

articles/storage/common/storage-account-get-info.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ services: storage
66
author: jimmart-dev
77

88
ms.author: jammart
9-
ms.date: 11/17/2022
9+
ms.date: 12/12/2022
1010
ms.service: storage
1111
ms.subservice: common
1212
ms.topic: how-to
13+
ms.custom: engagement-fy23
1314
---
1415

1516
# Get storage account configuration information
@@ -171,6 +172,54 @@ az storage account show-connection-string --resource-group <resource-group> --na
171172

172173
---
173174

175+
## 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
199+
$keyCreationTime = (Get-AzStorageAccount -ResourceGroupName $rgName -Name $accountName).keyCreationTime
200+
# Display the value for both keys
201+
$keyCreationTime
202+
# Check both properties for null values
203+
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.
222+
174223
## Next steps
175224

176225
- [Storage account overview](storage-account-overview.md)

0 commit comments

Comments
 (0)