Azure 資料總管是一項快速又可高度調整的資料探索服務,可用於處理記錄和遙測資料。 在本文中,您將瞭解如何使用 C#、Python 或 Azure Resource Manager (ARM) 範本,為 Azure Data Explorer新增叢集主體。
執行下列程式碼以新增叢集主體:
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 = new ClientSecretCredential(tenantId, clientId, clientSecret);
var resourceManagementClient = new ArmClient(credentials, subscriptionId);
var resourceGroupName = "testrg";
//The cluster that is created as part of the Prerequisites
var clusterName = "mykustocluster";
var subscription = await resourceManagementClient.GetDefaultSubscriptionAsync();
var resourceGroup = (await subscription.GetResourceGroupAsync(resourceGroupName)).Value;
var cluster = (await resourceGroup.GetKustoClusterAsync(clusterName)).Value;
var clusterPrincipalAssignments = cluster.GetKustoClusterPrincipalAssignments();
var clusterPrincipalAssignmentName = "mykustoclusterprincipalassignment";
var principalId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //User email, application ID, or security group name
var role = KustoClusterPrincipalRole.AllDatabasesAdmin; //AllDatabasesAdmin or AllDatabasesViewer
var tenantIdForPrincipal = new Guid("xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx");
var principalType = KustoPrincipalAssignmentType.App; //User, App, or Group
var clusterPrincipalAssignmentData = new KustoClusterPrincipalAssignmentData
{
ClusterPrincipalId = principalId, Role = role, PrincipalType = principalType, TenantId = tenantIdForPrincipal
};
await clusterPrincipalAssignments.CreateOrUpdateAsync(
WaitUntil.Completed, clusterPrincipalAssignmentName, clusterPrincipalAssignmentData
);
設定 |
建議的值 |
欄位描述 |
tenantId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
您的租用戶識別碼。 也稱為目錄識別碼。 |
subscriptionId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
您用來建立資源的訂用帳戶識別碼。 |
clientId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
應用程式的用戶端識別碼,可存取您租用戶中的資源。 |
clientSecret |
PlaceholderClientSecret |
應用程式的用戶端密碼,可以存取您租用戶中的資源。 |
resourceGroupName |
testrg |
包含叢集的資源群組名稱。 |
clusterName |
mykustocluster |
您叢集的名稱。 |
clusterPrincipalAssignmentName |
mykustoclusterprincipalassignment |
叢集主體資源的名稱。 |
principalId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
主體識別碼,可以是使用者電子郵件、應用程式識別碼或安全性群組名稱。 |
角色 (role) |
AllDatabasesAdmin |
叢集主體的角色,可以是 'AllDatabasesAdmin'、'AllDatabasesMonitor'或 'AllDatabasesViewer'。 |
tenantIdForPrincipal |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
主體的租使用者識別碼。 |
principalType |
App |
主體的類型,可以是 'User'、'App' 或 'Group' |
執行下列程式碼以新增叢集主體:
from azure.mgmt.kusto import KustoManagementClient
from azure.mgmt.kusto.models import ClusterPrincipalAssignment
from azure.common.credentials import ServicePrincipalCredentials
#Directory (tenant) ID
tenant_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
#Application ID
client_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
#Client Secret
client_secret = "xxxxxxxxxxxxxx"
subscription_id = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"
credentials = ServicePrincipalCredentials(
client_id=client_id,
secret=client_secret,
tenant=tenant_id
)
kusto_management_client = KustoManagementClient(credentials, subscription_id)
resource_group_name = "testrg"
#The cluster that is created as part of the Prerequisites
cluster_name = "mykustocluster"
principal_assignment_name = "clusterPrincipalAssignment1"
#User email, application ID, or security group name
principal_id = "xxxxxxxx"
#AllDatabasesAdmin, AllDatabasesMonitor or AllDatabasesViewer
role = "AllDatabasesAdmin"
tenant_id_for_principal = tenantId
#User, App, or Group
principal_type = "App"
#Returns an instance of LROPoller, check https://learn.microsoft.com/python/api/msrest/msrest.polling.lropoller?view=azure-python
poller = kusto_management_client.cluster_principal_assignments.create_or_update(resource_group_name=resource_group_name, cluster_name=cluster_name, principal_assignment_name= principal_assignment_name, parameters=ClusterPrincipalAssignment(principal_id=principal_id, role=role, tenant_id=tenant_id_for_principal, principal_type=principal_type))
設定 |
建議的值 |
欄位描述 |
tenant_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
您的租用戶識別碼。 也稱為目錄識別碼。 |
subscription_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
您用來建立資源的訂用帳戶識別碼。 |
client_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
應用程式的用戶端識別碼,可存取您租用戶中的資源。 |
client_secret |
xxxxxxxxxxxxxx |
應用程式的用戶端密碼,可以存取您租用戶中的資源。 |
resource_group_name |
testrg |
包含叢集的資源群組名稱。 |
cluster_name |
mykustocluster |
您叢集的名稱。 |
principal_assignment_name |
clusterPrincipalAssignment1 |
叢集主體資源的名稱。 |
principal_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
主體識別碼,可以是使用者電子郵件、應用程式識別碼或安全性群組名稱。 |
角色 (role) |
AllDatabasesAdmin |
叢集主體的角色,可以是 'AllDatabasesAdmin'、'AllDatabasesMonitor'或 'AllDatabasesViewer'。 |
tenant_id_for_principal |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
主體的租使用者識別碼。 |
principal_type |
App |
主體的類型,可以是 'User'、'App' 或 'Group' |
下列範例顯示用來新增叢集主體的 Azure Resource Manager 範本。 您可以使用表單,在 Azure 入口網站中編輯和部署範本。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"clusterPrincipalAssignmentName": {
"type": "string",
"defaultValue": "principalAssignment1",
"metadata": {
"description": "Specifies the name of the principal assignment"
}
},
"clusterName": {
"type": "string",
"defaultValue": "mykustocluster",
"metadata": {
"description": "Specifies the name of the cluster"
}
},
"principalIdForCluster": {
"type": "string",
"metadata": {
"description": "Specifies the principal id. It can be user email, application (client) ID, security group name"
}
},
"roleForClusterPrincipal": {
"type": "string",
"defaultValue": "AllDatabasesViewer",
"metadata": {
"description": "Specifies the cluster principal role. It can be 'AllDatabasesAdmin', 'AllDatabasesMonitor' or 'AllDatabasesViewer'"
}
},
"tenantIdForClusterPrincipal": {
"type": "string",
"metadata": {
"description": "Specifies the tenantId of the principal"
}
},
"principalTypeForCluster": {
"type": "string",
"defaultValue": "User",
"metadata": {
"description": "Specifies the principal type. It can be 'User', 'App', 'Group'"
}
}
},
"variables": {
},
"resources": [{
"type": "Microsoft.Kusto/Clusters/principalAssignments",
"apiVersion": "2019-11-09",
"name": "[concat(parameters('clusterName'), '/', parameters('clusterPrincipalAssignmentName'))]",
"properties": {
"principalId": "[parameters('principalIdForCluster')]",
"role": "[parameters('roleForClusterPrincipal')]",
"tenantId": "[parameters('tenantIdForClusterPrincipal')]",
"principalType": "[parameters('principalTypeForCluster')]"
}
}
]
}