Azure 数据资源管理器是一项快速且高度可缩放的数据探索服务,适用于日志和遥测数据。 本文介绍如何使用 C#、Python 或 Azure 资源管理器 (ARM) 模板向 Azure 数据资源管理器添加群集主体。
运行以下代码以添加群集主体:
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 |
租户 ID。 也称为目录 ID。 |
subscriptionId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
用于创建资源的订阅 ID。 |
clientId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
可以访问租户中资源的应用程序的客户端 ID。 |
clientSecret |
PlaceholderClientSecret |
可以访问租户中资源的应用程序的客户端密码。 |
resourceGroupName |
testrg |
包含群集的资源组的名称。 |
clusterName |
mykustocluster |
群集的名称。 |
clusterPrincipalAssignmentName |
mykustoclusterprincipalassignment |
群集主体资源的名称。 |
principalId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
主体 ID,可以是用户电子邮件、应用程序 ID 或安全组名称。 |
角色 (role) |
AllDatabasesAdmin |
群集主体的角色,可以是“AllDatabasesAdmin”、“AllDatabasesMonitor”或“AllDatabasesViewer”。 |
tenantIdForPrincipal |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
主体的租户 ID。 |
principalType |
应用 |
主体的类型,可以是“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 |
租户 ID。 也称为目录 ID。 |
subscription_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
用于创建资源的订阅 ID。 |
client_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
可以访问租户中资源的应用程序的客户端 ID。 |
client_secret |
xxxxxxxxxxxxxx |
可以访问租户中资源的应用程序的客户端密码。 |
resource_group_name |
testrg |
包含群集的资源组的名称。 |
cluster_name |
mykustocluster |
群集的名称。 |
principal_assignment_name |
clusterPrincipalAssignment1 |
群集主体资源的名称。 |
principal_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
主体 ID,可以是用户电子邮件、应用程序 ID 或安全组名称。 |
角色 (role) |
AllDatabasesAdmin |
群集主体的角色,可以是“AllDatabasesAdmin”、“AllDatabasesMonitor”或“AllDatabasesViewer”。 |
tenant_id_for_principal |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
主体的租户 ID。 |
principal_type |
应用 |
主体的类型,可以是“User”、“App”或“Group” |
以下示例演示了用于添加群集主体的 Azure 资源管理器模板。 可以使用此窗体在 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')]"
}
}
]
}