Skip to content

Commit f84ebfd

Browse files
authored
Merge pull request #306122 from RoseHJM/mdb-update-sample
MDB - Update Key Vault URI sample
2 parents d54fdce + b9f2511 commit f84ebfd

2 files changed

Lines changed: 80 additions & 42 deletions

File tree

articles/dev-box/how-to-customizations-connect-resource-repository.md

Lines changed: 80 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,85 +12,121 @@ ms.custom:
1212
- ai-seo-date:05/10/2025
1313
- ai-gen-description
1414
ms.topic: how-to
15-
ms.date: 07/22/2025
15+
ms.date: 09/26/2025
1616
---
1717

18-
# Connect to Azure resources or clone private repositories by using customizations
18+
# Securely connect to Azure resources or clone private repositories
1919

20-
You can use secrets from your Azure key vault in your YAML customizations to clone private repositories, or with any task you author that requires an access token. For example, in a team customization file, you can use a personal access token (PAT) stored in a key vault to access a private repository.
20+
When you access resources like repositories or Azure resources during the customization process, you need to authenticate securely. You can reference Azure Key Vault secrets in your customization files to avoid exposing sensitive information, and you can use service principals to authenticate to Azure for secure resource access. This article explains how to manage and access resources securely during dev box customization.
2121

2222
## Use key vault secrets in customization files
2323

24-
To use a secret, like a PAT, in your customization files, store your PAT as a key vault secret.
24+
Use secrets from Azure Key Vault in your YAML customizations to clone private repositories or run tasks that require an access token. For example, in a customization file, use a personal access token (PAT) stored in Azure Key Vault to access a private repository.
2525

26-
Both team and user customizations support fetching secrets from a key vault. Team customizations, also known as image definition files, define the base image for the dev box with the `image` parameter, and list the tasks that run when a dev box is created. User customizations list the tasks that run when a dev box is created. The following examples show how to use a key vault secret in both types of customizations.
26+
Both team and user customizations support fetching secrets from a key vault. Team customizations, which use image definition files, define the base image for the dev box with the `image` parameter, and list the tasks that run when a dev box is created. User customizations list the tasks that run when a dev box is created.
2727

28-
To configure key vault secrets for use in your team or user customizations, ensure that your dev center project's managed identity has the Key Vault Secrets User role on your key vault.
28+
To use a secret, like a PAT, in your customization files, store it as a key vault secret. The following examples show how to reference a key vault secret in both types of customizations.
2929

30-
To configure key vault secrets for use in user customizations, you need to additionally:
30+
### Configure key vault access for customizations
3131

32-
1. Ensure that your dev center project's managed identity has the Key Vault Reader role and the Key Vault Secrets User role on your key vault.
33-
2. Grant the Key Vault Secrets User role for the key vault secret to each user or user group that should be able to consume the secret during the customization of a dev box. The user or group granted the role must include the managed identity for the dev center, the admin's user account, and any user or group that needs the secret during dev box customization.
32+
To configure key vault secrets for use in your team or user customizations, make sure the Dev Center project's managed identity has the Key Vault Secrets User role on your key vault.
3433

35-
You can use a key vault secret in-line with the built-in task:
34+
If your key vault is private, let trusted Microsoft services bypass the firewall because Dev Center doesn't yet support service tags.
3635

