Skip to content

Commit 59a8196

Browse files
committed
Added final example
1 parent 3899eb0 commit 59a8196

File tree

3 files changed

+67
-17
lines changed

3 files changed

+67
-17
lines changed

articles/key-vault/key-vault-overview-storage-keys-powershell.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ The commands in this section complete the following actions:
188188
- Set an account shared access signature definition.
189189
- Create an account shared access signature token for Blob, File, Table, and Queue services. The token is created for resource types Service, Container, and Object. The token is created with all permissions, over https, and with the specified start and end dates.
190190
- Set a Key Vault managed storage shared access signature definition in the vault. The definition has the template URI of the shared access signature token that was created. The definition has the shared access signature type `account` and is valid for N days.
191-
191+
- Verify that the shared access signature was saved in your key vault as a secret.
192+
-
192193
### Set variables
193194

194195
First, set the variables to be used by the PowerShell cmdlets in the following steps. Be sure to update the <YourStorageAccountName> and <YourKeyVaultName> placeholders.
@@ -222,10 +223,40 @@ The value of $sasToken will look similar to this.
222223

223224
Use the the Azure PowerShell [Set-AzKeyVaultManagedStorageSasDefinition](/powershell/module/az.keyvault/set-azkeyvaultmanagedstoragesasdefinition?view=azps-2.6.0) cmdlet to create a shared access signature definition. You can provide the name of your choice to the `-Name` parameter.
224225

225-
```azurecli-interactive
226-
Set-AzKeyVaultManagedStorageSasDefinition -AccountName $storageAccountName -VaultName $keyVaultName -Name accountsas -TemplateUri $sasToken -SasType 'account' -ValidityPeriod ([System.Timespan]::FromDays(30))
226+
```azurepowershell-interactive
227+
Set-AzKeyVaultManagedStorageSasDefinition -AccountName $storageAccountName -VaultName $keyVaultName -Name <YourSASDefinitionName> -TemplateUri $sasToken -SasType 'account' -ValidityPeriod ([System.Timespan]::FromDays(30))
228+
```
229+
230+
### Verify the shared access signature definition
231+
232+
You can verify that the shared access signature definition has been stored in your key vault using the Azure PowerShell [Get-AzKeyVaultSecret](/powershell/module/az.keyvault/get-azkeyvaultsecret?view=azps-2.6.0) cmdlet.
233+
234+
First, find the shared access signature definition in your key vault.
235+
236+
```azurepowershell-interactive
237+
Get-AzKeyVaultSecret -vault-name <YourKeyVaultName>
238+
```
239+
240+
The secret corresponding to your SAS definition will have these properties:
241+
242+
```console
243+
Vault Name : <YourKeyVaultName>
244+
Name : <SecretName>
245+
...
246+
Content Type : application/vnd.ms-sastoken-storage
247+
Tags :
227248
```
228249

250+
You can now use the [Get-AzKeyVaultSecret](/cli/azure/keyvault/secret?view=azure-cli-latest#az-keyvault-secret-show) cmdlet and the secret `Name` property to view the content of that secret.
251+
252+
```azurepowershell-interactive
253+
$secret = Get-AzKeyVaultSecret -VaultName <YourKeyVaultName> -Name <SecretName>
254+
255+
Write-Host $secret.SecretValueText
256+
```
257+
258+
The output of this command will show your SAS definition string.
259+
229260

230261
## Next steps
231262

articles/key-vault/key-vault-ovw-storage-keys.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ The commands in this section complete the following actions:
9494
- Set an account shared access signature definition `<YourSASDefinitionName>`. The definition is set on a Key Vault managed storage account `<YourStorageAccountName>` in your key vault `<YourKeyVaultName>`.
9595
- Create an account shared access signature token for Blob, File, Table, and Queue services. The token is created for resource types Service, Container, and Object. The token is created with all permissions, over https, and with the specified start and end dates.
9696
- Set a Key Vault managed storage shared access signature definition in the vault. The definition has the template URI of the shared access signature token that was created. The definition has the shared access signature type `account` and is valid for N days.
97+
- Verify that the shared access signature was saved in your key vault as a secret.
9798

9899
### Create a shared access signature token
99100

@@ -119,6 +120,32 @@ Use the the Azure CLI [az keyvault storage sas-definition create](/cli/azure/key
119120
az keyvault storage sas-definition create --vault-name <YourKeyVaultName> --account-name <YourStorageAccountName> -n <YourSASDefinitionName> --validity-period P2D --sas-type account --template-uri <OutputOfSasTokenCreationStep>
120121
```
121122

