Skip to content

Commit f5aeaae

Browse files
author
RoseHJM
committed
MDB - Customization - service principal authentication
1 parent f55875f commit f5aeaae

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

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

Lines changed: 61 additions & 2 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/18/2025
1616
---
1717

1818
# Connect to Azure resources or clone private repositories by using customizations
@@ -74,14 +74,73 @@ 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

8181
:::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":::
8282

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

85+
## Authenticate with service principals
86+
87+
You can use service principals to authenticate with Azure resources in your customizations. Service principals are a secure way to access Azure resources without using user credentials.
88+
89+
Create a Service Principal with required role assignments, and use it to log in in a customizations tasks, hydrating its credentials at customization time using the existing secrets feature. The next section provides the necessary steps.
90+
91+
1. Create a service principal in Azure Active Directory (Azure AD) and assign it the necessary roles for the resources you want to access.
92+
93+
```azurecli
94+
$ az ad sp create-for-rbac -n DevBoxCustomizationsTest
95+
96+
{
97+
  "appId": "...",
98+
  "displayName": "DevBoxCustomizationsTest",
99+
  "password": "...",
100+
  "tenant": "..."
101+
}
102+
```
103+
104+
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.
105+
106+
Store the password returned above in a Key Vault secret, e.g.
107+
108+
https://mykeyvault.vault.azure.net/secrets/password
109+
110+
On the Key Vault, grant the "Key Vault Secrets User" role to the project identity
111+
112+
Now you can authenticate in customization tasks, hydrating the service principal password from the Key Vault at customization time. E.g. to download a file from storage account:
113+
114+
The following YAML snippet defines a Dev Box customization that performs two main tasks:
115+
116+
1. Installs the Azure CLI using the winget package manager.
117+
1. Runs a PowerShell script that:
118+
- Logs in to Azure using a service principal, with the password securely retrieved from Azure Key Vault.
119+
- Downloads a blob (file) from an Azure Storage account using the authenticated session.
120+
121+
```yaml
122+
$schema: "1.0"
123+
name: "devbox-customization"
124+
tasks:
125+
- name: ~/winget
126+
parameters:
127+
package: Microsoft.AzureCLI
128+
- name: ~/powershell
129+
parameters:
130+
command: |
131+
az login --service-principal `
132+
--username <appId> `
133+
--password {{https://mykeyvault.vault.azure.net/secrets/password}} `
134+
--tenant <tenantId>
135+
az storage blob download `
136+
--account-name <storage_account_name> `
137+
--container-name <container_name> `
138+
--name <blob_name> `
139+
--file <local_file_path> `
140+
--auth-mode login
141+
```
142+
143+
This setup allows automated, secure access to Azure resources during Dev Box provisioning, without exposing credentials in the script.
85144

86145
## Related content
87146

0 commit comments

Comments
 (0)