Search code examples
c#azureazure-storageazure-data-explorer

Ingest Data into Azure Clustered Storage give error for Kusto.Common.Svc.Exceptions.UnauthorizedOperationException


--Want to Add insert data into Azure storage cluster using stream method. --Ingestion client is generated but when try to insert new record into cluster table than it is giving error for authroization, Note i have added my account to access table and also give permission to ingest data Though other than these please let me know if any thing pending to ingest data or any reference link to ingest data in to azure cluster storage

 var tempObject = new { starttime = startTime, endtime = endTime, trigger = rowKey, 
                interval = "", site="",asset = asset,property = "",
                aggregate = "", value = "",normal ="",
                nvalue = "", svalue = "", meta = ""
            };
        var stringJson = JsonConvert.SerializeObject(tempObject);
        var kustoUri = "https://{cluster}.{region}.kusto.windows.net";
        var ingestUri = "https://ingest-{cluster}.{region}.kusto.windows.net";
        string database = "abcd";
        var kustoConnectionStringBuilder =
            new KustoConnectionStringBuilder(ingestUri)
            {
                FederatedSecurity = true,
                InitialCatalog = database,
                Authority = "{tenantID}"
            };

       
        var ingestClient = KustoIngestFactory.CreateQueuedIngestClient(kustoConnectionStringBuilder);
        var table = "TableName";
        var tableMapping = "TableMapping";
     
        var properties =
                new KustoQueuedIngestionProperties(database, table)
                {
                    Format = DataSourceFormat.multijson,
                    IngestionMapping = new IngestionMapping()
                    {
                        IngestionMappingReference = tableMapping
                    }
                };
        // convert string to stream
        byte[] byteArray = Encoding.UTF8.GetBytes(stringJson);
        //byte[] byteArray = Encoding.ASCII.GetBytes(contents);
        MemoryStream stream = new MemoryStream(byteArray);
        ingestClient.IngestFromStream(stream, properties);

Following error i get @ line ingestClient.IngestFromStream(stream, properties); I used following refrences to ingest data into it.

  Kusto.Ingest.Exceptions.IngestionResourcesNotFoundException: 'No ingestion resources were returned from Kusto endpoint. Error: 'An exception was thrown while attempting to retrieve resources from endpoint : 'https://ingest-{cluster}.{region}.kusto.windows.net'. 'Forbidden (403-Forbidden): {
        "error": {
            "code": "Forbidden",
            "message": "Caller is not authorized to perform this action",
            "@type": "Kusto.Common.Svc.Exceptions.UnauthorizedOperationException",
            "@message": "Principal '[email protected]' is not authorized to perform operation 'Access the Kusto DM service for Ingest on any of the cluster's databases' on '[unspecified target]'.",
            "@context": {
                "timestamp": "2021-03-03T02:24:06.4434620Z",
                "serviceAlias": "INGEST-RDDATAEXPLORERCLUSTER1",
                "machineName": "KDataMana000000",
                "processName": "Kusto.WinSvc.DM.Svc",
                "processId": 11984,
                "threadId": 4852,
                "appDomainName": "Kusto.WinSvc.DM.Svc.exe",
                "clientRequestId": "KI.KustoQueuedIngestClient.IngestFromStream.121db307-20b0-4940-b5aa-cdfaf8b1d4bc;5af7c92f-c57a-4d9f-bf6a-885bbcc4a52e;c7deb2bd-76bf-42b3-8eaf-84f4aac04986;1",
                "activityId": "22fdfdd9-5dc2-46cd-a9b2-9e829cf907ab",
                "subActivityId": "7916a2e6-daeb-4913-a2cd-77d82669320d",
                "activityType": "P.WCF.Service.ExecuteControlCommandInternal..IAdminClientServiceCommunicationContract",
                "parentActivityId": "8da57be2-5ab4-438b-88eb-211af02a36f1",
                "activityStack": "(Activity stack: CRID=KI.KustoQueuedIngestClient.IngestFromStream.121db307-20b0-4940-b5aa-cdfaf8b1d4bc;5af7c92f-c57a-4d9f-bf6a-885bbcc4a52e;c7deb2bd-76bf-42b3-8eaf-84f4aac04986;1 ARID=22fdfdd9-5dc2-46cd-a9b2-9e829cf907ab > DN.Admin.Client.ExecuteControlCommand/8da57be2-5ab4-438b-88eb-211af02a36f1 > P.WCF.Service.ExecuteControlCommandInternal..IAdminClientServiceCommunicationContract/7916a2e6-daeb-4913-a2cd-77d82669320d)"
            },
            "@permanent": true
        }
    }. This normally represents a permanent error, and retrying is unlikely to help.
    Error details:
    DataSource='https://{cluster}.{region}.australiaeast.kusto.windows.net:443/v1/rest/mgmt',
    DatabaseName='database name',
    ClientRequestId='KI.KustoQueuedIngestClient.IngestFromStream.121db307-20b0-4940-b5aa-cdfaf8b1d4bc;5af7c92f-c57a-4d9f-bf6a-885bbcc4a52e;c7deb2bd-76bf-42b3-8eaf-84f4aac04986;1',
    ActivityId='22fdfdd9-5dc2-46cd-a9b2-9e829cf907ab,
    Timestamp='2021-03-03T02:24:04.6431925Z'.'''

Solution

  • The error indicates that you do not have permission to ingest data into the specific table you are trying to ingest the data to.

    Please note that a person with "user" access, cannot ingest data to a table that was not created by that person.

    Please ensure that your identity has "ingestor" permission on the specific table or for the database. You can do it through the Azure portal or using the applicable commands.