Skip to content

Commit 1fefd28

Browse files
christothesheaths
andauthored
Readme and sample tweaks (#14801)
* Readme and sample tweaks * Update sdk/keyvault/Azure.Security.KeyVault.Administration/readme.md Co-authored-by: Heath Stewart <[email protected]> * Update sdk/keyvault/Azure.Security.KeyVault.Administration/readme.md Co-authored-by: Heath Stewart <[email protected]> * Update sdk/keyvault/Azure.Security.KeyVault.Administration/readme.md Co-authored-by: Heath Stewart <[email protected]> Co-authored-by: Heath Stewart <[email protected]>
1 parent 8c21d49 commit 1fefd28

File tree

6 files changed

+859
-30
lines changed

6 files changed

+859
-30
lines changed

sdk/keyvault/Azure.Security.KeyVault.Administration/readme.md

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Azure KeyVault Administration client library for .NET
22

3-
Azure Key Vault is a cloud service for securely storing and accessing secrets. A secret is anything that you want to tightly control access to, such as API keys, passwords, or certificates. A vault is a logical group of secrets.
3+
Azure Key Vault is a cloud service for securely storing and accessing secrets. A secret is anything to which you want to tightly control
4+
access, such as API keys, passwords, or certificates. A vault is a logical group of secrets.
45

56
The Azure Key Vault administration library clients support administrative tasks such as full backup / restore and key-level role-based access control (RBAC).
67

7-
[Source code][admin_client_src] | [Package (NuGet)][admin_client_nuget_package] | [API reference documentation][API_reference] | [Product documentation][keyvault_docs] | [Samples][admin_client_samples]
8+
[Source code][admin_client_src] | [Package (NuGet)][admin_client_nuget_package] | [Product documentation][keyvault_docs] | [Samples][admin_client_samples]
89

910
## Getting started
1011

@@ -22,10 +23,12 @@ dotnet install Azure.Security.KeyVault.Administration --version 4.0.0-beta.1
2223
See the final two steps in the next section for details on creating the Key Vault with the Azure CLI.
2324

2425
### Authenticate the client
25-
In order to interact with the Key Vault service, you'll need to create an instance of the [KeyVaultAccessControlClient][rbac_client] class. You need a **vault url**, which you may see as "DNS Name" in the portal,
26-
and **client secret credentials (client id, client secret, tenant id)** to instantiate a client object.
26+
In order to control permissions to the Key Vault service, you'll need to create an instance of the [KeyVaultAccessControlClient][rbac_client] class.
27+
You need a **vault URL**, which you may see as "DNS Name" in the portal, and **client secret credentials (client id, client secret, tenant id)**
28+
to instantiate a client object.
2729

28-
Client secret credential authentication is being used in this getting started section but you can find more ways to authenticate with [Azure identity][azure_identity]. To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below,
30+
Client secret credential authentication is being used in this getting started section but you can find more ways to authenticate with
31+
[Azure identity][azure_identity]. To use the [DefaultAzureCredential][DefaultAzureCredential] provider shown below,
2932
or other credential providers provided with the Azure SDK, you should install the Azure.Identity package:
3033

3134
```PowerShell
@@ -57,14 +60,16 @@ Use the [Azure CLI][azure_cli] snippet below to create/get client secret credent
5760
```
5861
"<your-service-principal-object-id>"
5962
```
60-
* Use the returned credentials above to set **AZURE_CLIENT_ID** (appId), **AZURE_CLIENT_SECRET** (password), and **AZURE_TENANT_ID** (tenant) environment variables. The following example shows a way to do this in Powershell:
63+
* Use the returned credentials above to set **AZURE_CLIENT_ID** (appId), **AZURE_CLIENT_SECRET** (password), and **AZURE_TENANT_ID** (tenant)
64+
environment variables. The following example shows a way to do this in Powershell:
6165
```PowerShell
6266
$Env:AZURE_CLIENT_ID="generated-app-ID"
6367
$Env:AZURE_CLIENT_SECRET="random-password"
6468
$Env:AZURE_TENANT_ID="tenant-ID"
6569
```
6670
67-
* Create the Key Vault and grant the above mentioned application authorization to perform administrative operations on the Azure Key Vault (replace `<your-resource-group-name>` and `<your-key-vault-name>` with your own, unique names and `<your-service-principal-object-id>` with the value from above):
71+
* Create the Key Vault and grant the above mentioned application authorization to perform administrative operations on the Azure Key Vault
72+
(replace `<your-resource-group-name>` and `<your-key-vault-name>` with your own, unique names and `<your-service-principal-object-id>` with the value from above):
6873
```
6974
az keyvault create --hsm-name <your-key-vault-name> --resource-group <your-resource-group-name> --administrators <your-service-principal-object-id> --location <your-azure-location>
7075
```
@@ -75,51 +80,73 @@ Use the [Azure CLI][azure_cli] snippet below to create/get client secret credent
7580
```
7681
7782
#### Create KeyVaultAccessControlClient
78-
Once you've populated the **AZURE_CLIENT_ID**, **AZURE_CLIENT_SECRET** and **AZURE_TENANT_ID** environment variables and replaced **your-vault-url** with the above returned URI, you can create the [KeyVaultAccessControlClient][rbac_client]:
83+
Once you've populated the **AZURE_CLIENT_ID**, **AZURE_CLIENT_SECRET** and **AZURE_TENANT_ID** environment variables and replaced **your-vault-url**
84+
with the above returned URI, you can create the [KeyVaultAccessControlClient][rbac_client]:
7985
80-
```C# Snippet:CreateKeyVaultAccessControlClient
81-
// Create a new access control client using the default credential from Azure.Identity using environment variables previously set,
82-
// including AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, and AZURE_TENANT_ID.
83-
KeyVaultAccessControlClient client = new KeyVaultAccessControlClient(vaultUri: new Uri(keyVaultUrl), credential: new DefaultAzureCredential());
86+
```C# Snippet:HelloCreateKeyVaultAccessControlClient
87+
KeyVaultAccessControlClient client = new KeyVaultAccessControlClient(new Uri(keyVaultUrl), new DefaultAzureCredential());
88+
```
8489

85-
// Retrieve all the role definitions.
86-
List<KeyVaultRoleDefinition> roleDefinitions = client.GetRoleDefinitions(KeyVaultRoleScope.Global).ToList();
90+
#### Create KeyVaultBackupClient
91+
Once you've populated the **AZURE_CLIENT_ID**, **AZURE_CLIENT_SECRET** and **AZURE_TENANT_ID** environment variables and replaced **your-vault-url**
92+
with the above returned URI, you can create the [KeyVaultBackupClient][backup_client]:
8793

88-
// Retrieve all the role assignments.
89-
List<KeyVaultRoleAssignment> roleAssignments = client.GetRoleAssignments(KeyVaultRoleScope.Global).ToList();
94+
```C# Snippet:HelloCreateKeyVaultBackupClient
95+
KeyVaultBackupClient client = new KeyVaultBackupClient(new Uri(keyVaultUrl), new DefaultAzureCredential());
9096
```
9197

9298
## Key concepts
9399

94100
### KeyVaultRoleDefinition
95-
A `KeyVaultRoleDefinition` is a collection of permissions. A role definition defines the operations that can be performed, such as read, write, and delete. It can also define the operations that are excluded from allowed operations.
101+
A `KeyVaultRoleDefinition` is a collection of permissions. A role definition defines the operations that can be performed, such as read, write,
102+
and delete. It can also define the operations that are excluded from allowed operations.
96103

97-
RoleDefinitions can be listed and specified as part of a `KeyVaultRoleAssignment`.
104+
KeyVaultRoleDefinitions can be listed and specified as part of a `KeyVaultRoleAssignment`.
98105

99-
### RoleAssignment.
106+
### KeyVaultRoleAssignment.
100107
A `KeyVaultRoleAssignment` is the association of a KeyVaultRoleDefinition to a service principal. They can be created, listed, fetched individually, and deleted.
101108

102109
### KeyVaultAccessControlClient
103110
A `KeyVaultAccessControlClient` provides both synchronous and asynchronous operations allowing for management of `KeyVaultRoleDefinition` and `KeyVaultRoleAssignment` objects.
104111

112+
### KeyVaultBackupClient
113+
114+
A `KeyVaultBackupClient` provides both synchronous and asynchronous operations for performing full key backups, full key restores, and selective key restores.
115+
116+
### BackupOperation
117+
118+
A `BackupOperation` represents a long running operation for a full key backup.
119+
120+
### RestoreOperation
121+
122+
A `RestoreOperation` represents a long running operation for both a full key and selective key restore.
123+
105124
## Examples
106125
The Azure.Security.KeyVault.Administration package supports synchronous and asynchronous APIs.
107126

108-
The following section provides several code snippets using the `client` [created above](#create-keyvaultaccesscontrolclient), covering some of the most common Azure Key Vault access control related tasks:
127+
The following section provides several code snippets using the `client` created above for either [access control](#create-keyvaultaccesscontrolclient) or [backup](#create-KeyVaultBackupClient) clients, covering some of the most common Azure Key Vault access control related tasks:
109128

110129
### Sync examples
111-
- [Listing All Role Definitions](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md#listing-all-role-definitions-sync)
112-
- [Listing All Role Assignments](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md#listing-all-role-assignments)
113-
- [Creating a Role Assignment](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md#creating-a-role-assignment)
114-
- [Getting a Role Assignment](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md#getting-a-role-assignment)
115-
- [Deleting a Role Assignment](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md#deleting-a-role-assignment)
130+
- Access control
131+
- [Listing All Role Definitions](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md#listing-all-role-definitions-sync)
132+
- [Listing All Role Assignments](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md#listing-all-role-assignments)
133+
- [Creating a Role Assignment](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md#creating-a-role-assignment)
134+
- [Getting a Role Assignment](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md#getting-a-role-assignment)
135+
- [Deleting a Role Assignment](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md#deleting-a-role-assignment)
136+
- Backup and restore
137+
- [Performing a full key backup](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_BackupHelloWorldSync.md#performing-a-full-key-backup)
138+
- [Performing a full key restore](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_BackupHelloWorldSync.md#performing-a-full-key-restore)
116139

117140
### Async examples
118-
- [Listing All Role Definitions](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md#listing-all-role-definitions-sync)
119-
- [Listing All Role Assignments](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md#listing-all-role-assignments)
120-
- [Creating a Role Assignment](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md#creating-a-role-assignment)
121-
- [Getting a Role Assignment](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md#getting-a-role-assignment)
122-
- [Deleting a Role Assignment](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md#deleting-a-role-assignment)
141+
- Access control
142+
- [Listing All Role Definitions](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md#listing-all-role-definitions-sync)
143+
- [Listing All Role Assignments](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md#listing-all-role-assignments)
144+
- [Creating a Role Assignment](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md#creating-a-role-assignment)
145+
- [Getting a Role Assignment](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md#getting-a-role-assignment)
146+
- [Deleting a Role Assignment](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md#deleting-a-role-assignment)
147+
- Backup and restore
148+
- [Performing a full key backup](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_BackupHelloWorldAsync.md#performing-a-full-key-backup)
149+
- [Performing a full key restore](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_BackupHelloWorldAsync.md#performing-a-full-key-restore)
123150

124151
## Troubleshooting
125152

@@ -185,6 +212,7 @@ additional questions or comments.
185212
[azure_sub]: https://azure.microsoft.com/free/
186213
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
187214
[rbac_client]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/src/KeyVaultAccessControlClient.cs
215+
[backup_client]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.Administration/src/KeyVaultBackupClient.cs
188216
[keyvault_docs]: https://docs.microsoft.com/azure/key-vault/
189217
[keyvault_rest]: https://docs.microsoft.com/rest/api/keyvault/
190218
[admin_client_nuget_package]: https://www.nuget.org/packages?q=Azure.Security.KeyVault.Administration
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Performing a full key restore
2+
3+
Using the `KeyVaultBackupClient`, you can restore a single key from backup by key name. The data source for a
4+
selective key restore is a storage blob accessed using Shared Access Signature authentication.
5+
For more details on creating a SAS token using the `BlobServiceClient`, see the
6+
[Azure Storage Blobs client README](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/storage/Azure.Storage.Blobs/README.md)
7+
and the [authentication samples](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/storage/Azure.Storage.Blobs/samples/Sample02_Auth.cs).
8+
Alternatively, it is possible to [generate a SAS token in Storage Explorer](https://docs.microsoft.com/en-us/azure/vs-azure-tools-storage-manage-with-storage-explorer?tabs=windows#generate-a-shared-access-signature-in-storage-explorer)
9+
10+
```C# Snippet:SelectiveRestoreAsync
11+
// Get the folder name from the backupBlobUri returned from a previous BackupOperation.
12+
string[] uriSegments = backupBlobUri.Segments;
13+
string folderName = uriSegments[uriSegments.Length - 1];
14+
string keyName = <key name to restore>;
15+
16+
// Start the restore for a specific key that was previously backed up.
17+
RestoreOperation restoreOperation = await Client.StartSelectiveRestoreAsync(keyName, builder.Uri, sasToken, folderName);
18+
19+
// Wait for completion of the RestoreOperation.
20+
Response restoreResult = await restoreOperation.WaitForCompletionAsync();
21+
```

sdk/keyvault/Azure.Security.KeyVault.Administration/tests/BackupRestoreTestBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class BackupRestoreTestBase : RecordedTestBase<KeyVaultTestEnvironment>
1515
public KeyVaultBackupClient Client { get; set; }
1616
internal string SasToken { get; set; }
1717
internal string BlobContainerName = "backup";
18+
internal string PreviouslyBackedUpKeyName = "rsa-1";
1819

1920
public BackupRestoreTestBase(bool isAsync, RecordedTestMode mode) : base(isAsync, mode)
2021
{

0 commit comments

Comments
 (0)