37-
```yml
38-
$schema: "1.0"
39-
image: microsoftwindowsdesktop_windows-ent-cpc_win11-24H2-ent-cpc
40-
tasks:
41-
- name: git-clone
42-
description: Clone this repository into C:\Workspaces
43-
parameters:
44-
command: MyCommand –MyParam '{{KEY_VAULT_SECRET_URI}}'
36+
The following screenshot shows the option to allow trusted Microsoft services to bypass the firewall in Azure Key Vault settings.
37+
38+
:::image type="content" source="media/how-to-customizations-connect-resource-repository/trusted-services-bypass-firewall.png" alt-text="Screenshot of the option to allow trusted Microsoft services to bypass the firewall in Azure Key Vault settings." lightbox="media/how-to-customizations-connect-resource-repository/trusted-services-bypass-firewall.png":::
39+
40+
To learn more about how to let trusted Microsoft services bypass the firewall, see [Configure Azure Key Vault networking settings](/azure/key-vault/general/how-to-azure-key-vault-network-security).
41+
42+
#### Additional configuration for user customizations
43+
44+
To configure key vault secrets for user customizations, also:
45+
46+
1. Ensure the Dev Center project's managed identity has both the Key Vault Reader and Key Vault Secrets User roles on your key vault.
47+
1. Grant the Key Vault Secrets User role for the secret to each user or group who needs it during dev box customization, including the Dev Center managed identity, admin accounts, and any other required users or groups.
48+
49+
### Team customizations example
50+
51+
This syntax uses a key vault secret (PAT) in an image definition file. The `KEY_VAULT_SECRET_URI` is the URI of the secret in your key vault.
52+
53+
```yaml
54+
$schema: "<SCHEMA_VERSION>"
55+
name: "<IMAGE_DEFINITION_NAME>"
56+
image: "<BASE_IMAGE>"
57+
description: "<DESCRIPTION>"
58+
59+
tasks:
60+
- name: <TASK_NAME>
61+
description: <TASK_DESCRIPTION>
62+
parameters:
63+
repositoryUrl: <REPOSITORY_URL>
64+
directory: <DIRECTORY_PATH>
65+
pat: "{{<KEY_VAULT_SECRET_URI>}}"
4566
```
46-
This example shows an image definition file. The `KEY_VAULT_SECRET_URI` is the URI of the secret in your key vault.
4767
48-
You can reference the secret in your YAML customization in the following format, which uses the `git-clone` task as an example:
68+
This example uses the `git-clone` task:
4969

50-
```yml
70+
```yaml
5171
$schema: "1.0"
72+
name: "example-image-definition"
73+
image: microsoftvisualstudio_visualstudioplustools_vs-2022-ent-general-win11-m365-gen2
74+
description: "Clones a public example Git repository"
75+
5276
tasks:
5377
- name: git-clone
54-
description: Clone this repository into C:\Workspaces
78+
description: Clone this repository into C:\workspaces
5579
parameters:
56-
repositoryUrl: https://myazdo.visualstudio.com/MyProject/_git/myrepo
57-
directory: C:\Workspaces
58-
pat: '{{KEY_VAULT_SECRET_URI}}'
80+
repositoryUrl: https://github.com/example-org/example-repo.git
81+
directory: C:\workspaces
82+
pat: "{{https://contoso-vault.vault.azure.net/secrets/github-pat}}"
5983
```
60-
This example shows a user customization file. There is no `image` specified.
6184

62-
User customizations let you obtain an Azure DevOps token to clone private repositories without explicitly specifying a PAT from the key vault. The service automatically exchanges your Azure token for an Azure DevOps token at run time.
85+
Or, you can reference the secret in-line with a built-in task, as shown in the following example:
6386

64-
```yml
87+
```yaml
6588
$schema: "1.0"
66-
tasks:
67-
- name: git-clone
89+
name: "example-image-definition"
90+
image: microsoftvisualstudio_visualstudioplustools_vs-2022-ent-general-win11-m365-gen2
91+
description: "Clones a public example Git repository"
92+
93+
tasks:
94+
- name: git-clone
6895
description: Clone this repository into C:\Workspaces
6996
parameters:
70-
repositoryUrl: https://myazdo.visualstudio.com/MyProject/_git/myrepo
71-
directory: C:\Workspaces
72-
pat: '{{ado://YOUR_ORG_NAME}}'
73-
```
97+
command: MyCommand –MyParam "{{KEY_VAULT_SECRET_URI}}"
98+
```
7499

75-
The Dev Box VS Code extension and Dev Box CLI don't support hydrating secrets in the inner-loop testing workflow for customizations.
76100

77-
### Configure key vault access
101+
### User customizations example
78102

79-
The dev center needs access to your key vault. Because dev centers don't support service tags, if your key vault is private, let trusted Microsoft services bypass the firewall.
103+
User customizations let you obtain an Azure DevOps token to clone private repositories without explicitly specifying a PAT from the key vault. The service automatically exchanges your Azure token for an Azure DevOps token at run time.
80104

