Azure / iotedgehubdev

IoT Edge Hub Dev Tool
Other
87 stars 30 forks source link

Authentication Error debugging in VS Code #128

Closed dtjensen closed 5 years ago

dtjensen commented 5 years ago

When I attempt to setup my local simulator environment, I start by right clicking on my edge device in Azure IoT Toolkit extension and Selecting "Setup IoT Edge Simulator". I get the following error:

PS C:\Users\iotedgedev\Documents\FirstEdgeSolution\modules\FirstEdgeModule> iotedgehubdev setup -c "HostName=<hostname>.azure-devices.net;DeviceId=iotedge-testvm;SharedAccessKey=<token>"
ERROR: Error: KWarg[hostname]:iotedge-devtest.4d4p0pcxyg0unojsbvyrqks2zd.bx.internal.cloudapp.net string length needs to greater than or equal to 1 and less than 64 characters.

Note - I have followed these steps: https://docs.microsoft.com/en-us/azure/iot-edge/how-to-develop-csharp-module. Specifically, I have run the command to set the module credentials to user settings.

The error is avoided if I specify the "-l" option on the CLI which sets the hostname to localhost, but there is not a way to specify that command in the VS Code tooling.

So, I ignore the error and attempt to debug the module. When the debugger launches, I get the following error:

 Inner exceptions found, see $exception in variables window for more details.
 Innermost exception     System.Security.Authentication.AuthenticationException : The remote certificate is invalid according to the validation procedure.
   at Microsoft.Azure.Devices.Client.InternalClient.<>c.<ApplyTimeout>b__62_2(Task t)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at FirstEdgeModule.Program.<Init>d__3.MoveNext() in C:\Users\iotedgedev\Documents\FirstEdgeSolution\modules\FirstEdgeModule\Program.cs:line 49

What is the underlying issue here and how can I resolve this?

UPDATE: That host name is shown as the default host name on the usage screen:

Options:
  -g, --gateway-host TEXT  GatewayHostName value for the module to connect.  [default: iotedge-
                           devtest.4d4p0pcxyg0unojsbvyrqks2zd.bx.internal.cloudapp.net]
  -h, --help               Show this message and exit.
adashen commented 5 years ago

@dtjensen Thanks for reporting the issue. Currently we limited the gateway host name length to 64. The error happens since your FQDN(iotedge-devtest.4d4.................) length is 67. So the setup failed. We will investigate and try to figure out the new max length. In the mean while. You could work around the issue by specify a gateway host name when setting up iotedgehubdev through command line: iotedgehubdev setup -g -c

dtjensen commented 5 years ago

I am aware why I got the error. The error message is clear. I am logging the error because the host name "iotedge-devtest.4d4p0pcxyg0unojsbvyrqks2zd.bx.internal.cloudapp.net" is the default value. I did not set that value. So, by default, it errors. I also stated that when I use the "-l" option to set the hostname to "localhost", it resolves the issue. So, I am only logging the fact that the default hostname is invalid and that causes some of the tooling to error initially.

adashen commented 5 years ago

Thanks @dtjensen , we will update the hostname validation rule in the next release. And will keep you updated when it is released.

LazarusX commented 5 years ago

@dtjensen The hostname issue was fixed in the latest version. Please pip install --upgrade iotedgehubdev and try if it works for you now.