Skip to content

Commit c52fa66

Browse files
mccoypchlowell
andauthored
[Key Vault] Address administration feedback (Azure#19099)
Co-authored-by: Charles Lowell <chlowe@microsoft.com>
1 parent e9bcb44 commit c52fa66

19 files changed

+605
-1450
lines changed

sdk/keyvault/azure-keyvault-administration/CHANGELOG.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,35 @@
33
## 4.0.0b4 (Unreleased)
44
### Changed
55
- Key Vault API version 7.2 is now the default
6+
- `KeyVaultAccessControlClient.delete_role_assignment` and
7+
`.delete_role_definition` no longer raise an error when the resource to be
8+
deleted is not found
9+
- Raised minimum azure-core version to 1.11.0
610

711
### Added
8-
- `KeyVaultAccessControlClient.set_role_definition` accepts an optional
12+
- `KeyVaultAccessControlClient.set_role_definition` accepts an optional
913
`assignable_scopes` keyword-only argument
1014

1115
### Breaking Changes
16+
- `KeyVaultAccessControlClient.delete_role_assignment` and
17+
`.delete_role_definition` return None
1218
- Changed parameter order in `KeyVaultAccessControlClient.set_role_definition`.
1319
`permissions` is now an optional keyword-only argument
14-
- Renamed `BackupOperation` to `KeyVaultBackupOperation`
15-
- Renamed `RestoreOperation` to `KeyVaultRestoreOperation`
16-
- Renamed `SelectiveKeyRestoreOperation` to
17-
`KeyVaultSelectiveKeyRestoreOperation`
18-
- Renamed `KeyVaultBackupClient.begin_selective_restore` to `begin_selective_key_restore`
19-
- Changed parameter order from `folder_url, sas_token, key_name` to
20-
`key_name, folder_url, sas_token`
20+
- Renamed `BackupOperation` to `KeyVaultBackupOperation`, and removed all but
21+
its `folder_url` property
22+
- Removed `RestoreOperation` and `SelectiveKeyRestoreOperation` classes
23+
- Removed `KeyVaultBackupClient.begin_selective_restore`. To restore a
24+
single key, pass the key's name to `KeyVaultBackupClient.begin_restore`:
25+
```
26+
# before (4.0.0b3):
27+
client.begin_selective_restore(folder_url, sas_token, key_name)
28+
29+
# after:
30+
client.begin_restore(folder_url, sas_token, key_name=key_name)
31+
```
32+
- Removed `KeyVaultBackupClient.get_backup_status` and `.get_restore_status`. Use
33+
the pollers returned by `KeyVaultBackupClient.begin_backup` and `.begin_restore`
34+
to check whether an operation has completed
2135
- `KeyVaultRoleAssignment`'s `principal_id`, `role_definition_id`, and `scope`
2236
are now properties of a `properties` property
2337
```
@@ -32,6 +46,12 @@
3246
- `denied_actions` -> `not_actions`
3347
- `allowed_data_actions` -> `data_actions`
3448
- `denied_data_actions` -> `denied_data_actions`
49+
- Renamed argument `role_assignment_name` to `name` in
50+
`KeyVaultAccessControlClient.create_role_assignment`, `.delete_role_assignment`,
51+
and `.get_role_assignment`
52+
- Renamed argument `role_definition_name` to `name` in
53+
`KeyVaultAccessControlClient.delete_role_definition` and `.get_role_definition`
54+
- Renamed argument `role_scope` to `scope` in `KeyVaultAccessControlClient` methods
3555

3656
## 4.0.0b3 (2021-02-09)
3757
### Added

sdk/keyvault/azure-keyvault-administration/README.md

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ a more appropriate name for your service principal.
8181
```Bash
8282
az keyvault create --hsm-name "<your-managed-hsm-name>" --resource-group "<your-resource-group-name>" --administrators <your-service-principal-object-id> --location "<your-azure-location>"
8383
```
84-
84+
8585
* Activate your managed HSM to enable key and role management. Detailed instructions can be found in [this quickstart guide](https://docs.microsoft.com/azure/key-vault/managed-hsm/quick-create-cli#activate-your-managed-hsm). Create three self signed certificates and download the [Security Domain](https://docs.microsoft.com/azure/key-vault/managed-hsm/security-domain) for your managed HSM:
8686
> **Important:** Create and store the RSA key pairs and security domain file generated in this step securely.
8787
```Bash
@@ -165,12 +165,12 @@ credential = DefaultAzureCredential()
165165
client = KeyVaultAccessControlClient(vault_url="https://my-managed-hsm-name.managedhsm.azure.net/", credential=credential)
166166
167167
# this will list all role definitions available for assignment
168-
role_definitions = client.list_role_definitions(role_scope=KeyVaultRoleScope.GLOBAL)
168+
role_definitions = client.list_role_definitions(KeyVaultRoleScope.GLOBAL)
169169
170-
for role_definition in role_definitions:
171-
print(role_definition.id)
172-
print(role_definition.role_name)
173-
print(role_definition.description)
170+
for definition in role_definitions:
171+
print(definition.id)
172+
print(definition.role_name)
173+
print(definition.description)
174174
```
175175
176176
### Set, Get, and Delete a role definition
@@ -180,33 +180,34 @@ for role_definition in role_definitions:
180180
```python
181181
import uuid
182182
from azure.identity import DefaultAzureCredential
183-
from azure.keyvault.administration import KeyVaultAccessControlClient, KeyVaultDataAction, KeyVaultPermission
183+
from azure.keyvault.administration import (
184+
KeyVaultAccessControlClient,
185+
KeyVaultDataAction,
186+
KeyVaultPermission,
187+
KeyVaultRoleScope
188+
)
184189
185190
credential = DefaultAzureCredential()
186191
187192
client = KeyVaultAccessControlClient(vault_url="https://my-managed-hsm-name.managedhsm.azure.net/", credential=credential)
188193
189-
# create the custom role definition
190-
role_scope = "/" # the global scope
191-
definition_name = uuid.uuid4()
194+
# create a custom role definition
192195
permissions = [KeyVaultPermission(allowed_data_actions=[KeyVaultDataAction.READ_HSM_KEY])]
193-
created_definition = client.set_role_definition(
194-
role_scope=role_scope, permissions=permissions, role_definition_name=definition_name
195-
)
196+
created_definition = client.set_role_definition(KeyVaultRoleScope.GLOBAL, permissions=permissions)
196197
197198
# update the custom role definition
198199
permissions = [
199200
KeyVaultPermission(allowed_data_actions=[], denied_data_actions=[KeyVaultDataAction.READ_HSM_KEY])
200201
]
201202
updated_definition = client.set_role_definition(
202-
role_scope=role_scope, permissions=permissions, role_definition_name=definition_name
203+
KeyVaultRoleScope.GLOBAL, permissions=permissions, role_name=created_definition.name
203204
)
204205
205206
# get the custom role definition
206-
definition = client.get_role_definition(role_scope=role_scope, role_definition_name=definition_name)
207+
definition = client.get_role_definition(KeyVaultRoleScope.GLOBAL, role_name=definition_name)
207208
208209
# delete the custom role definition
209-
deleted_definition = client.delete_role_definition(role_scope=role_scope, role_definition_name=definition_name)
210+
deleted_definition = client.delete_role_definition(KeyVaultRoleScope.GLOBAL, role_name=definition_name)
210211
```
211212
212213
### List all role assignments
@@ -221,43 +222,42 @@ credential = DefaultAzureCredential()
221222
client = KeyVaultAccessControlClient(vault_url="https://my-managed-hsm-name.managedhsm.azure.net/", credential=credential)
222223
223224
# this will list all role assignments
224-
role_assignments = client.list_role_assignments(role_scope=KeyVaultRoleScope.GLOBAL)
225+
role_assignments = client.list_role_assignments(KeyVaultRoleScope.GLOBAL)
225226
226-
for role_assignment in role_assignments:
227-
print(role_assignment.name)
228-
print(role_assignment.principal_id)
229-
print(role_assignment.role_definition_id)
227+
for assignment in role_assignments:
228+
print(assignment.name)
229+
print(assignment.principal_id)
230+
print(assignment.role_definition_id)
230231
```
231232
232233
### Create, Get, and Delete a role assignment
233234
Assign a role to a service principal. This will require a role definition id from the list retrieved in the [above snippet](#list-all-role-definitions) and the principal object id retrieved in the [Create and Get credentials](#create-and-get-credentials) section.
234235
235236
```python
236237
from azure.identity import DefaultAzureCredential
237-
from azure.keyvault.administration import KeyVaultAccessControlClient
238+
from azure.keyvault.administration import KeyVaultAccessControlClient, KeyVaultRoleScope
238239
239240
credential = DefaultAzureCredential()
240241
241242
client = KeyVaultAccessControlClient(vault_url="https://my-managed-hsm-name.managedhsm.azure.net/", credential=credential)
242243
243-
role_scope = "/" # the global scope
244244
role_definition_id = "<role-definition-id>" # Replace <role-definition-id> with the id of a definition returned from the previous example
245245
principal_id = "<your-service-principal-object-id>"
246246
247247
# first, let's create the role assignment
248-
role_assignment = client.create_role_assignment(role_scope, role_definition_id, principal_id)
248+
role_assignment = client.create_role_assignment(KeyVaultRoleScope.GLOBAL, role_definition_id, principal_id)
249249
print(role_assignment.name)
250250
print(role_assignment.principal_id)
251251
print(role_assignment.role_definition_id)
252252
253253
# now, we get it
254-
role_assignment = client.get_role_assignment(role_scope, role_assignment.name)
254+
role_assignment = client.get_role_assignment(KeyVaultRoleScope.GLOBAL, role_assignment.name)
255255
print(role_assignment.name)
256256
print(role_assignment.principal_id)
257257
print(role_assignment.role_definition_id)
258258
259259
# finally, we delete this role assignment
260-
role_assignment = client.delete_role_assignment(role_scope, role_assignment.name)
260+
role_assignment = client.delete_role_assignment(KeyVaultRoleScope.GLOBAL, role_assignment.name)
261261
print(role_assignment.name)
262262
print(role_assignment.principal_id)
263263
print(role_assignment.role_definition_id)
@@ -280,13 +280,13 @@ client = KeyVaultBackupClient(vault_url="https://my-managed-hsm-name.managedhsm.
280280
blob_storage_url = "<your-blob-storage-url>"
281281
sas_token = "<your-sas-token>" # replace with a sas token to your storage account
282282
283-
# performing a full key backup is a long-running operation. Calling result() on the poller will wait
284-
# until the backup is completed, then return an object representing the backup operation.
285-
backup_operation = client.begin_backup(blob_storage_url, sas_token).result()
283+
# Backup is a long-running operation. The client returns a poller object whose result() method
284+
# blocks until the backup is complete, then returns an object representing the backup operation.
285+
backup_poller = client.begin_backup(blob_storage_url, sas_token)
286+
backup_operation = backup_poller.result()
286287
288+
# this is the Azure Storage Blob URL of the backup
287289
print(backup_operation.folder_url)
288-
print(backup_operation.status)
289-
print(backup_operation.job_id)
290290
```
291291
292292
@@ -309,12 +309,10 @@ sas_token = "<your-sas-token>" # replace with a sas token to your storage accou
309309
# URL to a storage blob, for example https://<account name>.blob.core.windows.net/backup/mhsm-account-2020090117323313
310310
blob_url = "<your-blob-url>"
311311
312-
# performing a full key restore is a long-running operation. Calling `result()` on the poller will wait
313-
# until the restore is completed, then return an object representing the restore operation.
314-
restore_operation = client.begin_restore(blob_url, sas_token).result()
315-
316-
print(restore_operation.status)
317-
print(restore_operation.job_id)
312+
# Restore is a long-running operation. The client returns a poller object whose wait() method
313+
# blocks until the restore is complete.
314+
restore_poller = client.begin_restore(blob_url, sas_token)
315+
restore_poller.wait()
318316
```
319317
320318
## Troubleshooting

sdk/keyvault/azure-keyvault-administration/azure/keyvault/administration/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
KeyVaultRoleAssignment,
1313
KeyVaultRoleAssignmentProperties,
1414
KeyVaultRoleDefinition,
15-
KeyVaultRestoreOperation,
16-
KeyVaultSelectiveKeyRestoreOperation,
1715
)
1816

1917

@@ -28,6 +26,4 @@
2826
"KeyVaultRoleAssignmentProperties",
2927
"KeyVaultRoleDefinition",
3028
"KeyVaultRoleScope",
31-
"KeyVaultRestoreOperation",
32-
"KeyVaultSelectiveKeyRestoreOperation",
3329
]

0 commit comments

Comments
 (0)