81-
:::image type="content" source="media/how-to-customizations-connect-resource-repository/trusted-services-bypass-firewall.png" alt-text="Screenshot that shows the option to allow trusted Microsoft services to bypass the firewall in Azure Key Vault settings." lightbox="media/how-to-customizations-connect-resource-repository/trusted-services-bypass-firewall.png":::
105+
This example shows the ADO shorthand (`{{ado://...}}`). The service exchanges your Azure token for an Azure DevOps token at runtime, so you don't need to store a PAT in Key Vault.
82106

83-
To learn how to let trusted Microsoft services bypass the firewall, see [Configure Azure Key Vault networking settings](/azure/key-vault/general/how-to-azure-key-vault-network-security).
107+
```yaml
108+
$schema: "1.0"
109+
tasks:
110+
- name: git-clone
111+
description: Clone this repository into C:\workspaces
112+
parameters:
113+
repositoryUrl: https://dev.azure.com/example-org/MyProject/_git/example-repo
114+
directory: C:\workspaces
115+
pat: '{{ado://example-org}}'
116+
```
84117

118+
The Dev Box Visual Studio Code extension and Dev Box CLI don't support hydrating secrets in the inner-loop testing workflow for customizations.
85119

86120
## Authenticate to Azure resources with service principals
87121

88-
Service principals let you securely authenticate to Azure resources exposing user credentials. You can create a Service Principal, assign the necessary role assignments, and use it to authenticate in a customization tasks, hydrating its credentials at customization time using the existing secrets feature. The next section explains the steps.
122+
Service principals let you securely authenticate to Azure resources without exposing user credentials. Create a service principal, assign the required roles, and use it to authenticate in a customization task. Hydrate its password from Key Vault at customization time using the existing secrets feature.
89123

90124
1. Create a service principal in Azure Active Directory (Azure AD), and assign it the necessary roles for the resources you want to use.
91125

92126
The output is a JSON object containing the service principal's *appId*, *displayName*, *password*, and *tenant*, which are used for authentication and authorization in Azure Automation scenarios.
93127

128+
Example: CLI output when you create a service principal. Store the returned password in Key Vault and grant the Key Vault Secrets User role to the Dev Center project identity so the customization can hydrate the secret at runtime.
129+
94130
```azurecli
95131
$ az ad sp create-for-rbac -n DevBoxCustomizationsTest
96132
@@ -109,14 +145,16 @@ Service principals let you securely authenticate to Azure resources exposing use
109145
Now you can authenticate in customization tasks, hydrating the service principal password from the Key Vault at customization time.
110146

111147
### Example: Download a file from Azure Storage
112-
The following example shows you how to download a file from storage account. The YAML snippet defines a Dev Box customization that performs two main tasks:
148+
The following example shows how to download a file from a storage account. The YAML snippet defines a Dev Box customization that performs two main tasks:
113149

114150
1. Installs the Azure CLI using the winget package manager.
115151

116152
1. Runs a PowerShell script that:
117153
- Logs in to Azure using a service principal, with the password securely retrieved from Azure Key Vault.
118154
- Downloads a blob (file) from an Azure Storage account using the authenticated session.
119155

156+
Example: customization that hydrates a service principal password from Key Vault and uses it to authenticate and download a blob from Azure Storage. Store the service principal password in Key Vault and ensure the project identity has Key Vault Secrets User role.
157+
120158
```yaml
121159
$schema: "1.0"
122160
name: "devbox-customization"
@@ -142,7 +180,7 @@ The following example shows you how to download a file from storage account. The
142180
This setup lets you automate secure use of Azure resources during Dev Box provisioning without exposing credentials in the script.
143181

144182
### Example: Download an artifact from Azure DevOps
145-
Download build artifacts from Azure DevOps (ADO) by using a service principal for authentication. Add the service principal's Application ID (appId) as a user in your Azure DevOps organization, and assign it to the **Readers** group. This step gives the necessary permissions to use build artifacts.
183+
Download build artifacts from Azure DevOps (ADO) by using a service principal for authentication. Add the service principal's Application ID (appId) as a user in your Azure DevOps organization, then assign the principal to the **Readers** group. This step gives the necessary permissions to use build artifacts.
146184

147185
After you configure these steps, use the service principal credentials in customization tasks to authenticate and download artifacts securely from Azure DevOps.
148186

142 KB
Loading

0 commit comments

Comments
 (0)