创建可访问资源的 Azure AD 应用程序和服务主体。 我们在订阅范围添加角色分配,并获取所需的 Directory (tenant) ID、Application ID 和 Client Secret。
创建或更新群集
使用 Identity 属性创建或更新群集:
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 authClient = ConfidentialClientApplicationBuilder.Create(clientId)
.WithAuthority($"https://login.microsoftonline.com/{tenantId}")
.WithClientSecret(clientSecret)
.Build();
var result = authClient.AcquireTokenForClient(new[] { "https://management.core.windows.net/" }).ExecuteAsync().Result;
var credentials = new TokenCredentials(result.AccessToken, result.TokenType);
var kustoManagementClient = new KustoManagementClient(credentials) { SubscriptionId = subscriptionId };
var resourceGroupName = "testrg";
var clusterName = "mykustocluster";
var clusterData = new Cluster(
location: "Central US",
sku: new AzureSku("Standard_E8ads_v5", "Standard", 5),
identity: new Identity(IdentityType.SystemAssigned)
);
await kustoManagementClient.Clusters.CreateOrUpdateAsync(resourceGroupName, clusterName, clusterData);
var clusterPatch = new ClusterUpdate(identity: new Identity(IdentityType.None));
await kustoManagementClient.Clusters.UpdateAsync(resourceGroupName, clusterName, clusterPatch);
创建可访问资源的 Azure AD 应用程序和服务主体。 我们在订阅范围添加角色分配,并获取所需的 Directory (tenant) ID、Application ID 和 Client Secret。
创建或更新群集
使用 Identity 属性创建或更新群集:
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 authClient = ConfidentialClientApplicationBuilder.Create(clientId)
.WithAuthority($"https://login.microsoftonline.com/{tenantId}")
.WithClientSecret(clientSecret)
.Build();
var result = authClient.AcquireTokenForClient(new[] { "https://management.core.windows.net/" }).ExecuteAsync().Result;
var credentials = new TokenCredentials(result.AccessToken, result.TokenType);
var kustoManagementClient = new KustoManagementClient(credentials) { SubscriptionId = subscriptionId };
var resourceGroupName = "testrg";
var clusterName = "mykustocluster";
var userIdentityResourceId = $"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<identityName>";
var clusterData = new Cluster(
location: "Central US",
sku: new AzureSku("Standard_E8ads_v5", "Standard", 5),
identity: new Identity(
IdentityType.UserAssigned,
userAssignedIdentities: new Dictionary<string, IdentityUserAssignedIdentitiesValue>(1)
{
{ userIdentityResourceId, new IdentityUserAssignedIdentitiesValue() }
}
)
);
await kustoManagementClient.Clusters.CreateOrUpdateAsync(resourceGroupName, clusterName, clusterData);
var userIdentity = clusterData.Identity.UserAssignedIdentities[userIdentityResourceId];
var principalGuid = userIdentity.PrincipalId;
var clientGuid = userIdentity.ClientId;
PrincipalId 是用于 Azure AD 管理的标识的唯一标识符。
ClientId 是应用程序的新标识的唯一标识符,用于指定在运行时调用期间使用哪个标识。