Skip to content

Commit 1fae592

Browse files
authored
Fix doc issues for Key Vault Administration SDK (#33327)
* Add samples for role definition CRUD Fixes #25791 * Fix Key Vault Admin docs Fixes #25825 * Update Key Vault Admin README Fixes #25790 * Update Key Vault Admin sample README Fixes #25826 * Update Key Vault backup sample Fixes #25828 * Update RBAC scope assignments sample Fixes #25829 * Update backup/restore sample Fixes #25830
1 parent 8f9ec48 commit 1fae592

18 files changed

+626
-68
lines changed

sdk/core/Azure.Core/src/ClientOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public HttpPipelineTransport Transport
100100
public HttpPipelinePolicy? RetryPolicy { get; set; }
101101

102102
/// <summary>
103-
/// Adds an <see cref="HttpPipeline"/> policy into the client pipeline. The position of policy in the pipeline is controlled by <paramref name="position"/> parameter.
103+
/// Adds an <see cref="HttpPipeline"/> policy into the client pipeline. The position of policy in the pipeline is controlled by the <paramref name="position"/> parameter.
104104
/// If you want the policy to execute once per client request use <see cref="HttpPipelinePosition.PerCall"/> otherwise use <see cref="HttpPipelinePosition.PerRetry"/>
105105
/// to run the policy for every retry. Note that the same instance of <paramref name="policy"/> would be added to all pipelines of client constructed using this <see cref="ClientOptions"/> object.
106106
/// </summary>

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ Only the designated administrators that were assigned during the create command
5858

5959
To activate your HSM you need:
6060

61-
* Minimum 3 RSA key-pairs (maximum 10)
62-
* Specify minimum number of keys required to decrypt the security domain (quorum)
61+
* A minimum of 3 RSA key-pairs (maximum 10)
62+
* Specify the minimum number of keys required to decrypt the security domain (quorum)
6363

6464
To activate the HSM you send at least 3 (maximum 10) RSA public keys to the HSM. The HSM encrypts the security domain with these keys and sends it back.
6565
Once this security domain is successfully downloaded, your HSM is ready to use.
6666
You also need to specify quorum, which is the minimum number of private keys required to decrypt the security domain.
6767

68-
The example below shows how to use openssl to generate 3 self signed certificate.
68+
The example below shows how to use openssl to generate 3 self signed certificates.
6969

7070
```PowerShell
7171
openssl req -newkey rsa:2048 -nodes -keyout cert_0.key -x509 -days 365 -out cert_0.cer
@@ -74,7 +74,7 @@ openssl req -newkey rsa:2048 -nodes -keyout cert_2.key -x509 -days 365 -out cert
7474
```
7575

7676
Use the `az keyvault security-domain download` command to download the security domain and activate your managed HSM.
77-
The example below, uses 3 RSA key pairs (only public keys are needed for this command) and sets the quorum to 2.
77+
The example below uses 3 RSA key pairs (only public keys are needed for this command) and sets the quorum to 2.
7878

7979
```PowerShell
8080
az keyvault security-domain download --hsm-name <your-managed-hsm-name> --sd-wrapping-keys ./certs/cert_0.cer ./certs/cert_1.cer ./certs/cert_2.cer --sd-quorum 2 --security-domain-file ContosoMHSM-SD.json
@@ -95,7 +95,7 @@ Please read [best practices][best_practices] for properly securing your managed
9595

9696
#### Create KeyVaultAccessControlClient
9797

98-
Instantiate a `DefaultAzureCredential` to pass to the [KeyVaultAccessControlClient][rbac_client].
98+
Instantiate a `DefaultAzureCredential` to pass to the `KeyVaultAccessControlClient`.
9999
The same instance of a token credential can be used with multiple clients if they will be authenticating with the same identity.
100100

101101
```C# Snippet:HelloCreateKeyVaultAccessControlClient
@@ -104,7 +104,7 @@ KeyVaultAccessControlClient client = new KeyVaultAccessControlClient(new Uri(man
104104

105105
#### Create KeyVaultBackupClient
106106

107-
Instantiate a `DefaultAzureCredential` to pass to the [KeyVaultBackupClient][backup_client].
107+
Instantiate a `DefaultAzureCredential` to pass to the `KeyVaultBackupClient`.
108108
The same instance of a token credential can be used with multiple clients if they will be authenticating with the same identity.
109109

110110
```C# Snippet:HelloCreateKeyVaultBackupClient
@@ -113,7 +113,7 @@ KeyVaultBackupClient client = new KeyVaultBackupClient(new Uri(managedHsmUrl), n
113113

114114
#### Create KeyVaultSettingClient
115115

116-
Instantiate a `DefaultAzureCredential` to pass to the [KeyVaultSettingsClient][settings_client].
116+
Instantiate a `DefaultAzureCredential` to pass to the `KeyVaultSettingsClient`.
117117
The same instance of a token credential can be used with multiple clients if they will be authenticating with the same identity.
118118

119119
```C# Snippet:KeyVaultSettingsClient_Create
@@ -201,7 +201,7 @@ for details on how to diagnose various failure scenarios.
201201

202202
### General
203203

204-
When you interact with the Azure Key Vault administration library using the .NET SDK, errors returned by the service correspond to the same HTTP status codes returned for [REST API][keyvault_rest] requests.
204+
When you interact with the Azure Key Vault Administration library using the .NET SDK, errors returned by the service correspond to the same HTTP status codes returned for [REST API][keyvault_rest] requests.
205205

206206
For example, if you try to retrieve a role assignment that doesn't exist in your Azure Key Vault, a `404` error is returned, indicating "Not Found".
207207

@@ -233,7 +233,7 @@ Content-Type: application/json
233233
### Setting up console logging
234234

235235
The simplest way to see the logs is to enable the console logging.
236-
To create an Azure SDK log listener that outputs messages to console use AzureEventSourceListener.CreateConsoleLogger method.
236+
To create an Azure SDK log listener that outputs messages to console, use the `AzureEventSourceListener.CreateConsoleLogger` method.
237237

238238
```c#
239239
// Setup a listener to monitor logged events.
@@ -268,9 +268,6 @@ additional questions or comments.
268268
[best_practices]: https://learn.microsoft.com/azure/key-vault/managed-hsm/best-practices
269269
[built_in_roles]: https://learn.microsoft.com/azure/key-vault/managed-hsm/built-in-roles
270270
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
271-
[rbac_client]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/src/KeyVaultAccessControlClient.cs
272-
[backup_client]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/src/KeyVaultBackupClient.cs
273-
[settings_client]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/src/KeyVaultSettingsClient.cs
274271
[managedhsm_docs]: https://learn.microsoft.com/azure/key-vault/managed-hsm/
275272
[keyvault_rest]: https://learn.microsoft.com/rest/api/keyvault/
276273
[admin_client_nuget_package]: https://www.nuget.org/packages?q=Azure.Security.KeyVault.Administration

sdk/keyvault/Azure.Security.KeyVault.Administration/samples/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ description: Samples for the Azure.Security.KeyVault.Administration client libra
1111

1212
# Azure.Security.KeyVault.Administration Samples
1313

14-
- Creating, getting, and deleting role assignments [synchronously](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md) or [asynchronously](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md)
14+
- Creating, getting, and deleting role assignments and definitions [synchronously](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md) or [asynchronously](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md)
1515
- [Assigning roles for specific scopes](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample2_RbacScopeAssignment.md)
16-
- Performing a full key backup and restore [synchronously](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_BackupHelloWorldSync.md) and [asynchronously](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_BackupHelloWorldAsync.md)
16+
- Performing a full key key backup and restore [synchronously](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_BackupHelloWorldSync.md) and [asynchronously](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_BackupHelloWorldAsync.md)
1717
- [Performing selective key restore](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample2_SelectiveRestore.md)
1818
- [Checking the status of a previously started backup or restore](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample3_BackRestoreResume.md)

sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_BackupHelloWorldAsync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Performing a full key backup and restore (Async)
22

3-
This sample demonstrates how to a perform full key backup and restore in Azure Managed HSM.
3+
This sample demonstrates how to perform a full key backup and restore in Azure Managed HSM.
44
To get started, you'll need a URI to an Azure Managed HSM. See the [README](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/keyvault/Azure.Security.KeyVault.Administration/README.md) for links and instructions.
55

66
## Creating a KeyVaultBackupClient

sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldAsync.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,46 @@ To remove a role assignment from a service principal, the role assignment must b
7474
await client.DeleteRoleAssignmentAsync(KeyVaultRoleScope.Global, createdAssignment.Name);
7575
```
7676

77+
## Creating a Role Definition
78+
79+
You can also create custom role definitions with custom permissions:
80+
81+
```C# Snippet:CreateRoleDefinitionAsync
82+
CreateOrUpdateRoleDefinitionOptions options = new CreateOrUpdateRoleDefinitionOptions(KeyVaultRoleScope.Global)
83+
{
84+
RoleName = "Managed HSM Data Decryptor",
85+
Description = "Can only decrypt data using the private key stored in Managed HSM",
86+
Permissions =
87+
{
88+
new KeyVaultPermission()
89+
{
90+
DataActions =
91+
{
92+
KeyVaultDataAction.DecryptHsmKey
93+
}
94+
}
95+
}
96+
};
97+
KeyVaultRoleDefinition createdDefinition = await client.CreateOrUpdateRoleDefinitionAsync(options);
98+
```
99+
100+
## Getting a Role Definition
101+
102+
To get a role definition, you'll need to know the globally unique ID (GUID) instead of the name like with role assignments:
103+
104+
```C# Snippet:GetRoleDefinitionAsync
105+
Guid roleDefinitionId = new Guid(createdDefinition.Name);
106+
KeyVaultRoleDefinition fetchedDefinition = await client.GetRoleDefinitionAsync(KeyVaultRoleScope.Global, roleDefinitionId);
107+
```
108+
109+
## Deleting a Role Definition
110+
111+
To delete a role definition, you'll need to know the globally unique ID (GUID) instead of the name like with role assignments:
112+
113+
```C# Snippet:DeleteRoleDefinitionAsync
114+
await client.DeleteRoleDefinitionAsync(KeyVaultRoleScope.Global, roleDefinitionId);
115+
```
116+
77117
<!-- LINKS -->
78118
[azure_cli]: https://learn.microsoft.com/cli/azure
79119
[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md#defaultazurecredential

sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample1_RbacHelloWorldSync.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,46 @@ To remove a role assignment from a service principal, the role assignment must b
6666
client.DeleteRoleAssignment(KeyVaultRoleScope.Global, createdAssignment.Name);
6767
```
6868

69+
## Creating a Role Definition
70+
71+
You can also create custom role definitions with custom permissions:
72+
73+
```C# Snippet:CreateRoleDefinition
74+
CreateOrUpdateRoleDefinitionOptions options = new CreateOrUpdateRoleDefinitionOptions(KeyVaultRoleScope.Global)
75+
{
76+
RoleName = "Managed HSM Data Decryptor",
77+
Description = "Can only decrypt data using the private key stored in Managed HSM",
78+
Permissions =
79+
{
80+
new KeyVaultPermission()
81+
{
82+
DataActions =
83+
{
84+
KeyVaultDataAction.DecryptHsmKey
85+
}
86+
}
87+
}
88+
};
89+
KeyVaultRoleDefinition createdDefinition = client.CreateOrUpdateRoleDefinition(options);
90+
```
91+
92+
## Getting a Role Definition
93+
94+
To get a role definition, you'll need to know the globally unique ID (GUID) instead of the name like with role assignments:
95+
96+
```C# Snippet:GetRoleDefinition
97+
Guid roleDefinitionId = new Guid(createdDefinition.Name);
98+
KeyVaultRoleDefinition fetchedDefinition = client.GetRoleDefinition(KeyVaultRoleScope.Global, roleDefinitionId);
99+
```
100+
101+
## Deleting a Role Definition
102+
103+
To delete a role definition, you'll need to know the globally unique ID (GUID) instead of the name like with role assignments:
104+
105+
```C# Snippet:DeleteRoleDefinition
106+
client.DeleteRoleDefinition(KeyVaultRoleScope.Global, roleDefinitionId);
107+
```
108+
69109
<!-- LINKS -->
70110
[azure_cli]: https://learn.microsoft.com/cli/azure
71111
[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md#defaultazurecredential

sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample2_RbacScopeAssignment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You can also get the object Id for your currently signed in account by running t
1414
az ad signed-in-user show --query objectId
1515
```
1616

17-
A role definition Id can be obtained from the `Id` property of one of the role definitions returned from `GetRoleAssignments`.
17+
A role definition Id can be obtained from the `Id` property of one of the role definitions returned from `GetRoleDefinitions`.
1818

1919
```C# Snippet:CreateRoleAssignmentKeysScope
2020
string definitionIdToAssign = "<roleDefinitionId>";

sdk/keyvault/Azure.Security.KeyVault.Administration/samples/Sample3_BackRestoreResume.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ To get started, you'll need a URI to an Azure Managed HSM. See the [README](http
55

66
## Checking status of a full key backup operation
77

8-
Using the `KeyVaultBackupClient` and a `BackupOperation`, you can check the status and retrieve the result of a previously started `BackupOperation`.
8+
Using the `KeyVaultBackupClient` and a `KeyVaultBackupOperation`, you can check the status and retrieve the result of a previously started `KeyVaultBackupOperation`.
99
For example the `Id` from a started operation on one client can be saved to persistent storage instead of waiting for completion immediately.
10-
At some later time, another client can retrieve the persisted operation Id and construct a `BackupOperation` using a `KeyVaultBackupClient` and the Id
10+
At some later time, another client can retrieve the persisted operation Id and construct a `KeyVaultBackupOperation` using a `KeyVaultBackupClient` and the Id
1111
and check for status or wait for completion.
1212

1313
```C# Snippet:ResumeBackupAsync
@@ -26,9 +26,9 @@ Uri folderUri = backupResult.Value.FolderUri;
2626

2727
## Checking status of a full key restore operation
2828

29-
Using the `KeyVaultBackupClient` and a `RestoreOperation`, you can check the status and retrieve the result of a previously started `RestoreOperation`.
29+
Using the `KeyVaultBackupClient` and a `KeyVaultRestoreOperation`, you can check the status and retrieve the result of a previously started `KeyVaultRestoreOperation`.
3030
For example the `Id` from a started operation on one client can be saved to persistent storage instead of waiting for completion immediately.
31-
At some later time, another client can retrieve the persisted operation Id and construct a `RestoreOperation` using a `KeyVaultBackupClient` and the Id
31+
At some later time, another client can retrieve the persisted operation Id and construct a `KeyVaultRestoreOperation` using a `KeyVaultBackupClient` and the Id
3232
and check for status or wait for completion.
3333

3434
```C# Snippet:ResumeRestoreAsync

sdk/keyvault/Azure.Security.KeyVault.Administration/src/CreateOrUpdateRoleDefinitionOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public CreateOrUpdateRoleDefinitionOptions(KeyVaultRoleScope roleScope)
2323
}
2424

2525
/// <summary>
26-
/// Initializes a new instance of the <see cref="CreateOrUpdateRoleDefinitionOptions"/> class using a generated role definition name.
26+
/// Initializes a new instance of the <see cref="CreateOrUpdateRoleDefinitionOptions"/> class using the specified role definition name.
2727
/// </summary>
2828
/// <param name="roleScope">The <see cref="KeyVaultRoleScope"/> to which the definition applies.</param>
2929
/// <param name="roleDefinitionName">The unique role definition name. If the named role definition is already defined it will be updated.</param>

0 commit comments

Comments
 (0)