Unauthorized error send message from function app to eventgrid with Role Based Access for Event Grid Send

Sergio Solorzano 26 Reputation points
2022-11-25T10:47:27.733+00:00

I have a function app with a function that sends message to event grid. A function in this same function app is subscribed to this event grid topic. I get unauthorized access to send message despite function app has set role based access for Event Grid Send.

I have set the function app Identity to System Assigned ON:

264242-image.png

I also set the function app Assigned Role to Event Grid Sender at Subscription level (within which the event grid topic also sits):

264215-image.png

The event grid sender role assigned is confirmed at IAM Role Assignments of the Event Grid Topic:

264232-image.png

When I execute the function app to send data to event grid I get unauthorized error:

//Name of the endpoint of Event grid topic  
        string topicEndpoint = transformAlgoSendRMessage_TopicEP;  
        //Creating client to publish events to eventgrid topic  
        EventGridPublisherClient client = new EventGridPublisherClient(new Uri(topicEndpoint), new DefaultAzureCredential());  
        //Creating a sample event with Subject, Eventtype, dataVersion and data  
        EventGridEvent egEvent = new EventGridEvent("TransformTelemetry", "TransformAlgorithm.broadcastTransform", "1.0", machinePartTransformTelemetry);  
        // Send the event  
          
        try  
        {  
            await client.SendEventAsync(egEvent);  
            if (b_debug_contractor)  
                log.LogInformation("SendRTransformMessage sent transformdata - PosX:" + machinePartTransformTelemetry[1]);  
        }  
        catch (Exception e)  
        {  
            log.LogError("Failed to send SendRTransformMessage. " + e.Message);  
        }  

Unauthorized Error:

[2022-11-25T08:00:45.646Z] Failed to send SendRTransformMessage. The principal associated with access token presented with the incoming request does not have permission to send data to /subscriptions/MySubscriptionID/resourceGroups/myresourcegroup/providers/Microsoft.EventGrid/topics/functionappname. Report 'e9595a36-8420-4466-b91a-801fbfcf605d:4:11/25/2022 8:00:48 AM (UTC)' to our forums for assistance or raise a support ticket.  
[2022-11-25T08:00:45.646Z] Status: 401 (The principal associated with access token presented with the incoming request does not have permission to send data to /subscriptions/mySubscriptionID/resourceGroups/myresourcegroup/providers/Microsoft.EventGrid/topics/myfunctionappname. Report 'e9595a36-8420-4466-b91a-801fbfcf605d:4:11/25/2022 8:00:48 AM (UTC)' to our forums for assistance or raise a support ticket.)  
[2022-11-25T08:00:45.647Z] ErrorCode: Unauthorized  
[2022-11-25T08:00:45.647Z]  
[2022-11-25T08:00:45.647Z] Content:  
[2022-11-25T08:00:45.648Z] {  
[2022-11-25T08:00:45.648Z]     "error": {  
[2022-11-25T08:00:45.649Z]         "code": "Unauthorized",  
[2022-11-25T08:00:45.649Z]         "message": "The principal associated with access token presented with the incoming request does not have permission to send data to /subscriptions/mySubscriptionID/resourceGroups/myresourcegroup/providers/Microsoft.EventGrid/topics/myfunctionappname. Report 'e9595a36-8420-4466-b91a-801fbfcf605d:4:11/25/2022 8:00:48 AM (UTC)' to our forums for assistance or raise a support ticket.",  
[2022-11-25T08:00:45.650Z]         "details": [{  
[2022-11-25T08:00:45.650Z]             "code": "Unauthorized",  
[2022-11-25T08:00:45.650Z]             "message": "The principal associated with access token presented with the incoming request does not have permission to send data to /subscriptions/mySubscriptionID/resourceGroups/myresourcegroup/providers/Microsoft.EventGrid/topics/myfunctionappname. Report 'e9595a36-8420-4466-b91a-801fbfcf605d:4:11/25/2022 8:00:48 AM (UTC)' to our forums for assistance or raise a support ticket."  

I note I also tried with Grid Event topic key but received exception Key 1 doesn't exist.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,644 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
350 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sergio Solorzano 26 Reputation points
    2022-11-28T20:17:10.857+00:00

    In case it helps anyone, this was resolved see here.

    1 person found this answer helpful.
    0 comments No comments