Azure Data Explorer är en snabb och mycket skalbar datautforskningstjänst för logg- och telemetridata. I den här artikeln får du lära dig hur du lägger till klusterhuvudkonton för Azure Data Explorer med hjälp av C#, Python eller en ARM-mall (Azure Resource Manager).
Kraven varierar beroende på vilken metod som används för att lägga till huvudkontot. Välj relevant flik för önskad metod.
Kör följande kod för att lägga till ett klusterhuvudnamn:
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
);
Inställning |
Föreslaget värde |
Fältbeskrivning |
tenantId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
Ditt klientorganisations-ID. Kallas även katalog-ID. |
subscriptionId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
Det prenumerations-ID som du använder för att skapa resurser. |
ClientID |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
Klient-ID för programmet som kan komma åt resurser i din klientorganisation. |
clientSecret |
PlatshållareClientSecret |
Klienthemligheten för programmet som kan komma åt resurser i din klientorganisation. |
resourceGroupName |
testrg |
Namnet på resursgruppen som innehåller klustret. |
clusterName |
mykustocluster |
Namnet på klustret. |
principalAssignmentName |
clusterPrincipalAssignment1 |
Namnet på resursen för klustrets huvudnamn. |
principalId |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
Huvud-ID:t, som kan vara användarens e-post, program-ID eller säkerhetsgruppsnamn. |
roll |
AllDatabasesAdmin |
Rollen för klustrets huvudnamn, som kan vara "AllDatabasesAdmin", "AllDatabasesMonitor" eller "AllDatabasesViewer". |
tenantIdForPrincipal |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
Klientorganisations-ID för huvudkontot. |
principalType |
App |
Typen av huvudnamn, som kan vara "Användare", "App" eller "Grupp" |
Kör följande kod för att lägga till ett klusterhuvudnamn:
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))
Inställning |
Föreslaget värde |
Fältbeskrivning |
tenant_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
Ditt klientorganisations-ID. Kallas även katalog-ID. |
subscription_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
Det prenumerations-ID som du använder för att skapa resurser. |
client_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
Klient-ID för programmet som kan komma åt resurser i din klientorganisation. |
client_secret |
xxxxxxxxxxxxxx |
Klienthemligheten för programmet som kan komma åt resurser i din klientorganisation. |
resource_group_name |
testrg |
Namnet på resursgruppen som innehåller klustret. |
cluster_name |
mykustocluster |
Namnet på klustret. |
principal_assignment_name |
clusterPrincipalAssignment1 |
Namnet på resursen för klustrets huvudnamn. |
principal_id |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
Huvudkonto-ID, som kan vara användarens e-post, program-ID eller säkerhetsgruppsnamn. |
roll |
AllDatabasesAdmin |
Rollen för klustrets huvudnamn, som kan vara "AllDatabasesAdmin", "AllDatabasesMonitor" eller "AllDatabasesViewer". |
tenant_id_for_principal |
xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx |
Klientorganisations-ID för huvudkontot. |
principal_type |
App |
Typ av huvudkonto, som kan vara "Användare", "App" eller "Grupp" |
I följande exempel visas en Azure Resource Manager-mall för att lägga till ett klusterhuvudnamn. Du kan redigera och distribuera mallen i Azure Portal med hjälp av formuläret .
{
"$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')]"
}
}
]
}