Skip to content

Commit a9eb669

Browse files
authored
Merge pull request #303012 from RoseHJM/mdb-cust-add-auth-sp
MDB - Customization - service principal authentication
2 parents 040b392 + 0b26d53 commit a9eb669

File tree

3 files changed

+89
-5
lines changed

3 files changed

+89
-5
lines changed

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

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

1818
# Connect to Azure resources or clone private repositories by using customizations
@@ -74,7 +74,7 @@ tasks:
7474

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

77-
## Configure key vault access
77+
### Configure key vault access
7878

7979
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.
8080

@@ -83,8 +83,91 @@ The dev center needs access to your key vault. Because dev centers don't support
8383
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).
8484

8585

86+
## Authenticate to Azure resources with service principals
87+
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.
89+
90+
1. Create a service principal in Azure Active Directory (Azure AD), and assign it the necessary roles for the resources you want to use.
91+
92+
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.
93+
94+
```azurecli
95+
$ az ad sp create-for-rbac -n DevBoxCustomizationsTest
96+
97+
{
98+
"appId": "...",
99+
"displayName": "DevBoxCustomizationsTest",
100+
"password": "...",
101+
"tenant": "..."
102+
}
103+
```
104+
105+
1. Store the password returned above in a Key Vault secret, like this: `https://mykeyvault.vault.azure.net/secrets/password`
106+
107+
1. On the Key Vault, grant the *Key Vault Secrets User* role to the project identity.
108+
109+
Now you can authenticate in customization tasks, hydrating the service principal password from the Key Vault at customization time.
110+
111+
### 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:
113+
114+
1. Installs the Azure CLI using the winget package manager.
115+
116+
1. Runs a PowerShell script that:
117+
- Logs in to Azure using a service principal, with the password securely retrieved from Azure Key Vault.
118+
- Downloads a blob (file) from an Azure Storage account using the authenticated session.
119+
120+
```yaml
121+
$schema: "1.0"
122+
name: "devbox-customization"
123+
tasks:
124+
- name: ~/winget
125+
parameters:
126+
package: Microsoft.AzureCLI
127+
- name: ~/powershell
128+
parameters:
129+
command: |
130+
az login --service-principal `
131+
--username <appId> `
132+
--password {{https://mykeyvault.vault.azure.net/secrets/password}} `
133+
--tenant <tenantId>
134+
az storage blob download `
135+
--account-name <storage_account_name> `
136+
--container-name <container_name> `
137+
--name <blob_name> `
138+
--file <local_file_path> `
139+
--auth-mode login
140+
```
141+
142+
This setup lets you automate secure use of Azure resources during Dev Box provisioning without exposing credentials in the script.
143+
144+
### 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.
146+
147+
After you configure these steps, use the service principal credentials in customization tasks to authenticate and download artifacts securely from Azure DevOps.
148+
149+
#### Add a service principal to an Azure DevOps organization
150+
151+
To add a service principal to your Azure DevOps organization:
152+
153+
1. Sign in to your Azure DevOps organization, and open **Organization settings**.
154+
1. In the menu, select **Users**.
155+
1. On the **Users** page, select **Add users**.
156+
1. In the **Add new users** dialog, enter the following information:
157+
158+
:::image type="content" source="media/how-to-customizations-connect-resource-repository/dev-box-customizations-devops-add-user.png" alt-text="Screenshot of the Add new users dialog in Azure DevOps, showing fields for user email, access level, project, and group assignment." lightbox="media/how-to-customizations-connect-resource-repository/dev-box-customizations-devops-add-user.png":::
159+
160+
- **Users**: Enter the service principal's Application ID (appId) as the user email.
161+
- **Access Level**: Select **Basic**.
162+
- **Add to project**: Select the project where you want to add the service principal.
163+
- **Azure DevOps groups**: Assign the service principal to the **Readers** group.
164+
165+
1. Complete the process to grant the necessary permissions.
166+
167+
For details on how to add users to DevOps organizations, see [Add organization users and manage access](/azure/devops/organizations/accounts/add-organization-users).
168+
86169
## Related content
87170

88-
- [Microsoft Dev Box customizations](concept-what-are-dev-box-customizations.md)
89-
- [Configure Dev Box imaging](how-to-configure-dev-box-imaging.md)
90-
- Learn how to [add and configure a catalog from GitHub or Azure Repos](../deployment-environments/how-to-configure-catalog.md).
171+
- Learn how to [Set and retrieve a secret from Azure Key Vault using the Azure portal](/azure/key-vault/secrets/quick-create-portal).
172+
- Learn how to [Add and configure a catalog from GitHub or Azure Repos](../deployment-environments/how-to-configure-catalog.md).
173+
- Learn how to [Use service principals & managed identities in Azure DevOps](/azure/devops/integrate/get-started/authentication/service-principal-managed-identity).
Loading

articles/dev-box/toc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ items:
9191
- name: Configure tasks for customizations
9292
href: how-to-configure-customization-tasks.md
9393
- name: Connect to Azure resources and repositories
94+
displayName: customizations, secrets, Azure Key Vault
9495
href: how-to-customizations-connect-resource-repository.md
9596
- name: Add and Manage Catalogs
9697
href: how-to-configure-catalog.md

0 commit comments

Comments
 (0)