|
| 1 | +--- |
| 2 | +title: Configure Conditional Access Policies for Dev Tunnels |
| 3 | +description: Learn how to configure conditional access policies for the Dev tunnels service in Microsoft Entra ID to secure remote development environments and restrict access based on device management and IP ranges. |
| 4 | +author: RoseHJM |
| 5 | +contributors: |
| 6 | +ms.topic: how-to |
| 7 | +ms.date: 05/19/2025 |
| 8 | +ms.author: rosemalcolm |
| 9 | +ms.reviewer: rosemalcolm |
| 10 | +--- |
| 11 | + |
| 12 | +# Configure conditional access policies for Dev tunnels |
| 13 | + |
| 14 | +Microsoft Dev Box gives you an alternative connectivity method on top of Dev tunnels. You can develop remotely while coding locally or keep development going during Azure Virtual Desktop (AVD) outages or poor network performance. Many large enterprises using Dev Box have strict security and compliance policies, and their code is valuable to their business. Restricting Dev tunnels with conditional access policies is crucial for these controls. |
| 15 | + |
| 16 | +Conditional access policies for the Dev tunnels service: |
| 17 | + |
| 18 | +- Let Dev tunnels connect from managed devices, but deny connections from unmanaged devices. |
| 19 | +- Let Dev tunnels connect from specific IP ranges, but deny connections from other IP ranges. |
| 20 | +- Support other regular conditional access configurations. |
| 21 | +- Apply to both the Visual Studio Code application and VS Code web. |
| 22 | + |
| 23 | +## Configure conditional access |
| 24 | + |
| 25 | +The conditional access policies work correctly for the Dev tunnels service. Because registering the Dev tunnels service app to a tenant and making it available to the conditional access picker is unique, this article documents the steps. |
| 26 | + |
| 27 | +## Register Dev tunnels service to a tenant |
| 28 | + |
| 29 | +According to [Application and service principal objects in Microsoft Entra ID](/entra/identity-platform/app-objects-and-service-principals?tabs=browser), a service principal is created in each tenant where an application is used. However, this doesn't apply to the Dev tunnels service. The Dev tunnels service is a Microsoft service, and the service principal is created in the Microsoft Entra ID tenant where the Dev tunnels service is registered. The Dev tunnels service app isn't registered to your tenant by default, so you need to register it manually. |
| 30 | + |
| 31 | +Therefore, we're using [Microsoft.Graph PowerShell](/powershell/module/microsoft.graph.authentication/connect-mggraph?view=graph-powershell-1.0&preserve-view=true) to register the app to a tenant. |
| 32 | + |
| 33 | +1. Install PowerShell 7.x |
| 34 | + |
| 35 | +1. Follow [Install the Microsoft Graph PowerShell SDK | Microsoft Learn](/powershell/microsoftgraph/installation?view=graph-powershell-1.0&preserve-view=true) to install Microsoft.Graph PowerShell. |
| 36 | + |
| 37 | +1. Run the following commands: |
| 38 | + ```powershell |
| 39 | + # Connect to Microsoft Graph |
| 40 | + Connect-MgGraph -TenatnId <TenantID> -Scopes "Application.ReadWrite.All" |
| 41 | + |
| 42 | + # Register the Dev tunnels service app to the tenant |
| 43 | + $TunnelServiceAppId = "46da2f7e-b5ef-422a-88d4-2a7f9de6a0b2" |
| 44 | + New-MgServicePrincipal -AppId $TunnelServiceAppId |
| 45 | + ``` |
| 46 | +
|
| 47 | +1. Go to "Microsoft Entra ID" -> "Manage" -> "Enterprise applications" to verify if the Dev tunnels service is registered. |
| 48 | +
|
| 49 | + :::image type="content" source="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-register-service.png" alt-text="Screenshot of the Enterprise applications page in Microsoft Entra ID, showing the Dev tunnels service registration." lightbox="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-register-service.png"::: |
| 50 | +
|
| 51 | +## Enable the Dev tunnels service for the conditional access picker |
| 52 | +
|
| 53 | +The Microsoft Entra IDteam is working on removing the need to onboard apps for them to appear in the app picker, with delivery expected in May. Therefore, we aren't onboarding Dev tunnel service to the conditional access picker. Instead, target the Dev tunnels service in a conditional access policy using [Custom Security Attributes](/entra/identity/conditional-access/concept-filter-for-applications). |
| 54 | +
|
| 55 | +1. Follow [Add or deactivate custom security attribute definitions in Microsoft Entra ID](/entra/fundamentals/custom-security-attributes-add?tabs=ms-powershell) to add the following Attribute set and New attributes. |
| 56 | +
|
| 57 | + :::image type="content" source="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-custom-attributes.png" alt-text="Screenshot of the custom security attribute definition process in Microsoft Entra ID." lightbox="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-custom-attributes.png"::: |
| 58 | +
|
| 59 | + :::image type="content" source="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-attribute.png" alt-text="Screenshot of the new attribute creation in Microsoft Entra ID." lightbox="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-attribute.png"::: |
| 60 | +
|
| 61 | +1. Follow [Create a conditional access policy](/entra/identity/conditional-access/concept-filter-for-applications#create-a-conditional-access-policy) to create a conditional access policy. |
| 62 | +
|
| 63 | + :::image type="content" source="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-conditional-access-policy.png" alt-text="Screenshot of the conditional access policy creation process for Dev tunnels service." lightbox="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-conditional-access-policy.png"::: |
| 64 | +
|
| 65 | +1. Follow [Configure custom attributes](/entra/identity/conditional-access/concept-filter-for-applications#configure-custom-attributes) to configure the custom attribute for the Dev tunnels service. |
| 66 | +
|
| 67 | + :::image type="content" source="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-security-attributes.png" alt-text="Screenshot of configuring custom attributes for the Dev tunnels service in Microsoft Entra ID." lightbox="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-security-attributes.png"::: |
| 68 | +
|
| 69 | +## Testing |
| 70 | +
|
| 71 | +1. Turn off the BlockDevTunnelCA |
| 72 | +
|
| 73 | +1. Create a DevBox in the test tenant and run the following commands inside it. Dev tunnels can be created and connected externally. |
| 74 | +``` |
| 75 | +code tunnel user login --provider microsoft |
| 76 | +code tunnel |
| 77 | +``` |
| 78 | +
|
| 79 | +1. Enable the BlockDevTunnelCA. |
| 80 | +
|
| 81 | + 1. New connections to the existing Dev tunnels can't be established. Test with an alternate browser if a connection has already been established. |
| 82 | +
|
| 83 | + 1. Any new attempts to execute the commands in step #2 will fail. Both errors are: |
| 84 | +
|
| 85 | + :::image type="content" source="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-no-access.png" alt-text="Screenshot of error message when Dev tunnels connection is blocked by conditional access policy." lightbox="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-no-access.png"::: |
| 86 | +
|
| 87 | +1. The Microsoft Entra ID sign-in logs show these entries. |
| 88 | +
|
| 89 | + :::image type="content" source="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-activity-logs.png" alt-text="Screenshot of Microsoft Entra ID sign-in logs showing entries related to Dev tunnels conditional access policy." lightbox="media/how-to-conditional-access-dev-tunnels-service/dev-tunnels-activity-logs.png"::: |
| 90 | +
|
| 91 | +## Limitations |
| 92 | +
|
| 93 | +With Dev Tunnels, the following limitations apply: |
| 94 | +- You can't configure conditional access policies for Dev Box service to manage Dev tunnels for Dev Box users. |
| 95 | +- You can't limit Dev tunnels that aren't managed by the Dev Box service. In the context of Dev Boxes, if the Dev tunnels GPO is configured **to allow only selected Microsoft Entra tenant IDs**, Conditional Access policies can also restrict self-created Dev tunnels. |
| 96 | +
|
| 97 | +## Related content |
| 98 | +- [Conditional Access policies](/entra/identity/conditional-access/concept-conditional-access-policies) |
0 commit comments