123+
### Verify the shared access signature definition
124+
125+
You can verify that the shared access signature definition has been stored in your key vault using the Azure CLI [az keyvault secret list](/cli/azure/keyvault/secret?view=azure-cli-latest#az-keyvault-secret-list) and [az keyvault secret show](/cli/azure/keyvault/secret?view=azure-cli-latest#az-keyvault-secret-show) commands.
126+
127+
First, find the shared access signature definition in your key vault using the [az keyvault secret list](/cli/azure/keyvault/secret?view=azure-cli-latest#az-keyvault-secret-list) command.
128+
129+
```azurecli-interactive
130+
az keyvault secret list --vault-name <YourKeyVaultName>
131+
```
132+
133+
The secret corresponding to your SAS definition will have these properties:
134+
135+
```console
136+
"contentType": "application/vnd.ms-sastoken-storage",
137+
"id": "https://<YourKeyVaultName>.vault.azure.net/secrets/<YourStorageAccountName>-<YourSASDefinitionName>",
138+
```
139+
140+
You can now use the [az keyvault secret show](/cli/azure/keyvault/secret?view=azure-cli-latest#az-keyvault-secret-show) command and the `id` property to view the content of that secret.
141+
142+
```azurecli-interactive
143+
az keyvault secret show --vault-name <YourKeyVaultName> --id <SasDefinitionID>
144+
```
145+
146+
The output of this command will show your SAS definition string as`value`.
147+
148+
122149
## Next steps
123150

124151
- Learn more about [keys, secrets, and certificates](https://docs.microsoft.com/rest/api/keyvault/).

articles/key-vault/storage-keys-sas-tokens-code.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,16 @@ ms.date: 09/10/2019
1212
---
1313
# Fetch shared access signature tokens in code
1414

15-
Execute operations on your storage account by fetching [shared access signature tokens](../storage/common/storage-dotnet-shared-access-signature-part-1.md) from Key Vault.
15+
You can manage your storage account with the [shared access signature tokens](../storage/common/storage-dotnet-shared-access-signature-part-1.md) in your key vault. This article provides examples of C# code that fetches a SAS token and performs operations with it. For information on how to create and store SAS tokens, see [Manage storage account keys with Key Vault and the Azure CLI](key-vault-ovw-storage-keys) or [Manage storage account keys with Key Vault and Azure PowerShell](key-vault-overview-storage-keys-powershell.md).
1616

17-
There are three ways to authenticate to Key Vault:
18-
19-
- Use a managed service identity. This approach is highly recommended.
20-
- Use a service principal and certificate.
21-
- Use a service principal and password. This approach isn't recommended.
22-
23-
For more information, see [Azure Key Vault: Basic concepts](basic-concepts.md).
24-
25-
The following example demonstrates how to fetch shared access signature tokens. You fetch the tokens after you create a shared access signature definition.
17+
In this example, the code fetches a SAS token from your key vault, uses it to create a new storage account, and creates a new Blob service client.
2618

2719
```cs
2820
// After you get a security token, create KeyVaultClient with vault credentials.
2921
var kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(securityToken));
3022

3123
// Get a shared access signature token for your storage from Key Vault.
32-
// The format for SecretUri is https://<VaultName>.vault.azure.net/secrets/<ExamplePassword>
24+
// The format for SecretUri is https://<YourKeyVaultName>.vault.azure.net/secrets/<ExamplePassword>
3325
var sasToken = await kv.GetSecretAsync("SecretUri");
3426

3527
// Create new storage credentials by using the shared access signature token.
@@ -41,7 +33,7 @@ var accountWithSas = new CloudStorageAccount(accountSasCredential, new Uri ("htt
4133
var blobClientWithSas = accountWithSas.CreateCloudBlobClient();
4234
```
4335

44-
If your shared access signature token is about to expire, fetch the shared access signature token again from Key Vault and update the code.
36+
If your shared access signature token is about to expire, you can fetch the shared access signature token from your key vault and update the code.
4537

4638
```cs
4739
// If your shared access signature token is about to expire,
@@ -52,7 +44,7 @@ accountSasCredential.UpdateSASToken(sasToken);
5244

5345

5446
## Next steps
55-
56-
- [Managed storage account key samples](https://github.com/Azure-Samples?utf8=%E2%9C%93&q=key+vault+storage&type=&language=)
47+
- Learn how to [Manage storage account keys with Key Vault and the Azure CLI](key-vault-ovw-storage-keys) or [Azure PowerShell](key-vault-overview-storage-keys-powershell.md).
48+
- See [Managed storage account key samples](https://github.com/Azure-Samples?utf8=%E2%9C%93&q=key+vault+storage&type=&language=)
5749
- [About keys, secrets, and certificates](about-keys-secrets-and-certificates.md)
5850
- [Key Vault PowerShell reference](/powershell/module/az.keyvault/?view=azps-1.2.0#key_vault)

0 commit comments

Comments
 (0)