Skip to content

Commit 65f455e

Browse files
authored
Merge pull request #106855 from nibaccam/secrets-maintenance
Secrets| Freshness update
2 parents 4721507 + 4780d2b commit 65f455e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

articles/machine-learning/how-to-use-secrets-in-runs.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,33 @@ ms.reviewer: larryfr
99
ms.service: machine-learning
1010
ms.subservice: core
1111
ms.topic: conceptual
12-
ms.date: 11/08/2019
13-
ms.custom: seodec18
12+
ms.date: 03/09/2020
1413

1514
---
1615

1716
# Use secrets in training runs
1817
[!INCLUDE [applies-to-skus](../../includes/aml-applies-to-basic-enterprise-sku.md)]
1918

20-
In this article, you learn how to use secrets in training runs securely. For example, to connect to an external database to query training data, you would need to pass your username and password to the remote run context. Coding such values into training scripts in cleartext is insecure as it would expose the secret.
19+
In this article, you learn how to use secrets in training runs securely. Authentication information such as your user name and password are secrets. For example, if you connect to an external database in order to query training data, you would need to pass your username and password to the remote run context. Coding such values into training scripts in cleartext is insecure as it would expose the secret.
2120

22-
Instead, your Azure Machine Learning Workspace has [Azure Key Vault](https://docs.microsoft.com/azure/key-vault/key-vault-overview) as associated resource. This Key Vault can be used for passing secrets to remote runs securely through a set of APIs in Azure Machine Learning Python SDK.
21+
Instead, your Azure Machine Learning workspace has an associated resource called a [Azure Key Vault](https://docs.microsoft.com/azure/key-vault/key-vault-overview). Use this Key Vault to pass secrets to remote runs securely through a set of APIs in the Azure Machine Learning Python SDK.
2322

2423
The basic flow for using secrets is:
25-
1. On local computer, log in to Azure and connect to your Workspace.
24+
1. On local computer, log in to Azure and connect to your workspace.
2625
2. On local computer, set a secret in Workspace Key Vault.
2726
3. Submit a remote run.
28-
4. Within the remote run, get the secret from Key Value and use it.
27+
4. Within the remote run, get the secret from Key Vault and use it.
2928

3029
## Set secrets
3130

32-
In the Azure Machine Learning Python SDK, the [Keyvault](https://docs.microsoft.com/python/api/azureml-core/azureml.core.keyvault.keyvault?view=azure-ml-py) class contains methods for setting secrets. In your local Python session, first obtain a reference to Workspace Key Vault, and then use [set_secret](https://docs.microsoft.com/python/api/azureml-core/azureml.core.keyvault.keyvault?view=azure-ml-py#set-secret-name--value-) method to set a secret by name and value.
31+
In the Azure Machine Learning, the [Keyvault](https://docs.microsoft.com/python/api/azureml-core/azureml.core.keyvault.keyvault?view=azure-ml-py) class contains methods for setting secrets. In your local Python session, first obtain a reference to your workspace Key Vault, and then use the [`set_secret()`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.keyvault.keyvault?view=azure-ml-py#set-secret-name--value-) method to set a secret by name and value. The __set_secret__ method updates the secret value if the name already exists.
3332

3433
```python
3534
from azureml.core import Workspace
35+
from azureml.core import Keyvault
3636
import os
3737

38+
3839
ws = Workspace.from_config()
3940
my_secret = os.environ.get("MY_SECRET")
4041
keyvault = ws.get_default_keyvault()
@@ -43,25 +44,25 @@ keyvault.set_secret(name="mysecret", value = my_secret)
4344

4445
Do not put the secret value in your Python code as it is insecure to store it in file as cleartext. Instead, obtain the secret value from an environment variable, for example Azure DevOps build secret, or from interactive user input.
4546

46-
You can list secret names using the [list_secrets](https://docs.microsoft.com/python/api/azureml-core/azureml.core.keyvault.keyvault?view=azure-ml-py#list-secrets--) method. The __set_secret__ method updates the secret value if the name already exists.
47+
You can list secret names using the [`list_secrets()`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.keyvault.keyvault?view=azure-ml-py#list-secrets--) method and there is also a batch version,[set_secrets()](https://docs.microsoft.com/python/api/azureml-core/azureml.core.keyvault.keyvault?view=azure-ml-py#set-secrets-secrets-batch-) that allows you to set multiple secrets at a time.
4748

4849
## Get secrets
4950

50-
In your local code, you can use the[Keyvault.get_secret](https://docs.microsoft.com/python/api/azureml-core/azureml.core.keyvault.keyvault?view=azure-ml-py#get-secret-name-) method to get the secret value by name.
51+
In your local code, you can use the[`get_secret()`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.keyvault.keyvault?view=azure-ml-py#get-secret-name-) method to get the secret value by name.
5152

52-
In runs submitted using [Experiment.submit](https://docs.microsoft.com/python/api/azureml-core/azureml.core.experiment.experiment?view=azure-ml-py#submit-config--tags-none----kwargs-), use the [Run.get_secret](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run.run?view=azure-ml-py#get-secret-name-) method. Because a submitted run is aware of its Workspace, this method shortcuts the Workspace instantiation and returns the secret value directly.
53+
For runs submitted the [`Experiment.submit`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.experiment.experiment?view=azure-ml-py#submit-config--tags-none----kwargs-) , use the [`get_secret()`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run.run?view=azure-ml-py#get-secret-name-) method with the [`Run`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run(class)?view=azure-ml-py) class. Because a submitted run is aware of its workspace, this method shortcuts the Workspace instantiation and returns the secret value directly.
5354

5455
```python
5556
# Code in submitted run
56-
from azureml.core import Run
57+
from azureml.core import Experiment, Run
5758

5859
run = Run.get_context()
5960
secret_value = run.get_secret(name="mysecret")
6061
```
6162

6263
Be careful not to expose the secret value by writing or printing it out.
6364

64-
The set and get methods also have batch versions [set_secrets](https://docs.microsoft.com/python/api/azureml-core/azureml.core.keyvault.keyvault?view=azure-ml-py#set-secrets-secrets-batch-) and [get_secrets](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run.run?view=azure-ml-py#get-secrets-secrets-) for accessing multiple secrets at once.
65+
There is also a batch version, [get_secrets()](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run.run?view=azure-ml-py#get-secrets-secrets-) for accessing multiple secrets at once.
6566

6667
## Next steps
6768

0 commit comments

Comments
 (0)