Azure CLI と REST API を使用して Azure RBAC ロールを構成する

この記事では、Azure Command-Line Interface (CLI) と REST API を使用して Azure Health Data Services にアクセスするためのアクセス許可をクライアント アプリケーション (およびユーザー) に付与する方法について説明します。 この手順は、"ロールの割り当て" または Azure ロールベースのアクセス制御 (Azure RBAC ロール) と呼ばれます。 Azure Health Data Services に対して定義されているアプリケーション ロールの詳細については、「 Azure RBAC ロールの構成」を参照してください。

CLI スクリプトREST API スクリプトは、Azure Health Data Services のサンプルから表示およびダウンロードできます。

注意

ロールの割り当て操作を実行するには、ユーザー (またはクライアント アプリケーション) に RBAC アクセス許可を付与する必要があります。 Azure サブスクリプション管理者に問い合わせてください。

CLI を使用したロールの割り当て

ロール名または GUID ID を使用して、アプリケーション ロールを一覧表示できます。 スペースがある場合は、ロール名を二重引用符で囲みます。 詳細については、「Azure ロールの定義を一覧表示する」を参照してください。

az role definition list --name "FHIR Data Contributor"
az role definition list --name 5a1fc7df-4bf1-4951-a576-89034ee01acd
az role definition list --name "DICOM Data Owner"
az role definition list --name 58a3b984-7adf-4c20-983a-32417c86fbc8

Azure Health Data Services ロールの割り当て

Azure Health Data Services のロールの割り当てには、次の値が必要です。

  • アプリケーション ロール名または GUID ID。
  • ユーザーまたはクライアント アプリケーションのサービス プリンシパル ID。
  • ロールの割り当てのスコープ、つまり Azure Health Data Services サービス インスタンス。 これには、サブスクリプション、リソース グループ、ワークスペース名、FHIR または DICOM サービス名が含まれます。 スコープには絶対 URL または相対 URL を使用できます。 相対 URL の先頭に "/" が追加されていないことに注意してください。
#Azure Health Data Services role assignment
fhirrole="FHIR Data Contributor"
dicomrole="DICOM Data Owner"
clientid=xxx
subscriptionid=xxx
resourcegroupname=xxx
workspacename=xxx
fhirservicename=xxx
dicomservicename=xxx
fhirrolescope="subscriptions/$subscriptionid/resourceGroups/$resourcegroupname/providers/Microsoft.HealthcareApis/workspaces/$workspacename/fhirservices/$fhirservicename"
dicomrolescope="subscriptions/$subscriptionid/resourceGroups/$resourcegroupname/providers/Microsoft.HealthcareApis/workspaces/$workspacename/dicomservices/$dicomservicename"

#find client app service principal id
spid=$(az ad sp show --id $clientid --query objectId --output tsv)

#assign the specified role
az role assignment create --assignee-object-id $spid --assignee-principal-type ServicePrincipal --role "$fhirrole" --scope $fhirrolescope
az role assignment create --assignee-object-id $spid --assignee-principal-type ServicePrincipal --role "$dicomrole" --scope $dicomrolescope

ロールの割り当ての状態は、コマンド ライン応答またはAzure portalから確認できます。

Azure API for FHIR ロールの割り当て

Azure API for FHIR のロールの割り当ても同様に機能します。 違いは、スコープに FHIR サービスのみが含まれており、ワークスペース名は必要ないということです。

#azure api for fhir role assignment
fhirrole="FHIR Data Contributor"
clientid=xxx
subscriptionid=xxx
resourcegroupname=xxx
fhirservicename=xxx
fhirrolescope="subscriptions/$subscriptionid/resourceGroups/$resourcegroupname/providers/Microsoft.HealthcareApis/services/$fhirservicename"

#find client app service principal id
spid=$(az ad sp show --id $clientid --query objectId --output tsv)

#assign the specified role
az role assignment create --assignee-object-id $spid --assignee-principal-type ServicePrincipal --role "$fhirrole" --scope $fhirrolescope

REST API を使用したロールの割り当て

または、ロールの割り当て REST API に直接 Put 要求を送信することもできます。 詳細については、「 REST API を使用して Azure ロールを割り当てる」を参照してください。

注意

この記事の REST API スクリプトは、 REST クライアント 拡張機能に基づいています。 別の環境にいる場合は、変数を変更する必要があります。

