Share via


Add cluster principals for Azure Data Explorer

Azure Data Explorer is a fast and highly scalable data exploration service for log and telemetry data. In this article, you'll learn how to add cluster principals for Azure Data Explorer by using C#, Python, or an Azure Resource Manager (ARM) template.

Prerequisites

The prerequisites vary based on the method used to add the principal. Choose the relevant tab for your preferred method.

The following list outlines the prerequisites to add a cluster principal with C#.

Add a cluster principal

Run the following code to add a cluster principal:

var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Directory (tenant) ID
var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Application ID
var clientSecret = "PlaceholderClientSecret"; //Client Secret
var subscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
var credentials = await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, clientSecret);
var kustoManagementClient = new KustoManagementClient(credentials) { SubscriptionId = subscriptionId };
var resourceGroupName = "testrg";
//The cluster that is created as part of the Prerequisites
var clusterName = "mykustocluster";
var clusterPrincipalAssignmentName = "mykustoclusterprincipalassignment";
var principalId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //User email, application ID, or security group name
var role = "AllDatabasesAdmin"; //AllDatabasesAdmin or AllDatabasesViewer
var tenantIdForPrincipal = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
var principalType = "App"; //User, App, or Group
var clusterPrincipalAssignmentData = new ClusterPrincipalAssignment(
    principalId: principalId, role: role, principalType: principalType, tenantId: tenantIdForPrincipal
);
await kustoManagementClient.ClusterPrincipalAssignments.CreateOrUpdateAsync(
    resourceGroupName, clusterName, clusterPrincipalAssignmentName, clusterPrincipalAssignmentData
);
Setting Suggested value Field description
tenantId xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx Your tenant ID. Also known as directory ID.
subscriptionId xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx The subscription ID that you use for resource creation.
clientId xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx The client ID of the application that can access resources in your tenant.
clientSecret PlaceholderClientSecret The client secret of the application that can access resources in your tenant.
resourceGroupName testrg The name of the resource group containing your cluster.
clusterName mykustocluster The name of your cluster.
principalAssignmentName clusterPrincipalAssignment1 The name of your cluster principal resource.
principalId xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx The principal ID, which can be user email, application ID, or security group name.
role AllDatabasesAdmin The role of your cluster principal, which can be 'AllDatabasesAdmin', 'AllDatabasesMonitor', or 'AllDatabasesViewer'.
tenantIdForPrincipal xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx The tenant ID of the principal.
principalType App The type of the principal, which can be 'User', 'App', or 'Group'

Next steps