-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Role definitions during deployment (#136)
* Work on AAD roles deployment scripts * Moved Set-FhirServerApiApplicationRoles * Moved Set-FhirServerClientAppRoleAssignments to FhirServer module * Created Set-FhirServerUserAppRoleAssignments.ps1 for adding users to roles * Adjusted calls in FhirServerRelease to use new functions in FhirServer and updated deployment documentation * Fixed bug and added instructions for specifying roles * Check for role assignment when New-AzureADServiceAppRoleAssignment throws * Fixed multiple incompatibilities in Add-AadTestAuthEnvironment.ps1, fixed a few bugs * Updated documentation based on PR feedback * Additional PR feedback
- Loading branch information
Showing
10 changed files
with
269 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,15 +27,29 @@ Register an AAD Application for the FHIR server API: | |
|
||
```PowerShell | ||
$fhirServiceName = "myfhirservice" | ||
$apiAppReg = New-FhirServerApiApplicationRegistration -FhirServiceName $fhirServiceName | ||
$apiAppReg = New-FhirServerApiApplicationRegistration -FhirServiceName $fhirServiceName -AppRoles admin,nurse,patient | ||
``` | ||
|
||
The `-AppRoles` defines a set of roles that can be granted to users or service principals (service accounts) interacting with the FHIR server API. Configuration settings for the FHIR server will determine which privileges (Read, Write, etc.) that are assosiated with each role. | ||
|
||
To access the FHIR server from a client, you will also need a client AAD Application registration with a client secret. This client AAD Application registration will need to have appropriate application permissions and reply URLs configured. Here is how to register a client AAD Application for use with [Postman](https://getpostman.com): | ||
|
||
```PowerShell | ||
$clientAppReg = New-FhirServerClientApplicationRegistration -ApiAppId $apiAppReg.AppId -DisplayName "myfhirclient" -ReplyUrl "https://www.getpostman.com/oauth2/callback" | ||
``` | ||
|
||
If you would like a client application to be able to act as a service account, you can assign roles to the client application: | ||
|
||
```PowerShell | ||
Set-FhirServerClientAppRoleAssignments -AppId $clientAppReg.AppId -ApiAppId $apiAppReg.AppId -AppRoles admin,patient | ||
``` | ||
|
||
To assign roles to a specific user in Azure Active Directory: | ||
|
||
```PowerShell | ||
Set-FhirServerUserAppRoleAssignments -UserPrincipalName [email protected] -ApiAppId $apiAppReg.AppId -AppRoles admin,nurse | ||
``` | ||
|
||
## Deploying the FHIR Server Template | ||
|
||
To deploy the backend Cosmos DB, Azure Web App, and FHIR server code, use the buttons below to deploy through the Azure Portal. If you would like to protect the FHIR API with token authorization, you will need to supply application registration details as described above. | ||
|
@@ -71,6 +85,8 @@ New-AzureRmResourceGroupDeployment ` | |
-ResourceGroupName $rg.ResourceGroupName -serviceName $fhirServiceName | ||
``` | ||
|
||
The default deployment will have a single role (`admin`) defined. To define more roles when deploying the server, see [details on specifying roles](Roles.md). | ||
|
||
You can use [Postman to test the FHIR server](PostmanTesting.md). | ||
|
||
## Clean up Azure AD App Registrations | ||
|
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,96 @@ | ||
# Roles in Microsoft FHIR Server for Azure | ||
|
||
The FHIR server uses a role based access control system. The privileges (Read, Write, etc.) assigned to specific roles are defined with an array structure: | ||
|
||
```json | ||
[ | ||
{ | ||
"name": "clinician", | ||
"resourcePermissions": [ | ||
{ | ||
"actions": [ | ||
"Read", | ||
"Write" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "researcher", | ||
"resourcePermissions": [ | ||
{ | ||
"actions": [ | ||
"Read" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "admin", | ||
"resourcePermissions": [ | ||
{ | ||
"actions": [ | ||
"Read", | ||
"Write", | ||
"HardDelete" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
``` | ||
|
||
This structure is passed to the FHIR server at startup and enforced using the `roles` claim in the JWT access token presented when cusuming the FHIR server API. | ||
|
||
When deploying the FHIR server into Azure using the provided [resource manager template](../samples/templates/default-azuredeploy.json) the array of roles can be passed in the `additionalFhirServerConfigProperties` parameter, which will add the roles to the [App Settings](https://docs.microsoft.com/en-us/azure/app-service/web-sites-configure) of the front end [Web App](https://azure.microsoft.com/en-us/services/app-service/web/) running the server. | ||
|
||
In the app settings the nested array structure must be flattened and added to the `FhirServer:Security:Authorization:RoleConfiguration:Roles` section of the configuration. Specifically, a roles array like: | ||
|
||
```json | ||
[ | ||
{ | ||
"name": "admin", | ||
"resourcePermissions": [ | ||
{ | ||
"actions": [ | ||
"Read", | ||
"Write", | ||
"HardDelete" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
``` | ||
|
||
would become: | ||
|
||
```json | ||
{ | ||
"FhirServer:Security:Authorization:RoleConfiguration:Roles:0:name": "admin", | ||
"FhirServer:Security:Authorization:RoleConfiguration:Roles:0:resourcePermissions:0:actions:0": "Read", | ||
"FhirServer:Security:Authorization:RoleConfiguration:Roles:0:resourcePermissions:0:actions:1": "Write", | ||
"FhirServer:Security:Authorization:RoleConfiguration:Roles:0:resourcePermissions:0:actions:2": "HardDelete" | ||
} | ||
``` | ||
|
||
To avoid having to maintain the role definitions in the less readable flattened form, you can use a script to convert the JSON form to the flattened table. There is a an example in the [ConvertTo-FlattenedConfigurationHashtable.ps1 script](../release/ConvertTo-FlattenedConfigurationHashtable.ps1). To use it: | ||
|
||
```PowerShell | ||
$roles = ConvertFrom-Json (Get-Content -Raw .\roles.json) | ||
$flattenedRoles = .\release\scripts\PowerShell\ConvertTo-FlattenedConfigurationHashtable.ps1 -InputObject $roles -PathPrefix "FhirServer:Security:Authorization:RoleConfiguration:Roles" | ||
``` | ||
|
||
To pass the array of roles in when deploying the FHIR server (see [Deployment Instructions](DefaultDeployment.md) for details): | ||
|
||
```PowerShell | ||
$rg = New-AzureRmResourceGroup -Name "RG-NAME" -Location westus2 | ||
New-AzureRmResourceGroupDeployment ` | ||
-TemplateUri "https://raw.githubusercontent.com/Microsoft/fhir-server/master/samples/templates/default-azuredeploy.json" ` | ||
-ResourceGroupName $rg.ResourceGroupName ` | ||
-serviceName $fhirServiceName ` | ||
-securityAuthenticationAuthority $apiAppReg.Authority ` | ||
-securityAuthenticationAudience $apiAppReg.Audience ` | ||
-additionalFhirServerConfigProperties $flattenedRoles | ||
``` |
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
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
Oops, something went wrong.