-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assign FHIR and DICOM roles automatically (#3104)
* Assign fhir and dicom roles automatically * Add external provider * CR changes
- Loading branch information
Showing
7 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
templates/workspace_services/health-services/terraform/get_app_role_members.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
eval "$(jq -r '@sh "AUTH_CLIENT_ID=\(.auth_client_id) AUTH_CLIENT_SECRET=\(.auth_client_secret) AUTH_TENANT_ID=\(.auth_tenant_id) WORSKPACE_CLIENT_ID=\(.workspace_client_id)"')" | ||
|
||
az login --allow-no-subscriptions --service-principal --username "$AUTH_CLIENT_ID" --password "$AUTH_CLIENT_SECRET" --tenant "$AUTH_TENANT_ID" > /dev/null | ||
|
||
# get the service principal object id | ||
sp=$(az rest --method GET --uri "https://graph.microsoft.com/v1.0/serviceprincipals?\$filter=appid eq '${WORSKPACE_CLIENT_ID}'" -o json) | ||
spId=$(echo "$sp" | jq -r '.value[0].id') | ||
|
||
# filter to the Workspace Researcher Role | ||
workspaceResearcherRoleId=$(echo "$sp" | jq -r '.value[0].appRoles[] | select(.value == "WorkspaceResearcher") | .id') | ||
principals=$(az rest --method GET --uri "https://graph.microsoft.com/v1.0/serviceprincipals/${spId}/appRoleAssignedTo" -o json | jq -r --arg workspaceResearcherRoleId "${workspaceResearcherRoleId}" '.value[] | select(.appRoleId == $workspaceResearcherRoleId) | .principalId') | ||
|
||
jq -n --arg principals "$principals" '{"principals":$principals}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
templates/workspace_services/health-services/terraform/roles.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
data "azurerm_key_vault_secret" "workspace_client_id" { | ||
name = "workspace-client-id" | ||
key_vault_id = data.azurerm_key_vault.ws.id | ||
} | ||
|
||
data "external" "app_role_members" { | ||
program = ["bash", "${path.module}/get_app_role_members.sh"] | ||
|
||
query = { | ||
auth_client_id = var.auth_client_id | ||
auth_client_secret = var.auth_client_secret | ||
auth_tenant_id = var.auth_tenant_id | ||
workspace_client_id = data.azurerm_key_vault_secret.workspace_client_id.value | ||
} | ||
} | ||
|
||
data "azurerm_role_definition" "azure_fhir_contributor" { | ||
name = "FHIR Data Contributor" | ||
} | ||
|
||
data "azurerm_role_definition" "azure_dicom_data_owner" { | ||
name = "DICOM Data Owner" | ||
} | ||
|
||
resource "azurerm_role_assignment" "app_role_members_fhir_contributor" { | ||
for_each = !var.deploy_fhir || (data.external.app_role_members.result.principals == "") ? [] : toset(split("\n", data.external.app_role_members.result.principals)) | ||
scope = azurerm_healthcare_fhir_service.fhir[0].id | ||
role_definition_id = data.azurerm_role_definition.azure_fhir_contributor.id | ||
principal_id = each.value | ||
} | ||
|
||
resource "azurerm_role_assignment" "app_role_members_dicom_data_owner" { | ||
for_each = !var.deploy_dicom || (data.external.app_role_members.result.principals == "") ? [] : toset(split("\n", data.external.app_role_members.result.principals)) | ||
scope = azurerm_healthcare_dicom_service.dicom[0].id | ||
role_definition_id = data.azurerm_role_definition.azure_dicom_data_owner.id | ||
principal_id = each.value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters