Closed fvdnabee closed 2 years ago
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @kasun04, @saglodha.
Author: | fvdnabee |
---|---|
Assignees: | - |
Labels: | `Event Hubs`, `Service Attention`, `customer-reported`, `question`, `needs-team-attention`, `Service` |
Milestone: | - |
Hi @fvdnabee. Thank you for reaching out and we regret that you're experiencing difficulties. In this case, the stack trace indicates that the Event Hubs service is rejecting the authorization request.
Azure.Messaging.EventHubs.EventHubsException : InvalidIssuer: Token issuer is invalid. TrackingId:ec70fbfe-4f50-4621-a6e1-c58a67070b49, SystemTracker:NoSystemTracker, Timestamp:2022-03-10T13:52:30 (iot-d-10007318-0)
Because IoT Hub provisions an Event Hubs instance on your behalf, I believe that it can only be accessed using the associated connection string. I've routed this to the Event Hubs service team, who would be best able to answer this authoritatively.
//cc: @serkantkaraca, @JamesBirdsall
Can you make sure both EH and function app are under the same tenant? Event Hubs doesn't support cross tenant OAuth2 authorization.
@serkantkaraca Given the exception text I also thought that the tenant is to blame, but alas the function and the IoT hub are very much under the same tenant (even in the same subscription and resource group). To me it sounds like the function app is not using the tenant from the MSI for authenticating to the EH. I've tried adding an app setting <CONNECTION_NAME_PREFIX>__tenantId
, to explicitly state the Tenant ID (even though this is documented as unsupported when hosted in the Azure Function service), but the same error remains. I'd like to debug the auth token presented to the EH service, but don't know how from a Function App.
@jsquire note that the docs state that Identity-based connections are supported by the IoT hub binding. I'm guessing the docs are just copied from the EH binding, but if it turns out that identity-based connections are in fact not supported for the IoT hub binding specifically it would be nice to update the docs.
After fiddling with the logging settings in the function's host.json file, I got some more debugging output from the Azure SDK. Unfortunately all the interesting fields in regards to MSI authentication are redacted; can these be (temporarily) unredacted?
Another question that popped up: with identity-based connections for IoT hubs what should the eventHubName setting be set to? When using a connection string, the name is sourced from the conn string; does it use the entityPath in this case? I've set eventHubName via an app setting to the name of the iothub (iot-d-10007318-0); is this the correct eventhub name for an IoT hub? The connection string for the IoT hub built-in EH looks is follows: Endpoint=sb://iothub-ns-iot-d-1000-17752060-5d3adbd147.servicebus.windows.net/;SharedAccessKeyName=iothubowner;SharedAccessKey=REDACTED;EntityPath=iot-d-10007318-0
, does the SDK source the eventHubName from the Endpoint or from the EntityPath in the case of a connection string?
Here are some interesting excerpts from the logs:
Note the logs also contain storage access (which uses a connection string (from key vault), as MSI authentication is not supported for Azure Files which is mandatory for Windows Function consumption plans)
I've tried switching to a System-managed MSI only and dropping the key vault references (i.e. the Function App only has a SystemAssigned MSI now); but the same Token issuer is invalid exception remains.
I made a terraform config that is shareable, if anyone would like to reproduce this. For now, I don't know how to continue troubleshooting this issue.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @drwill-ms, @timtay-microsoft, @abhipsaMisra, @azabbasi, @brycewang-microsoft, @aandykwong-ms.
Author: | fvdnabee |
---|---|
Assignees: | - |
Labels: | `IoT`, `Service Attention`, `customer-reported`, `question`, `needs-team-attention`, `Service` |
Milestone: | - |
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @drwill-ms, @timtay-microsoft, @abhipsaMisra, @azabbasi, @brycewang-microsoft, @aandykwong-ms.
Author: | fvdnabee |
---|---|
Assignees: | - |
Labels: | `IoT`, `Service Attention`, `customer-reported`, `question`, `needs-team-attention`, `Service` |
Milestone: | - |
It seems as if we've moved into an area where IoT Hub expertise is needed; I've retagged and looped in the IoT Hub team.
I've produced a reproduction repo for this issue, where you can verify that the Eventhub trigger with an identity-based connection works for an Eventhub binding input but not for an IoT hub binding input (InvalidIssuer).
The repro repo allows you to easily switch between consuming from an eventhub or an iot hub.
The repro repo uses a system-assigned MSI, as opposed to a user-assigned MSI from the OP. Switching to user-assigned identity is straightforward, cfr. the Use user-assigned identity to authenticate with IoT hub
comments in TF code for funcapp.tf.
This is unfortunately not a bug, but incorrect Azure Functions documentation. If you take a look at the Permissions for IoT Hub Service APIs section you can see that Azure AD Auth for the Event Hub Compatible Endpoint is not supported. Only key-based access is available.
If you'd like to use Managed Identities end to end, the recommendation is to use IoT Hub Routing to send data to an event hub you control (outbound routing can be authenticated with Managed Identity). And then read from that event hub using MI.
We should update the functions doc to show the correct capabilities: @ggailey777 @cachai2 @dksimpson @craigshoemaker
That is indeed unfortunate, might I then suggest to update the IoT hub function docs with this limitation and to just include a link to the docs on the eventhub binding for identity-based connections.
Are there any plans for supporting Azure AD Auth on the Event Hub Compatible Endpoint? Could be an interesting differentiator for the Standard SKU.
I've addressed this issue as suggested by both @jlorich and @fvdnabee in the Functions IoT hub trigger article. https://github.com/MicrosoftDocs/azure-docs-pr/pull/191924
@fvdnabee unfortunately the event hub that IoT hub creates on your behalf lives in a different tenant, untrusted by the AAD of the MSI - or at least that is my understanding of it.
Alternatively, one can create their own event hub and configure it with IoT hub routing (and disable the built-in endpoint). Then you can do whatever you want to your event hub instance, including access it via an MSI.
Library name and version
Microsoft.Azure.WebJobs.Extensions.EventHubs: 5.0.0
Describe the bug
A Function App containing an IoT hub trigger binding configured with am eventhub connection via a user-assigned MSI is unable to authenticate with the EventHub, the SDK throws an exception
Azure.Messaging.EventHubs.EventHubsException : InvalidIssuer: Token issuer is invalid
.Expected behavior
The Function App is able to authenticate successfully with the event hub.
Actual behavior
The following exception is thrown by the Function App runtime, indicating that the function has failed to start (indeed it is never invoked successfully).
Azure.Messaging.EventHubs.EventHubsException : InvalidIssuer: Token issuer is invalid
2022-03-10T13:52:17.487 [Information] Starting JobHost 2022-03-10T13:52:17.490 [Information] Starting Host (HostId=func-d-10007318-cdbfx-hdz7, InstanceId=e42ad721-4353-4d59-8d42-ca9638defca1, Version=4.1.3.17473, ProcessId=7160, AppDomainId=1, InDebugMode=True, InDiagnosticMode=False, FunctionsExtensionVersion=~4) 2022-03-10T13:52:17.504 [Information] FUNCTIONS_WORKER_RUNTIME set to node. Skipping WorkerConfig for language:java 2022-03-10T13:52:17.506 [Information] FUNCTIONS_WORKER_RUNTIME set to node. Skipping WorkerConfig for language:powershell 2022-03-10T13:52:17.508 [Information] Loading functions metadata 2022-03-10T13:52:17.533 [Information] 1 functions loaded 2022-03-10T13:52:17.559 [Information] Generating 1 job function(s) 2022-03-10T13:52:17.599 [Information] Found the following functions: Host.Functions.iothub-events-func 2022-03-10T13:52:18.295 [Information] Initializing function HTTP routes No HTTP routes mapped 2022-03-10T13:52:18.301 [Information] Host initialized (804ms) 2022-03-10T13:52:18.343 [Information] HttpOptions { "DynamicThrottlesEnabled": true, "EnableChunkedRequestBinding": false, "MaxConcurrentRequests": 100, "MaxOutstandingRequests": 200, "RoutePrefix": "api" } 2022-03-10T13:52:18.418 [Information] Worker process started and initialized. 2022-03-10T13:52:22.613 [Information] Host lock lease acquired by instance ID 'ffb36bd0b4e8606c3d02b60790248fe9'. 2022-03-10T13:52:30.511 [Error] The listener for function 'Functions.iothub-events-func' was unable to start. Microsoft.Azure.WebJobs.Host.Listeners.FunctionListenerException : The listener for function 'Functions.iothub-events-func' was unable to start. ---> System.AggregateException : One or more errors occurred. (InvalidIssuer: Token issuer is invalid. TrackingId:ec70fbfe-4f50-4621-a6e1-c58a67070b49, SystemTracker:NoSystemTracker, Timestamp:2022-03-10T13:52:30 (iot-d-10007318-0)) ---> InvalidIssuer: Token issuer is invalid. TrackingId:ec70fbfe-4f50-4621-a6e1-c58a67070b49, SystemTracker:NoSystemTracker, Timestamp:2022-03-10T13:52:30 (iot-d-10007318-0) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Azure.Messaging.EventHubs.Primitives.EventProcessor`1.StartProcessingInternalAsync[TPartition](Boolean async,CancellationToken cancellationToken) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Azure.Messaging.EventHubs.Primitives.EventProcessor`1.StartProcessingAsync[TPartition](CancellationToken cancellationToken) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Microsoft.Azure.WebJobs.EventHubs.Processor.EventProcessorHost.StartProcessingAsync(IEventProcessorFactory processorFactory,BlobsCheckpointStore checkpointStore,CancellationToken cancellationToken) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Microsoft.Azure.WebJobs.EventHubs.Listeners.EventHubListener.StartAsync(CancellationToken cancellationToken) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Microsoft.Azure.WebJobs.Host.Listeners.FunctionListener.StartAsync(??) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Listeners\FunctionListener.cs : 68 ---> (Inner Exception #0) Azure.Messaging.EventHubs.EventHubsException : InvalidIssuer: Token issuer is invalid. TrackingId:ec70fbfe-4f50-4621-a6e1-c58a67070b49, SystemTracker:NoSystemTracker, Timestamp:2022-03-10T13:52:30 (iot-d-10007318-0) at Azure.Messaging.EventHubs.AmqpError.ThrowIfErrorResponse(AmqpMessage response,String eventHubName) at async Azure.Messaging.EventHubs.Amqp.AmqpClient.GetPropertiesAsync(EventHubsRetryPolicy retryPolicy,CancellationToken cancellationToken) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Azure.Messaging.EventHubs.Amqp.AmqpClient.GetPropertiesAsync(EventHubsRetryPolicy retryPolicy,CancellationToken cancellationToken) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Azure.Messaging.EventHubs.EventHubConnection.GetPropertiesAsync(EventHubsRetryPolicy retryPolicy,CancellationToken cancellationToken) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Azure.Messaging.EventHubs.Primitives.EventProcessor`1.ValidateEventHubsConnectionAsync[TPartition](CancellationToken cancellationToken) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Azure.Messaging.EventHubs.Primitives.EventProcessor`1.ValidateEventHubsConnectionAsync[TPartition](CancellationToken cancellationToken) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at async Azure.Messaging.EventHubs.Primitives.EventProcessor`1.ValidateStartupAsync[TPartition](Boolean async,CancellationToken cancellationToken)<--- End of inner exceptionIt is unclear how I can further diagnose the issue, as I lack access to the Azure Functions runtime. I verified that the app settings are indeed set from the scm.azurewebsites.net page.
Reproduction Steps
Deploy a Function App with an IoT hub trigger using a user-managed MSI for authentication. When Azure Functions tries to start the function, you will find the InvalidIssuer exception in the function logs.
Environment
IoT hub trigger binding configured with eventhub connection via a user-assigned MSI.
The function app runs on a Windows Consumption Function App,
The following App settings are set to authenticate via a user-managed MSI, in accordance with the docs on Identity-based connections:
The user-assigned MSI has been granted a role assignment on the resource group containing the IoT hub for the Azure Event Hubs Data Receiver role.
The function's Eventhub binding is configured as follows (function.json; the function is written in javascript):
The function is using the latest extension bundle publicly available: Azure Functions Extensions Bundles Preview release 4.0.0.
Windows Consumption plan Function app details:
edit:
The function app has two user-managed MSIs assigned: one for authenticating with the IoT hub eventhub and a second one for authenticating with a key vault (containing the storage account connection string, amongst others). There is no system-managed MSI assigned to the function app