建立可存取資源的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 Resource Manager 範本移除系統指派的身分識別
執行下列命令以移除系統指派的身分識別:
{
"identity": {
"type": "None"
}
}
注意
如果叢集同時擁有系統指派和使用者指派的身分識別,在移除系統指派的身分識別之後, type 屬性將會是 UserAssigned
建立可存取資源的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;
對於 Azure AD 管理所用的身分識別,PrincipalId 是唯一識別碼。
ClientId是應用程式新身分識別的唯一識別碼,用來指定要在執行時間呼叫期間使用的身分識別。