API には、次の値が必要です。

  • 割り当て ID。トランザクションを一意に識別する GUID 値です。 Visual Studio や Visual Studio Code 拡張機能などのツールを使用して、GUID 値を取得できます。 また、 UUID ジェネレーター などのオンライン ツールを使用して取得することもできます。
  • API でサポートされている API バージョン。
  • アクセス許可を付与する Azure Health Data Services のスコープ。 これには、サブスクリプション ID、リソース グループ名、FHIR または DICOM サービス インスタンス名が含まれます。
  • "FHIR データ共同作成者" や "DICOM データ所有者" などのロールのロール定義 ID。 ロール定義 ID を一覧表示するには、 を使用 az role definition list --name "<role name>" します。
  • ユーザーまたはクライアント アプリケーションのサービス プリンシパル ID。
  • Azure Health Data Services ではなく、 https://management.azure.com/への Azure AD アクセス トークン。 アクセス トークンは、既存のツールまたは Azure CLI コマンドを使用して取得できます。 az account get-access-token --resource "https://management.azure.com/"
  • Azure Health Data Services の場合、スコープにはワークスペース名と FHIR/DICOM サービス インスタンス名が含まれます。
### Create a role assignment - Azure Health Data Services (DICOM)
@roleassignmentid=xxx
@roleapiversion=2021-04-01
@roledefinitionid=58a3b984-7adf-4c20-983a-32417c86fbc8
dicomservicename-xxx
@scope=/subscriptions/{{subscriptionid}}/resourceGroups/{{resourcegroupname}}/providers/Microsoft.HealthcareApis/workspaces/{{workspacename}}/dicomservices/{{dicomservicename}}
#get service principal id
@spid=xxx
#get access token
@token=xxx

PUT https://management.azure.com/{{scope}}/providers/Microsoft.Authorization/roleAssignments/{{roleassignmentid}}?api-version={{roleapiversion}}
Authorization: Bearer {{token}}
Content-Type: application/json
Accept: application/json

{
  "properties": {
    "roleDefinitionId": "/subscriptions/{{subscriptionid}}/providers/Microsoft.Authorization/roleDefinitions/{{roledefinitionid}}",
    "principalId": "{{spid}}"
  }
}

Azure API for FHIR の場合、スコープは FHIR サービスのみをサポートしているため、少し異なる方法で定義され、ワークスペース名は必要ありません。

### Create a role assignment - Azure API for FHIR
@roleassignmentid=xxx
@roleapiversion=2021-04-01
@roledefinitionid=5a1fc7df-4bf1-4951-a576-89034ee01acd
fhirservicename-xxx
@scope=/subscriptions/{{subscriptionid}}/resourceGroups/{{resourcegroupname}}/providers/Microsoft.HealthcareApis/services/{{fhirservicename}}
#get service principal id
@spid=xxx
#get access token
@token=xxx

PUT https://management.azure.com/{{scope}}/providers/Microsoft.Authorization/roleAssignments/{{roleassignmentid}}?api-version={{roleapiversion}}
Authorization: Bearer {{token}}
Content-Type: application/json
Accept: application/json

{
  "properties": {
    "roleDefinitionId": "/subscriptions/{{subscriptionid}}/providers/Microsoft.Authorization/roleDefinitions/{{roledefinitionid}}",
    "principalId": "{{spid}}"
  }
}

Azure Health Data Services のサービス インスタンスを一覧表示する

必要に応じて、Azure Health Data Services サービスまたは Azure API for FHIR の一覧を取得できます。 API のバージョンは、ロール割り当て REST API のバージョンではなく、Azure Health Data Services に基づいていることに注意してください。

Azure Health Data Services の場合は、サブスクリプション ID、リソース グループ名、ワークスペース名、FHIR または DICOM サービス、API バージョンを指定します。

### Get Azure Health Data Services DICOM services
@apiversion=2021-06-01
@subscriptionid=xxx
@resourcegroupname=xxx
@workspacename=xxx

GET  https://management.azure.com/subscriptions/{{subscriptionid}}/resourceGroups/{{resourcegroupname}}/providers/Microsoft.HealthcareApis/workspaces/{{workspacename}}/dicomservices?api-version={{apiversion}}
Authorization: Bearer {{token}}
Content-Type: application/json
Accept: application/json

Azure API for FHIR の場合は、サブスクリプション ID と API バージョンを指定します。

### Get a list of Azure API for FHIR services
@apiversion=2021-06-01
@subscriptionid=xxx

GET  https://management.azure.com/subscriptions/{{subscriptionid}}/providers/Microsoft.HealthcareApis/services?api-version={{apiversion}}
Authorization: Bearer {{token}}
Content-Type: application/json
Accept: application/json

クライアント アプリケーションに適切なアクセス許可を付与したので、アプリケーションで Azure Health Data Services にアクセスできます。

次の手順

この記事では、Azure CLI と REST API を使用してクライアント アプリケーションにアクセス許可を付与する方法について説明しました。 Visual Studio Code で REST クライアント拡張機能を使用して Azure Health Data Services にアクセスする方法については、以下を参照してください。

FHIR® は HL7 の登録商標であり、HL7 の許可を得て使用しています。