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: articles/machine-learning/how-to-migrate-from-v1.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -172,7 +172,7 @@ Environments created from v1 can be used in v2. In v2, environments have new fea
172
172
173
173
## Managing secrets
174
174
175
-
The management of Key Vault secrets differs significantly in V2 compared to V1. The V1 set_secret and get_secret SDK methods are not available in V2. Instead, direct access using Key Vault client libraries should be used.
175
+
The management of Key Vault secrets differs significantly in V2 compared to V1. The V1 set_secret and get_secret SDK methods are not available in V2. Instead, direct access using Key Vault client libraries should be used. When accessing secrets from a training script, you can use either the managed identity of the compute or your identity.
176
176
177
177
For details about Key Vault, see [Use authentication credential secrets in Azure Machine Learning training jobs](how-to-use-secrets-in-runs.md?view=azureml-api-2&preserve-view=true).
Copy file name to clipboardExpand all lines: articles/machine-learning/how-to-use-secrets-in-runs.md
+40-2Lines changed: 40 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ ms.author: larryfr
8
8
ms.reviewer: roastala
9
9
ms.service: azure-machine-learning
10
10
ms.subservice: enterprise-readiness
11
-
ms.date: 01/19/2024
11
+
ms.date: 08/20/2024
12
12
ms.topic: how-to
13
13
ms.custom: sdkv2
14
14
---
@@ -42,7 +42,7 @@ Before following the steps in this article, make sure you have the following pre
42
42
43
43
* (Optional) An Azure Machine Learning compute cluster configured to use a [managed identity](how-to-create-attach-compute-cluster.md?tabs=azure-studio#set-up-managed-identity). The cluster can be configured for either a system-assigned or user-assigned managed identity.
44
44
45
-
* If your job will run on a compute cluster, grant the managed identity for the compute cluster access to the secrets stored in key vault. Or, if the job will run on serverless compute, grant the managed identity specified for the job access to the secrets. The method used to grant access depends on how your key vault is configured:
45
+
* If your job runs on a compute cluster, grant the managed identity for the compute cluster access to the secrets stored in key vault. Or, if the job will run on serverless compute, grant the managed identity specified for the job access to the secrets. The method used to grant access depends on how your key vault is configured:
46
46
47
47
*[Azure role-based access control (Azure RBAC)](/azure/key-vault/general/rbac-guide): When configured for Azure RBAC, add the managed identity to the __Key Vault Secrets User__ role on your key vault.
48
48
*[Azure Key Vault access policy](/azure/key-vault/general/assign-access-policy): When configured to use access policies, add a new policy that grants the __get__ operation for secrets and assign it to the managed identity.
@@ -60,6 +60,10 @@ Before following the steps in this article, make sure you have the following pre
60
60
61
61
1. From your training code, use the [Azure Identity SDK](/python/api/overview/azure/identity-readme) and [Key Vault client library](/python/api/overview/azure/keyvault-secrets-readme) to get the managed identity credentials and authenticate to key vault:
62
62
63
+
# [Managed identity](#tab/managed)
64
+
65
+
To use the managed identity of the compute to access the key vault, use `DefaultAzureCredential` to get the compute's identity.
66
+
63
67
```python
64
68
from azure.identity import DefaultAzureCredential
65
69
from azure.keyvault.secrets import SecretClient
@@ -69,13 +73,47 @@ Before following the steps in this article, make sure you have the following pre
When you submit the training job, you must specify that it runs in the context of your identity by using `identity=UserIdentityConfiguration()`. The following example submits a job using this parameter:
89
+
90
+
```python
91
+
from azure.ai.ml import Input, command
92
+
from azure.ai.ml.constants import AssetTypes
93
+
from azure.ai.ml.entities import UserIdentityConfiguration
For an example of using the Azure CLI to submit a job that uses your identity, visit [Https://github.com/Azure/azureml-examples/blob/d4c90eead3c1fd97393d0657f7a78831490adf1c/cli/jobs/single-step/on-behalf-of/README.md](https://github.com/Azure/azureml-examples/blob/d4c90eead3c1fd97393d0657f7a78831490adf1c/cli/jobs/single-step/on-behalf-of/README.md).
106
+
107
+
---
108
+
72
109
1. After authenticating, use the Key Vault client library to retrieve a secret by providing the associated key:
73
110
74
111
```python
75
112
secret = secret_client.get_secret("secret-name")
76
113
print(secret.value)
77
114
```
78
115
116
+
79
117
## Next steps
80
118
81
119
For an example of submitting a training job using the Azure Machine Learning Python SDK v2, see [Train models with the Python SDK v2](how-to-train-sdk.md).
0 commit comments