You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 13, 2023. It is now read-only.
feat: implement multi-tenancy and group export (#416)
* feat: add tenantId attribute to Cognito user pool (#348)
* feat: remove unneeded scope checks in authorizer (#347)
* feat: update lambda state machine to accommodate tenantId (#367)
* feat: add "enableMultiTenancy" CFN parameter (#381)
* test: add multi-tenancy integ tests (#387)
* fix: remove _id, _tenantId from bulk export results (#384)
* feat: Group export scripts (#389)
* fix: add multi-tenant metadata route (#392)
* fix: allow more concurrent export jobs for multi-tenant deployments (#397)
* test: integ tests for Group export (#393)
* feat: add ES hard delete config value (#398)
* docs: update postman collection and docs to use Id token (#399)
* docs: add multi-tenancy docs (#400)
Co-authored-by: Yanyu Zheng <[email protected]>
BREAKING CHANGE: The Cognito IdToken is now used instead of the accessToken to authorize requests.
If you intend to use FHIR Implementation Guides read the [Using Implementation Guides](./USING_IMPLEMENTATION_GUIDES.md) documentation first.
42
42
43
+
If you intend to do a multi-tenant deployment read the [Using Multi-Tenancy](./USING_MULTI_TENANCY.md) documentation first.
44
+
43
45
## Architecture
44
46
45
47
The system architecture consists of multiple layers of AWS serverless services. The endpoint is hosted using API Gateway. The database and storage layer consists of Amazon DynamoDB and S3, with Elasticsearch as the search index for the data written to DynamoDB. The endpoint is secured by API keys and Cognito for user-level authentication and user-group authorization. The diagram below shows the FHIR server’s system architecture components and how they are related.
@@ -103,23 +105,17 @@ Set up the following three environment variables:
103
105
104
106
For instructions on importing the environment JSON, click [here](https://thinkster.io/tutorials/testing-backend-apis-with-postman/managing-environments-in-postman).
105
107
108
+
The `COGNITO_AUTH_TOKEN` required for each of these files can be obtained by following the instructions under [Authorizing a user](#authorizing-a-user).
109
+
106
110
The following variables required in the Postman collection can be found in `Info_Output.log` or by running `serverless info --verbose`:
107
111
+ API_URL: from Service Information:endpoints: ANY
108
112
+ API_KEY: from Service Information: api keys: developer-key
109
-
+ CLIENT_ID: from Stack Outputs: UserPoolAppClientId
To find what FHIR Server supports, use the `GET Metadata` Postman request to retrieve the [Capability Statement](https://www.hl7.org/fhir/capabilitystatement.html)
119
115
120
116
**Authorizing a user**
121
117
122
-
FHIR Works on AWS uses Role-Based Access Control (RBAC) to determine what operations and what resource types a user can access. The default rule set can be found in [RBACRules.ts](https://github.com/awslabs/fhir-works-on-aws-deployment/blob/mainline/src/RBACRules.ts). To access the API, you must use the OAuth access token. This access token must include scopes of either `openid`, `profile` or `aws.cognito.signin.user.admin`.
118
+
FHIR Works on AWS uses Role-Based Access Control (RBAC) to determine what operations and what resource types a user can access. The default rule set can be found in [RBACRules.ts](https://github.com/awslabs/fhir-works-on-aws-deployment/blob/mainline/src/RBACRules.ts). To access the API, you must use the ID token. This ID token must include scopes of either `openid`, `profile` or `aws.cognito.signin.user.admin`.
123
119
124
120
Using either of these scopes provide information about users and their group. It helps determine what resources/records they can access.
125
121
@@ -129,18 +125,9 @@ Using either of these scopes provide information about users and their group. It
129
125
130
126
For more information, click [here](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-app-idp-settings.html).
131
127
132
-
**Retrieving access token via postman using the openid profile**
133
-
134
-
To access the FHIR API, an access token is required. This can be obtained by following these steps within Postman:
135
-
136
-
1. Open Postman and choose the operation (for example, `GET Patient`).
137
-
2. In the **Authorization** tab, choose **Get New Access Token**.
138
-
3. A sign in page appears. Enter the username and password (if you don't know it look at the [init-auth.py](https://github.com/awslabs/fhir-works-on-aws-deployment/blob/mainline/scripts%5Cinit-auth.py) script).
139
-
4. After signing in, the access token is set and you have the access for approximately one hour.
140
-
141
-
**Retrieving an access token using aws.cognito.signin.user.admin**
128
+
**Retrieving an ID token using aws.cognito.signin.user.admin**
142
129
143
-
A Cognito OAuth access token can be obtained using the following command substituting all variables with their values from `Info_Output.log` or by using the `serverless info --verbose` command.
130
+
To access the FHIR API, an ID token is required. A Cognito ID token can be obtained using the following command substituting all variables with their values from `INFO_OUTPUT.log` or by using the `serverless info --verbose` command.
The return value is an access token that can be used to hit the FHIR API without accessing the Oauth Sign In page. In Postman, instead of clicking the Get New Access Token button, you can paste the `ACCESS_TOKEN` value into the **Available Tokens** field.
139
+
The return value is the `COGNITO_AUTH_TOKEN` (found in the postman collection) to be used for access to the FHIR APIs.
Multi-tenancy allows a single `fhir-works-on-aws` stack to serve as multiple FHIR servers for different tenants.
4
+
5
+
`fhir-works-on-aws` uses a pooled infrastructure model for multi-tenancy. This means that all tenants share the
6
+
same infrastructure (DynamoDB tables, S3 Buckets, Elasticsearch cluster, etc.), but the data
7
+
is logically partitioned to ensure that tenants are prevented from accessing another tenant’s resources.
8
+
9
+
## Enabling multi-tenancy
10
+
11
+
Use the `enableMultiTenancy` option when deploying the stack:
12
+
13
+
```bash
14
+
serverless deploy --enableMultiTenancy true
15
+
```
16
+
17
+
**Note:** Updating an existing (single-tenant) stack to enable multi-tenancy is a breaking change. Multi-tenant
18
+
deployments use a different data partitioning strategy that renders the old, single-tenant, data inaccessible.
19
+
If you wish to switch from single-tenant to a multi-tenant model, it is recommended to create a new multi-tenant stack
20
+
and then migrate the data from the old stack. Switching from multi-tenant to a single-tenant model is also a breaking change.
21
+
22
+
## Tenant identifiers
23
+
24
+
Tenants are identified by a tenant Id in the auth token. A tenant Id is a string that can contain alphanumeric characters,
25
+
dashes, and underscores and have a maximum length of 64 characters.
26
+
27
+
There are 2 ways to include a tenant Id in the auth token:
28
+
29
+
1. Add the tenant Id in a custom claim. This is the recommended approach.
30
+
The default configuration adds the tenant Id on the `custom:tenantId` claim
31
+
32
+
1. Encode the tenant Id in the `aud` claim by providing an URL that matches `<baseUrl>/tenant/<tenantId>`.
33
+
This can be useful when using an IDP that does not support custom claims.
34
+
35
+
If a token has a tenant Id in a custom claim and in the aud claim, then both claims must have the same tenant Id value,
36
+
otherwise an Unauthorized error is thrown.
37
+
38
+
The default deployment adds a custom claim `custom:tenantId` to the Cognito User Pool. You can manage the tenant Id value
39
+
for the different users on the AWS Cognito Console. The [provision-user.py](https://github.com/awslabs/fhir-works-on-aws-deployment/blob/mainline/scripts/provision-user.py)
40
+
script will also create users with a set tenant Id.
41
+
42
+
## Additional Configuration
43
+
44
+
Additional configuration values can be set on [config.ts](https://github.com/awslabs/fhir-works-on-aws-deployment/blob/mainline/src/config.ts)
45
+
46
+
-`enableMultiTenancy`: Whether or not to enable multi-tenancy.
47
+
-`useTenantSpecificUrl`: When enabled, `/tenant/<tenantId>/` is appended to the FHIR server url.
48
+
49
+
e.g. A client with `tennatId=tenantA` would use the following url to search for Patients:
50
+
```
51
+
GET <serverUrl>/tenant/<tenantId>/Patient
52
+
GET https://1234567890.execute-api.us-west-2.amazonaws.com/dev/tenant/tenantA/Patient
53
+
```
54
+
Enabling this setting is useful to give each tenant a unique FHIR server base URL.
55
+
56
+
-`tenantIdClaimPath`: Path to the tenant Id claim in the auth token JSON. Defaults to `custom:tenantId`
compartmentdefinition-patient.3.0.2.json: http://hl7.org/fhir/stu3/compartmentdefinition-patient.json.html (Note the AuditEvent and Provenance fields in this file are updated to remove dotted path)
0 commit comments