Arduino
Arduino

Reputation: 373

Azure IoT failed acces [401 Unauthorised]

I'm facing a connection issue from my IoT Edge device to its IoT Hub (apparently) as a result of an unauthorised access. This same set-up worked fine under a personal (regular router-ISP) network connection, but failed once set in a larger and more secured network.

I've made sure all necessary ports are open for the device's static IP and connection strings have no typos, but the problem persists. After researching I've found out some users with similar issues had trouble with the SAS authentification, although I've never changed it nor touched it in any of the tests run before, so I'm usure about that one. The logs I'm getting along with the error is the following one:

-- Logs begin at Thu 2016-11-03 14:16:42 -03, end at Sun 2019-01-13 03:36:22 -03. --
Jan 13 03:05:21 camaraIQF0 systemd[1]: Started Azure IoT Edge daemon.
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Starting Azure IoT Edge Security Daemon
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Version - 1.0.5 (d76e0316c6f324345d77c48a83ce836d09392699)
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Using config file: /etc/iotedge/config.yaml
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Using runtime network id azure-iot-edge
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Initializing the module runtime...
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Initializing module runtime...
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Successfully initialized module runtime
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Finished initializing the module runtime.
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Configuring /var/lib/iotedge as the home directory.
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Configuring certificates...
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Transparent gateway certificates not found, operating in quick start mode...
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Finished configuring certificates.
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Initializing hsm...
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Finished initializing hsm.
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Detecting if configuration file has changed...
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - No change to configuration file detected.
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Obtaining workload CA succeeded.
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Provisioning edge device...
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Manually provisioning device "camaraIQF_0" in hub "camarasIQF.azure-devices.net"
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Finished provisioning edge device.
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Starting management API...
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Starting workload API...
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Starting watchdog with 60 second frequency...
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Listening on fd://iotedge.mgmt.socket/ with 1 thread for management API.
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Listening on fd://iotedge.socket/ with 1 thread for workload API.
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Checking edge runtime status
Jan 13 03:05:21 camaraIQF0 iotedged[724]: 2019-01-13T06:05:21Z [INFO] - Creating and starting edge runtime module edgeAgent
Jan 13 03:05:22 camaraIQF0 iotedged[724]: 2019-01-13T06:05:22Z [WARN] - Error in watchdog when checking for edge runtime status:
Jan 13 03:05:22 camaraIQF0 iotedged[724]: 2019-01-13T06:05:22Z [WARN] - A module runtime error occurred.
Jan 13 03:05:22 camaraIQF0 iotedged[724]: 2019-01-13T06:05:22Z [WARN] -         caused by: Could not get identity $edgeAgent
Jan 13 03:05:22 camaraIQF0 iotedged[724]: 2019-01-13T06:05:22Z [WARN] -         caused by: Could not get module $edgeAgent
Jan 13 03:05:22 camaraIQF0 iotedged[724]: 2019-01-13T06:05:22Z [WARN] -         caused by: HTTP request failed: [401 Unauthorized] {"Message":"ErrorCode:IotHubUnauthorizedAccess;Un         authorized","ExceptionMessage":"Tracking ID:876068fddc8545f799e54da7f991d694-G:10-TimeStamp:01/14/2019 15:19:50"}

After the last warning messages it keeps looping checking the edge runtime status and failing to connect, so it never downloads the modules and therefore can't run properly. The device is a raspberry running raspbian.

Any ideas on this issue?

Thanks!

Upvotes: 1

Views: 1452

Answers (1)

Arduino
Arduino

Reputation: 373

Found the issue, posting here in case anyone comes accross the same problem.

The device couldn't get the date and time automatically so there was a mismatch between this one and Azure's and that caused the authentification error.

Setting the raspberry's date and time to the current one in my region solved the problem.

Upvotes: 2

Related Questions