"Unauthorized access" error message when using azure CLI "az iot hub device-identity create" command

Anatoli A 5 Reputation points
2025-01-31T18:50:03.9033333+00:00

I am using azure CLI v2.68.0 to create IoT devices in the IoT hub from Raspberry Pi

 $ az --version
azure-cli                         2.68.0
core                              2.68.0
telemetry                          1.1.0
Extensions:
azure-iot                         0.25.0
Dependencies:
msal                              1.31.1
azure-mgmt-resource               23.1.1
Python location '/opt/az/bin/python3'
Extensions directory '/home/flasher/.azure/cliextensions'
Python (Linux) 3.12.8 (main, Jan  8 2025, 03:39:17) [GCC 12.2.0]
Legal docs and information: aka.ms/AzureCliLegal

Upon setup - everything works fine - devices are created fine.

Overnight something happens and the same exact command starts to give this error message:

{'Message': '{"errorCode":401002,"message":"Unauthorized access","trackingId":"827C01A8D2084CEF9E98CC376C4A75C9-G2:-TimeStamp:2025-01-31T18:39:38.719746153Z","timestampUtc":"2025-01-31T18:39:38.719746153Z","info":null}', 'ExceptionMessage': ''}

Running in verbose more does not provide any more details. Azure documentation does not elaborate on the details of error 401002

Any ideas? It happened twice already. Works right after fresh install and then stops overnight,

Help!

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,235 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Anatoli A 5 Reputation points
    2025-01-31T19:09:40.4133333+00:00

    Figured it out - this is caused by the NTP failure - az refuses to honor commands from the past.

    Go figure... login from the past is OK, device create - no.

    1 person found this answer helpful.
    0 comments No comments

  2. Abiola Akinbade 23,060 Reputation points
    2025-01-31T22:46:01.8733333+00:00

    Hello Anatoli A,

    Glad that fixed it.

    For the error codes in future you could cross-verify here

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.devices.common.exceptions.errorcode?view=azure-dotnet

    Regards,

    Abiola

    0 comments No comments

  3. Sander van de Velde | MVP 34,766 Reputation points MVP
    2025-02-01T02:53:14.8733333+00:00

    Hello @Anatoli A ,

    welcome to this moderated Azure community forum.

    If I understand correctly, you encountered a 401002 error with the message 'Unauthorized access' when you wanted to create another device using the Azure CLI.

    You are using azure-iot extention 0.25.0 which is the latest release at this moment.

    It was fixed by logging in via 'az login' while the correct time was set, a problem that was related via to a NTP failure.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.