Azure / Azure/azure-iot-sdk-csharp
[Bug Report] Owner and Contributor roles fail with 'is not authorized for GET on /twins/device_id', "IoT Hub Data Reader" is explicitely required
- Dominant language
- C#
- Stars
- 477
- Forks
- 492
- Avg merge
- 9h 55m
- Merged PRs (30d)
- 2
Description
1. Setup IoT Hub and give yourself Owner and/or Contributor roles
2. Create a device called in IoT Hub
3. ✅ This works:
```
az login --tenant xyz
az iot hub device-twin show --hub-name 'hub1' --device-id 'John' --query 'properties.desired' --output json --subscription 'sub1'
```
4. ❌ This doesn't work:
```
var hub = "rbtestiothub-leia.azure-devices.net";
var deviceId = "John";
var credential = new AzureCliCredential();
var ar rm = RegistryManager.Create(hub, credential);
var twin = await rm.GetTwinAsync(deviceId); // IotHubUnauthorized;Principal @.com is not authorized for GET on /twins/John
```
Error:
> Error: Microsoft.Azure.Devices.Common.Exceptions.UnauthorizedException: {"Message":"ErrorCode:IotHubUnauthorized;Principal @.com is not authorized for GET on /twins/John due to no assigned permissions","ExceptionMessage":"Tracking ID:abc:0-TimeStamp:06/26/2023 07:44:12"}
5. Assign "IoT Hub Data Reader" role to the user
6. ✅
```
var twin = await rm.GetTwinAsync(deviceId); // Success
```
----
Usings:
```
#i "nuget:https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json"
#i "nuget:https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json"
#r "nuget:Azure.Identity"
#r "nuget:Microsoft.Extensions.Azure"
#r "nuget:Microsoft.Azure.Devices"
using Azure.Identity;
using Microsoft.Extensions.Azure;
using Microsoft.Azure.Devices;
```
Contributor guide
Research direction
No source file or test is named. Start with RegistryManager.Create and GetTwinAsync, then compare their Azure CLI behavior under Owner or Contributor roles; done means the authorization discrepancy is reproduced and its expected behavior is confirmed with a regression test or documented resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- authorization, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100