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
+58-6Lines changed: 58 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,17 @@
1
1
---
2
2
title: Authentication secrets
3
3
titleSuffix: Azure Machine Learning
4
-
description: Learn how to pass secrets to training jobs in secure fashion using Azure Key Vault.
4
+
description: Learn how to securely get secrets from Azure Key Vault in your training jobs by using the Key Vault Secrets client library.
5
5
services: machine-learning
6
6
author: Blackmist
7
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
-
ms.custom: sdkv2
13
+
ms.custom: sdkv2, FY25Q1-Linter
14
+
# Customer intent: As a data scientist, I want to securely access secrets from Azure Key Vault in my training jobs so that I can use them in my training scripts.
14
15
---
15
16
16
17
# Use authentication credential secrets in Azure Machine Learning jobs
@@ -42,7 +43,7 @@ Before following the steps in this article, make sure you have the following pre
42
43
43
44
* (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
45
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:
46
+
* 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 runs 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
47
47
48
*[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
49
*[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.
@@ -52,7 +53,14 @@ Before following the steps in this article, make sure you have the following pre
52
53
> [!TIP]
53
54
> The quickstart link is to the steps for using the Azure Key Vault Python SDK. In the table of contents in the left navigation area are links to other ways to set a key.
54
55
55
-
## Getting secrets
56
+
## Get secrets
57
+
58
+
There are two ways to get secrets during training:
59
+
60
+
- Using a managed identity associated with the compute resource the training job runs on.
61
+
- Using your identity by having the compute run the job on your behalf.
62
+
63
+
# [Managed identity](#tab/managed)
56
64
57
65
1. Add the `azure-keyvault-secrets` and `azure-identity` packages to the [Azure Machine Learning environment](concept-environments.md) used when training the model. For example, by adding them to the conda file used to build the environment.
58
66
@@ -76,6 +84,50 @@ Before following the steps in this article, make sure you have the following pre
76
84
print(secret.value)
77
85
```
78
86
79
-
## Next steps
87
+
# [Your identity](#tab/user)
88
+
89
+
1. Add the `azure-keyvault-secrets`, `azure-identity`, and`azure-ai-ml` packages to the [Azure Machine Learning environment](concept-environments.md) used when training the model. For example, by adding them to the conda file used to build the environment.
90
+
91
+
The environment is used to build the Docker image that the training job runs in on the compute cluster.
92
+
93
+
1. From your training code, use the [Azure Machine Learning SDK](/python/api/overview/azure/ai-ml-readme) and [Key Vault client library](/python/api/overview/azure/keyvault-secrets-readme) to get the managed identity credentials and authenticate to key vault. The `AzureMLOnBehalfOfCredential`classis used to authenticate on behalf of your user identity:
94
+
95
+
```python
96
+
from azure.ai.ml.identity import AzureMLOnBehalfOfCredential
After authenticating, use the Key Vault client library to retrieve a secret by providing the associated key:
104
+
105
+
```python
106
+
secret = secret_client.get_secret("secret-name")
107
+
print(secret.value)
108
+
```
109
+
110
+
1. When you submit the training job, you must specify that it runs on behalf of your identity by using `identity=UserIdentityConfiguration()`. The following example submits a job using this parameter:
111
+
112
+
```python
113
+
from azure.ai.ml import Input, command
114
+
from azure.ai.ml.constants import AssetTypes
115
+
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).
128
+
129
+
---
130
+
131
+
## Related content
80
132
81
133
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