You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sdk/keyvault/azure-keyvault-administration/README.md
+309-2Lines changed: 309 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,308 @@
1
-
# Azure Key Vault Administration client library for Python
1
+
# Azure KeyVault Administration client library for Python
2
+
Azure Key Vault helps solve the following problems:
3
+
- Vault administration (this library) - role-based access control (RBAC), and vault-level backup and restore options
4
+
- Cryptographic key management ([azure-keyvault-keys](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/keyvault/azure-keyvault-keys)) - create, store, and control
[azure-identity][azure_identity] is used for Azure Active Directory
22
+
authentication as demonstrated below.
23
+
24
+
### Prerequisites
25
+
* An [Azure subscription][azure_sub]
26
+
* Python 2.7, 3.5.3, or later
27
+
* A Key Vault. If you need to create one, See the final two steps in the next section for details on creating the Key Vault with the Azure CLI.
28
+
29
+
### Authenticate the client
30
+
This document demonstrates using [DefaultAzureCredential][default_cred_ref]
31
+
to authenticate as a service principal. However, this package's clients
32
+
accept any [azure-identity][azure_identity] credential. See the
33
+
[azure-identity][azure_identity] documentation for more information about other
34
+
credentials.
35
+
36
+
#### Create and Get credentials
37
+
This [Azure Cloud Shell][azure_cloud_shell] snippet shows how to create a
38
+
new service principal. Before using it, replace "your-application-name" with
39
+
a more appropriate name for your service principal.
40
+
41
+
* Create a service principal:
42
+
```Bash
43
+
az ad sp create-for-rbac --name http://your-application-name --skip-assignment
44
+
```
45
+
46
+
> Output:
47
+
>```json
48
+
> {
49
+
>"appId": "generated app id",
50
+
>"displayName": "your-application-name",
51
+
>"name": "http://your-application-name",
52
+
>"password": "random password",
53
+
>"tenant": "tenant id"
54
+
> }
55
+
>```
56
+
57
+
* Take note of the service principal objectId
58
+
```Bash
59
+
az ad sp show --id <appId> --query objectId
60
+
```
61
+
62
+
63
+
> Output:
64
+
>```
65
+
>"<your-service-principal-object-id>"
66
+
>```
67
+
68
+
* Use the output to set**AZURE_CLIENT_ID** ("appId" above), **AZURE_CLIENT_SECRET**
69
+
("password" above) and **AZURE_TENANT_ID** ("tenant" above) environment variables.
70
+
The following example shows a way to do this in Bash:
71
+
```Bash
72
+
export AZURE_CLIENT_ID="generated app id"
73
+
export AZURE_CLIENT_SECRET="random password"
74
+
export AZURE_TENANT_ID="tenant id"
75
+
```
76
+
77
+
* 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):
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.
122
+
123
+
A role definition is specified as part of a role assignment.
124
+
125
+
### Role Assignment.
126
+
A role assignment is the association of a role definition to a service principal. They can be created, listed, fetched individually, and deleted.
127
+
128
+
### KeyVaultAccessControlClient
129
+
A `KeyVaultAccessControlClient` manages role definitions and role assignments.
130
+
131
+
### KeyVaultBackupClient
132
+
A `KeyVaultBackupClient` performs full key backups, full key restores, and selective key restores.
133
+
7
134
## Examples
135
+
This section conntains code snippets covering common tasks:
136
+
* Access Control
137
+
* [List all role definitions](#list-all-role-definitions "List all role definitions")
138
+
* [List all role assignments](#list-all-role-assignments "List all role assignments")
139
+
* [Create, Get, and Delete a role assignment](#create-get-and-delete-a-role-assignment "Create, Get, and Delete a role assignment")
140
+
* Backup and Restore
141
+
* [Perform a full key backup](#perform-a-full-key-backup "Perform a full key backup")
142
+
* [Perform a full key restore](#perform-a-full-key-restore "Perform a full key restore")
143
+
144
+
### List all role definitions
145
+
List the role definitions available for assignment.
146
+
147
+
```python
148
+
from azure.identity import DefaultAzureCredential
149
+
from azure.keyvault.administration import KeyVaultAccessControlClient
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)
186
+
187
+
```python
188
+
import uuid
189
+
from azure.identity import DefaultAzureCredential
190
+
from azure.keyvault.administration import KeyVaultAccessControlClient
Back up your entire collection of keys. The backing store for full key backups is a blob storage container using Shared Access Signature authentication.
222
+
223
+
For more details on creating a SAS token using the `BlobServiceClient`, see the sample [here](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/storage/azure-storage-blob/samples/blob_samples_authentication.py#L105).
224
+
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)
225
+
226
+
```python
227
+
from azure.identity import DefaultAzureCredential
228
+
from azure.keyvault.administration import KeyVaultBackupClient
Restore your entire collection of keys from a backup. The data sourcefor a full key restore is a storage blob accessed using Shared Access Signature authentication.
251
+
You will also need the `azure_storage_blob_container_uri` from the [above snippet](#perform-a-full-key-backup).
252
+
253
+
For more details on creating a SAS token using the `BlobServiceClient`, see the sample [here](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/storage/azure-storage-blob/samples/blob_samples_authentication.py#L105).
254
+
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)
255
+
256
+
```python
257
+
from azure.identity import DefaultAzureCredential
258
+
from azure.keyvault.administration import KeyVaultBackupClient
securely store and control access to tokens, passwords, certificates, API keys,
9
9
and other secrets
10
+
- Vault administration ([azure-keyvault-administration](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/keyvault/azure-keyvault-administration)) - role-based access control (RBAC), and vault-level backup and restore options
create, manage, and deploy public and private SSL/TLS certificates
12
+
- Vault administration ([azure-keyvault-administration](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/keyvault/azure-keyvault-administration)) - role-based access control (RBAC), and vault-level backup and restore options
create, manage, and deploy public and private SSL/TLS certificates
13
+
- Vault administration ([azure-keyvault-administration](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/keyvault/azure-keyvault-administration)) - role-based access control (RBAC), and vault-level backup and restore options
0 commit comments