Skip to content

Commit b8dbf31

Browse files
Merge pull request #211885 from rastala/ci-msi
Update how-to-create-manage-compute-instance.md
2 parents 7d58505 + 95d4fac commit b8dbf31

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

articles/machine-learning/how-to-create-manage-compute-instance.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,58 @@ Following is a sample policy to default a shutdown schedule at 10 PM PST.
428428
}
429429
```
430430

431+
## Assign managed identity (preview)
432+
433+
You can assign a system- or user-assigned [managed identity](https://learn.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview) to a compute instance, to autheticate against other Azure resources such as storage. Using managed identities for authentication helps improve workspace security and management. For example you can allow users to access training data only when logged in to compute instance, or use a common user-assigned managed identity to permit access to a specific storage account.
434+
435+
You can create compute instance with managed identity from Azure ML Studio:
436+
437+
1. Fill out the form to [create a new compute instance](?tabs=azure-studio#create).
438+
1. Select **Next: Advanced Settings**.
439+
1. Enable **Assign a managed identity**.
440+
1. Select **System-assigned** or **User-assigned** under **Identity type**.
441+
1. If you selected **User-assigned**, select subscription and name of the identity.
442+
443+
You can use V2 CLI to create compute instance with assign system-assigned managed identity:
444+
445+
```azurecli
446+
az ml compute create --name myinstance --identity-type SystemAssigned --type ComputeInstance --resource-group my-resource-group --workspace-name my-workspace
447+
```
448+
449+
You can also use V2 CLI with yaml file, for example to create a compute instance with user-assigned managed identity:
450+
451+
```azurecli
452+
azure ml compute create --file compute.yaml --resource-group my-resource-group --workspace-name my-workspace
453+
```
454+
455+
The identity definition is contained in compute.yaml file:
456+
457+
```yaml
458+
https://azuremlschemas.azureedge.net/latest/computeInstance.schema.json
459+
name: myinstance
460+
type: computeinstance
461+
identity:
462+
type: user_assigned
463+
user_assigned_identities:
464+
- resource_id: identity_resource_id
465+
```
466+
467+
Once the managed identity is created, enable [identity-based data access enabled](how-to-identity-based-data-access.md) to your storage accounts for that identity. Then, when you worki on the compute instance, the managed identity is used automatically to authenticate against data stores.
468+
469+
You can also use the managed identity manually to authenticate against other Azure resources. For example, to use it to get ARM access token, use following.
470+
471+
```python
472+
import requests
473+
474+
def get_access_token_msi(resource):
475+
client_id = os.environ.get("DEFAULT_IDENTITY_CLIENT_ID", None)
476+
resp = requests.get(f"{os.environ['MSI_ENDPOINT']}?resource={resource}&clientid={client_id}&api-version=2017-09-01", headers={'Secret': os.environ["MSI_SECRET"]})
477+
resp.raise_for_status()
478+
return resp.json()["access_token"]
479+
480+
arm_access_token = get_access_token_msi("https://management.azure.com")
481+
```
482+
431483
## Add custom applications such as RStudio (preview)
432484

433485
You can set up other applications, such as RStudio, when creating a compute instance. Follow these steps in studio to set up a custom application on your compute instance
@@ -437,7 +489,7 @@ You can set up other applications, such as RStudio, when creating a compute inst
437489
1. Select **Add application** under the **Custom application setup (RStudio Workbench, etc.)** section
438490

439491
:::image type="content" source="media/how-to-create-manage-compute-instance/custom-service-setup.png" alt-text="Screenshot showing Custom Service Setup.":::
440-
492+
441493
### Setup RStudio Workbench
442494

443495
RStudio is one of the most popular IDEs among R developers for ML and data science projects. You can easily set up RStudio Workbench to run on your compute instance, using your own RStudio license, and access the rich feature set that RStudio Workbench offers.

0 commit comments

Comments
 (0)