次の手順では、割り当てられたユーザー割り当てマネージド ID を持つ Azure SQL Database の新しい論理サーバーと新しいデータベースを作成するプロセスの概要を説明します。
Azure portal の [SQL デプロイ オプションの選択] ページを参照します。
まだ Azure portal にサインインしていない場合は、求められたらサインインします。
[SQL データベース] で、 [リソースの種類] を [単一データベース] に設定し、 [作成] を選択します。
[SQL データベースの作成] フォームの [基本] タブにある [プロジェクトの詳細] で、目的の Azure [サブスクリプション] を選択します。
[リソース グループ] の [新規作成] を選択し、リソース グループの名前を入力し、 [OK] を選択します。
[データベース名] に、目的のデータベース名を入力します。
[サーバー] で、 [新規作成] を選択し、 [新しいサーバー] フォームに次の値を入力します。
-
[サーバー名] : 一意のサーバー名を入力します。 サーバー名は、サブスクリプション内で一意ではなく、Azure のすべてのサーバーに対してグローバルに一意である必要があります。
-
[サーバー管理者ログイン]: 管理者のログイン名を入力します (例:
azureuser
)。
-
パスワード: パスワード要件を満たすパスワードを入力し、[パスワードの確認入力] フィールドにもう一度入力します。
-
[場所] : ドロップダウン リストから場所を選択します
ページの下部にある [Next: Networking](次へ: ネットワーク) を選択します。
[ネットワーク] タブの [接続方法] で、 [パブリック エンドポイント] を選択します。
[ファイアウォール規則] で、 [現在のクライアント IP アドレスを追加する] を [はい] に設定します。
[Azure サービスおよびリソースにこのサーバー グループへのアクセスを許可する] を [いいえ] に設定したままにします。
ページの下部で [次へ: セキュリティ] を選択します。
[セキュリティ] タブの [ID] で、[ID の構成] を選択します。
[ID]ウィンドウで、[ユーザー割り当てマネージド ID]の[追加]を選択します。 目的のサブスクリプションを選択し、[ユーザー割り当てマネージド ID] で、選択したサブスクリプションから目的のユーザー割り当てマネージド ID を選択します。 次に [選択] ボタンを選択します。
[プライマリ ID] で、前の手順で選択したのと同じユーザー割り当てマネージド ID を選択します。
注
システム割り当てマネージド ID がプライマリ ID の場合は、[プライマリ ID] フィールドが空である必要があります。
[適用] を選択します
ページの下部にある [確認と作成] を選択します
[確認と作成] ページで、確認後、 [作成] を選択します。
Azure CLI コマンド az sql server create
は、新しい論理サーバーをプロビジョニングするために使用されます。 次のコマンドは、ユーザー割り当てマネージド ID を使用して新しいサーバーをプロビジョニングします。 この例では、Microsoft Entra 専用認証も有効にし、サーバーの Microsoft Entra 管理者を設定します。
サーバー SQL 管理者ログインが自動的に作成され、パスワードはランダムなパスワードに設定されます。 このサーバーを作成すると SQL 認証接続が無効になるため、SQL 管理者ログインは使用されません。
サーバー Microsoft Entra 管理者は、<AzureADAccount>
に設定したアカウントになり、サーバーの管理に使用できます。
この例では次の値を置き換えます。
-
<subscriptionId>
: サブスクリプション ID は Azure portal で確認できます
-
<ResourceGroupName>
: 論理サーバーのリソース グループの名前
-
<managedIdentity>
: ユーザー割り当てマネージド ID。 プライマリ ID として使用することもできます。
-
<primaryIdentity>
: サーバー ID として使用するプライマリ ID
-
<AzureADAccount>
: Microsoft Entra ユーザーまたはグループを指定できます。 たとえば、DummyLogin
のように指定します。
-
<AzureADAccountSID>
: ユーザー アカウントの Microsoft Entra オブジェクト ID
-
<ServerName>
: 一意の論理サーバー名を使用します
-
<Location>
: サーバーの場所 (westus
、centralus
など)
subscription_id=<subscriptionId>
resource_group=<ResourceGroupName>
managed_identity=<managedIdentity>
primary_identity=<primaryIdentity>
azure_ad_account=<AzureADAccount>
azure_ad_account_sid=<AzureADAccountSID>
server_name=<ServerName>
___location=<Location>
az sql server create \
--assign-identity \
--identity-type UserAssigned \
--user-assigned-identity-id /subscriptions/$subscription_id/resourceGroups/$resource_group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$managed_identity \
--primary-user-assigned-identity-id /subscriptions/$subscription_id/resourceGroups/$resource_group/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$primary_identity \
--enable-ad-only-auth \
--external-admin-principal-type User \
--external-admin-name $azure_ad_account \
--external-admin-sid $azure_ad_account_sid \
-g $resource_group \
-n $server_name \
-l $___location
詳細については、「az sql server create」を参照してください。
注
上記の例では、ユーザー割り当てマネージド ID のみを使用してサーバーをプロビジョニングします。 両方の種類のマネージド ID をサーバーで作成する場合は、--identity-type
を UserAssigned,SystemAssigned
に設定できます。
作成後にサーバーの状態を確認するには、次のコマンドを参照してください。
az sql server show --name <ServerName> --resource-group <ResourceGroupName> --expand-ad-admin
PowerShell コマンド New-AzSqlServer
は、新しい Azure SQL 論理サーバーをプロビジョニングするために使用されます。 次のコマンドは、ユーザー割り当てマネージド ID を使用して新しいサーバーをプロビジョニングします。 この例では、Microsoft Entra 専用認証も有効にし、サーバーの Microsoft Entra 管理者を設定します。
サーバー SQL 管理者ログインが自動的に作成され、パスワードはランダムなパスワードに設定されます。 このサーバーを作成すると SQL 認証接続が無効になるため、SQL 管理者ログインは使用されません。
サーバー Microsoft Entra 管理者は、<AzureADAccount>
に設定したアカウントになり、サーバーの管理に使用できます。
この例では次の値を置き換えます。
-
<ResourceGroupName>
: 論理サーバーのリソース グループの名前
-
<Location>
: サーバーの場所 (West US
、Central US
など)
-
<ServerName>
: 一意の論理サーバー名を使用します
-
<subscriptionId>
: サブスクリプション ID は Azure portal で確認できます
-
<managedIdentity>
: ユーザー割り当てマネージド ID。 プライマリ ID として使用することもできます
-
<primaryIdentity>
: サーバー ID として使用するプライマリ ID
-
<AzureADAccount>
: Microsoft Entra ユーザーまたはグループを指定できます。 たとえば、DummyLogin
のように指定します。
$server = @{
ResourceGroupName = "<ResourceGroupName>"
Location = "<Location>"
ServerName = "<ServerName>"
ServerVersion = "12.0"
AssignIdentity = $true
IdentityType = "UserAssigned"
UserAssignedIdentityId = "/subscriptions/<subscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managedIdentity>"
PrimaryUserAssignedIdentityId = "/subscriptions/<subscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<primaryIdentity>"
ExternalAdminName = "<AzureADAccount>"
EnableActiveDirectoryOnlyAuthentication = $true
}
New-AzSqlServer @server
詳細については、「New-AzSqlServer」を参照してください。
注
上記の例では、ユーザー割り当てマネージド ID のみを使用してサーバーをプロビジョニングします。 両方の種類のマネージド ID をサーバーで作成する場合は、-IdentityType
を "UserAssigned,SystemAssigned"
に設定できます。
作成後にサーバーの状態を確認するには、次のコマンドを参照してください。
Get-AzSqlServer -ResourceGroupName "<ResourceGroupName>" -ServerName "<ServerName>" -ExpandActiveDirectoryAdministrator
「Servers - Create Or Update」の REST API を使って、ユーザー割り当てマネージド ID を持つ論理サーバーを作成できます。
次のスクリプトでは、論理サーバーをプロビジョニングし、Microsoft Entra 管理者を <AzureADAccount>
として設定して、Microsoft Entra 専用認証を有効にします。 サーバー SQL 管理者ログインも自動的に作成され、パスワードはランダムなパスワードに設定されます。 このプロビジョニングでは SQL 認証接続が無効になるため、SQL 管理者ログインは使用されません。
Microsoft Entra 管理者 <AzureADAccount>
は、プロビジョニングが完了したときにサーバーを管理するために使用できます。
この例では次の値を置き換えます。
-
<tenantId>
: Azure portal に移動し、Microsoft Entra ID リソースに移動すると確認できます。
[概要] ペインに [テナント ID] が表示されます
-
<subscriptionId>
: サブスクリプション ID は Azure portal で確認できます
-
<ServerName>
: 一意の論理サーバー名を使用します
-
<ResourceGroupName>
: 論理サーバーのリソース グループの名前
-
<AzureADAccount>
: Microsoft Entra ユーザーまたはグループを指定できます。 たとえば、DummyLogin
のように指定します。
-
<Location>
: サーバーの場所 (westus2
、centralus
など)
-
<objectId>
: Azure portal に移動し、Microsoft Entra ID リソースに移動すると確認できます。
[ユーザー] ウィンドウで Microsoft Entra ユーザーを検索し、オブジェクト IDを特定します
-
<managedIdentity>
: ユーザー割り当てマネージド ID。 プライマリ ID として使用することもできます
-
<primaryIdentity>
: サーバー ID として使用するプライマリ ID
Import-Module Azure
Import-Module MSAL.PS
$tenantId = '<tenantId>'
$clientId = '1950a258-227b-4e31-a9cf-717495945fc2' # Static Microsoft client ID used for getting a token
$subscriptionId = '<subscriptionId>'
$uri = "urn:ietf:wg:oauth:2.0:oob"
$authUrl = "https://login.windows.net/$tenantId"
$serverName = "<ServerName>"
$resourceGroupName = "<ResourceGroupName>"
Login-AzAccount -tenantId $tenantId
# login as a user with SQL Server Contributor role or higher
# Get a token
$result = Get-MsalToken -RedirectUri $uri -ClientId $clientId -TenantId $tenantId -Scopes "https://management.core.windows.net/.default"
#Authentication header
$authHeader = @{
'Content-Type'='application\json; '
'Authorization'=$result.CreateAuthorizationHeader()
}
# Enable Azure AD-only auth and sets a user-managed identity as the server identity
# No server admin is specified, and only Azure AD admin and Azure AD-only authentication is set to true
# Server admin (login and password) is generated by the system
# The sid is the Azure AD Object ID for the user
# Replace all values in a <>
$body = '{
"___location": "<Location>",
"identity": {"type" : "UserAssigned", "UserAssignedIdentities" : {"/subscriptions/<subscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managedIdentity>" : {}}},
"properties": { "PrimaryUserAssignedIdentityId":"/subscriptions/<subscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<primaryIdentity>","administrators":{ "login":"<AzureADAccount>", "sid":"<objectId>", "tenantId":"<tenantId>", "principalType":"User", "azureADOnlyAuthentication":true }
}
}'
# Provision the server
Invoke-RestMethod -Uri https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Sql/servers/$serverName/?api-version=2020-11-01-preview -Method PUT -Headers $authHeader -Body $body -ContentType "application/json"
注
上記の例では、ユーザー割り当てマネージド ID のみを使用してサーバーをプロビジョニングします。 両方の種類のマネージド ID をサーバーで作成する場合は、"type"
を "UserAssigned,SystemAssigned"
に設定できます。
サーバーの状態を確認するには、次のスクリプトを使用します。
$uri = 'https://management.azure.com/subscriptions/'+$subscriptionId+'/resourceGroups/'+$resourceGroupName+'/providers/Microsoft.Sql/servers/'+$serverName+'?api-version=2020-11-01-preview&$expand=administrators/activedirectory'
$response=Invoke-WebRequest -Uri $uri -Method PUT -Headers $authHeader -Body $body -ContentType "application/json"
$response.statuscode
$response.content
ユーザー割り当てマネージド ID を使用して Azure SQL Database 論理サーバーを作成する ARM テンプレートの例を次に示します。 このテンプレートでは、サーバーの Microsoft Entra 管理者セットも追加され、Microsoft Entra 専用認証が有効になりますが、これはテンプレートの例から削除できます。
ARM テンプレートの詳細については、「Azure SQL データベース用 Azure Resource Manager テンプレート」を参照してください。
Azure portal のカスタム デプロイを使用し、エディターで独自のテンプレートを作成します。 次に、例に貼り付けたら、構成を保存します。
ユーザー割り当てマネージド ID のリソース ID を取得するには、Azure portal でマネージド ID を検索します。 マネージド ID を見つけて、[プロパティ] に移動します。 UMI リソース ID の例は /subscriptions/<subscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managedIdentity>
のようになります。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.1",
"parameters": {
"server": {
"type": "string",
"defaultValue": "[uniqueString('sql', resourceGroup().id)]",
"metadata": {
"description": "The name of the logical server."
}
},
"___location": {
"type": "string",
"defaultValue": "[resourceGroup().___location]",
"metadata": {
"description": "Location for all resources."
}
},
"aad_admin_name": {
"type": "String",
"metadata": {
"description": "The name of the Azure AD admin for the SQL server."
}
},
"aad_admin_objectid": {
"type": "String",
"metadata": {
"description": "The Object ID of the Azure AD admin."
}
},
"aad_admin_tenantid": {
"type": "String",
"defaultValue": "[subscription().tenantId]",
"metadata": {
"description": "The Tenant ID of the Azure Active Directory"
}
},
"aad_admin_type": {
"defaultValue": "User",
"allowedValues": [
"User",
"Group",
"Application"
],
"type": "String"
},
"aad_only_auth": {
"defaultValue": true,
"type": "Bool"
},
"user_identity_resource_id": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "The Resource ID of the user-assigned managed identity, in the form of /subscriptions/<subscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managedIdentity>."
}
},
"AdminLogin": {
"minLength": 1,
"type": "String"
},
"AdminLoginPassword": {
"type": "SecureString"
}
},
"resources": [
{
"type": "Microsoft.Sql/servers",
"apiVersion": "2020-11-01-preview",
"name": "[parameters('server')]",
"___location": "[parameters('___location')]",
"identity": {
"type": "UserAssigned",
"UserAssignedIdentities": {
"[parameters('user_identity_resource_id')]": {}
}
},
"properties": {
"administratorLogin": "[parameters('AdminLogin')]",
"administratorLoginPassword": "[parameters('AdminLoginPassword')]",
"PrimaryUserAssignedIdentityId": "[parameters('user_identity_resource_id')]",
"administrators": {
"login": "[parameters('aad_admin_name')]",
"sid": "[parameters('aad_admin_objectid')]",
"tenantId": "[parameters('aad_admin_tenantid')]",
"principalType": "[parameters('aad_admin_type')]",
"azureADOnlyAuthentication": "[parameters('aad_only_auth')]"
}
}
}
]
}