Azure Data Explorer is een snelle en zeer schaalbare service voor gegevensverkenning voor telemetrische gegevens en gegevens uit logboeken. In dit artikel leert u hoe u clusterprincipals voor Azure Data Explorer toevoegt met behulp van C#, Python of een ARM-sjabloon (Azure Resource Manager).
De vereisten variƫren op basis van de methode die wordt gebruikt om de principal toe te voegen. Kies het relevante tabblad voor de gewenste methode.
Voer de volgende code uit om een clusterprincipal toe te voegen:
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
);
Instelling |
Voorgestelde waarde |
Beschrijving van veld |
tenantId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
Uw tenant-id. Ook wel bekend als map-id. |
subscriptionId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
De abonnements-id die u gebruikt voor het maken van resources. |
clientId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
De client-id van de toepassing die toegang heeft tot resources in uw tenant. |
clientSecret |
PlaceholderClientSecret |
Het clientgeheim van de toepassing die toegang heeft tot resources in uw tenant. |
resourceGroupName |
testrg |
De naam van de resourcegroep die uw cluster bevat. |
clusterName |
mykustocluster |
De naam van uw cluster. |
principalAssignmentName |
clusterPrincipalAssignment1 |
De naam van de clusterprincipalresource. |
principalId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
De principal-id, die het e-mailadres van de gebruiker, de toepassings-id of de naam van de beveiligingsgroep kan zijn. |
role |
AllDatabasesAdmin |
De rol van uw clusterprincipal, die 'AllDatabasesAdmin', 'AllDatabasesMonitor' of 'AllDatabasesViewer' kan zijn. |
tenantIdForPrincipal |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
De tenant-id van de principal. |
principalType |
App |
Het type principal, dat 'Gebruiker', 'App' of 'Groep' kan zijn |
Voer de volgende code uit om een clusterprincipal toe te voegen:
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))
Instelling |
Voorgestelde waarde |
Beschrijving van veld |
tenant_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
Uw tenant-id. Ook wel bekend als map-id. |
subscription_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
De abonnements-id die u gebruikt voor het maken van resources. |
client_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
De client-id van de toepassing die toegang heeft tot resources in uw tenant. |
client_secret |
xxxxxxxxxxxxxxxx |
Het clientgeheim van de toepassing die toegang heeft tot resources in uw tenant. |
resource_group_name |
testrg |
De naam van de resourcegroep die uw cluster bevat. |
cluster_name |
mykustocluster |
De naam van uw cluster. |
principal_assignment_name |
clusterPrincipalAssignment1 |
De naam van de principal-resource van uw cluster. |
principal_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
De principal-id, die het e-mailadres van de gebruiker, de toepassings-id of de naam van de beveiligingsgroep kan zijn. |
role |
AllDatabasesAdmin |
De rol van uw clusterprincipal, die 'AllDatabasesAdmin', 'AllDatabasesMonitor' of 'AllDatabasesViewer' kan zijn. |
tenant_id_for_principal |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
De tenant-id van de principal. |
principal_type |
App |
Het type principal, dat kan 'Gebruiker', 'App' of 'Groep' zijn |
In het volgende voorbeeld ziet u een Azure Resource Manager-sjabloon voor het toevoegen van een clusterprincipal. U kunt de sjabloon in de Azure Portal bewerken en implementeren met behulp van het formulier.
{
"$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')]"
}
}
]
}