サービス プリンシパルを一覧表示する
使用する既存のサービス プリンシパルが既にある場合、この手順では、既存のサービス プリンシパルを取得する方法について説明します。
テナント内のサービス プリンシパルの一覧は、 az ad sp list を使用して取得できます。 既定では、このコマンドはテナントの最初の 100 個のサービス プリンシパルを返します。 テナントのすべてのサービス プリンシパルを取得するには、 --all
パラメーターを使用します。 このリストの取得には時間がかかる場合があるため、次のいずれかのパラメーターを使用してリストをフィルター処理することをお勧めします。
-
--display-name
は、指定された名前と一致する プレフィックス を持つサービス プリンシパルを要求します。 サービス プリンシパルの表示名は、作成時に--name
パラメーターで設定された値です。 サービス プリンシパルの作成時に--name
を設定しなかった場合、名前プレフィックスはazure-cli-
。 -
--spn
は、正確なサービス プリンシパル名の一致に対するフィルター処理を行います。 サービス プリンシパル名は常にhttps://
で始まります。--name
に使用した値が URI でない場合、この値の後に表示名https://
。 -
--show-mine
は、サインインしているユーザーによって作成されたサービス プリンシパルのみを要求します。 -
--filter
は OData フィルターを受け取り、 サーバー側の フィルター処理を実行します。 この方法は、CLI の--query
パラメーターを使用してクライアント側をフィルター処理するよりも推奨されます。 OData フィルターの詳細については、フィルターの OData 式構文に関するページを参照してください。
サービス プリンシパル オブジェクトに対して返される情報は冗長です。 サインインに必要な情報のみを取得するには、クエリ文字列 [].{id:appId, tenant:appOwnerOrganizationId}
を使用します。 現在ログインしているユーザーによって作成されたすべてのサービス プリンシパルのサインイン情報を取得する例を次に示します。
az ad sp list --show-mine --query "[].{SPname:displayName, SPid:appId, tenant:appOwnerOrganizationId}" --output table
多数のサービス プリンシパルを持つ大規模な組織で作業している場合は、次のコマンドの例を試してください。
# get service principals containing a keyword
az ad sp list --display-name mySearchWord --output table
# get service principals using an OData filter
az ad sp list --filter "displayname eq 'myExactServicePrincipalName'" --output json
# get a service principal having a certain servicePrincipalNames property value
az ad sp list --spn https://spURL.com
Von Bedeutung
ユーザーとテナントの両方を az ad sp list と az ad sp show で取得できますが、認証シークレット または 認証方法は使用できません。 Azure Key Vault の証明書のシークレットは az keyvault secret show を使用して取得できますが、既定では他のシークレットは格納されません。 認証方法またはシークレットを忘れた場合は、 サービス プリンシパルの資格情報をリセットします。
サービス プリンシパルの特性
az ad sp list
を使用してサービス プリンシパルの一覧を取得すると、スクリプトで参照できる出力プロパティが多数あります。
[
{
"accountEnabled": true,
"addIns": [],
"alternativeNames": [],
"appDescription": null,
"appDisplayName": "myServicePrincipalName",
"appId": "00000000-0000-0000-0000-000000000000",
"appOwnerOrganizationId": "00000000-0000-0000-0000-000000000000",
"appRoleAssignmentRequired": false,
"appRoles": [],
"applicationTemplateId": null,
"createdDateTime": null,
"deletedDateTime": null,
"description": null,
"disabledByMicrosoftStatus": null,
"displayName": "myServicePrincipalName",
"homepage": "https://myURL.com",
"id": "00000000-0000-0000-0000-000000000000",
"info": {
"logoUrl": null,
"marketingUrl": null,
"privacyStatementUrl": null,
"supportUrl": null,
"termsOfServiceUrl": null
},
"keyCredentials": [],
"loginUrl": null,
"logoutUrl": null,
"notes": null,
"notificationEmailAddresses": [],
"oauth2PermissionScopes": [
{
"adminConsentDescription": "my admin description",
"adminConsentDisplayName": "my admin display name",
"id": "00000000-0000-0000-0000-000000000000",
"isEnabled": true,
"type": "User",
"userConsentDescription": "my user description",
"userConsentDisplayName": "my user display name",
"value": "user_impersonation"
}
],
"passwordCredentials": [],
"preferredSingleSignOnMode": null,
"preferredTokenSigningKeyThumbprint": null,
"replyUrls": [],
"resourceSpecificApplicationPermissions": [],
"samlSingleSignOnSettings": null,
"servicePrincipalNames": [
"00000000-0000-0000-0000-000000000000",
"https://myURL.com"
],
"servicePrincipalType": "Application",
"signInAudience": null,
"tags": [
"WindowsAzureActiveDirectoryIntegratedApp"
],
"tokenEncryptionKeyId": null,
"verifiedPublisher": {
"addedDateTime": null,
"displayName": null,
"verifiedPublisherId": null
}
}
]
--query
パラメーターを使用して、サービス プリンシパルのプロパティを取得し、変数に格納します。
# Bash script
spID=$(az ad sp list --display-name myServicePrincipalName --query "[].{spID:appId}" --output tsv)
tenantID=$(az ad sp list --display-name myServicePrincipalName --query "[].{tenant:appOwnerOrganizationId}" --output tsv)
userConsentDescr=$(az ad sp list --display-name myServicePrincipalName --query "[].{ucs:oauth2PermissionScopes.userConsentDescription[0]}" --output tsv)
echo "Using appId $spID in tenant $tenantID for $userConsentDescr"
次のステップ
既存のサービス プリンシパルを取得する方法を学習したので、次の手順に進み、サービス プリンシパル ロールを管理する方法を学習します。
Azure CLI