Based on the error pattern and the timing after your security policy update, here’s the comprehensive solution addressing all three focus areas:
IoT Hub IAM Roles:
First, verify the DPS managed identity has the correct roles assigned:
az role assignment create --assignee <DPS-managed-identity-id> \
--role "IoT Hub Data Contributor" \
--scope /subscriptions/<sub>/resourceGroups/<rg>/providers/Microsoft.Devices/IotHubs/<hub>
You need both ‘IoT Hub Data Contributor’ and ‘IoT Hub Registry Contributor’ for full device registration capabilities.
DPS Integration Permissions:
Your custom security policy needs to explicitly allow DPS operations. Update your policy JSON to include:
{
"properties": {
"policyRule": {
"if": {
"allOf": [
{"field": "type", "equals": "Microsoft.Devices/IotHubs/devices"},
{"field": "identity.principalId", "equals": "<DPS-managed-identity-id>"}
]
},
"then": {"effect": "allow"}
}
}
}
Custom Security Policy Restrictions:
The issue is that custom-security-policy-v2 likely has a broad deny rule that’s catching DPS registration attempts. You need to add an exception specifically for the provisioning service. Here’s the critical fix:
- Navigate to your IoT Hub policy assignments in the Azure Portal
- Edit custom-security-policy-v2
- Add an exemption for the DPS service principal before any deny rules
- Ensure the policy allows ‘Microsoft.Devices/IotHubs/devices/write’ action for DPS identity
The key is understanding the evaluation order: Custom Policy → RBAC → Resource-specific permissions. Your policy was blocking at the first gate, so RBAC roles never even got evaluated.
After making these changes, test with a new device enrollment. The 403 should resolve immediately. If you still see issues, enable IoT Hub diagnostic logs (category: DeviceIdentityOperations) to see the exact policy rule that’s triggering.
One more important note: If you’re using enrollment groups in DPS, make sure the custom policy allows bulk registration operations, not just individual device writes. This requires the ‘Microsoft.Devices/ProvisioningServices/enrollmentGroups/write’ action to be permitted as well.