Security Position
Roles define the work a user may perform. Access to a particular record also depends on the tenant, organisation, facility, patient class, protected classification, purpose of use, query type and export risk.
AMCDR checks access in layers: authenticated identity, membership scope, role keys, route authorization, executable access policies, protected-record clearances, row/query controls, and audit.
The Authentication and Access-Control Matrix explains access levels, authentication methods, patient permissions and deny precedence. It also identifies who manages each control and gives examples of access decisions.
Keycloak Roles and Assignment Groups
The Keycloak configuration defines 56 AMCDR realm roles and assignment profiles below /access-profiles. Administrators should assign the narrowest suitable group rather than attaching individual roles. Profile families cover platform administration, clinical services, MPI stewardship, privacy and release, design and integration, transfers, and Patient Portal identities.
AMCDR normalizes hyphenated Keycloak roles to internal underscore keys. For example, mpi-steward becomes mpi_steward and patient-release-manager becomes patient_release_manager. AMCDR also checks tenant context, SMART grants, patient consent, care-team privacy and protected-record policy.
KEYCLOAK_CONTAINER=terminology-keycloak-keycloak-1 \
./scripts/keycloak/sync-amcdr-access-model.sh
The synchronizer is additive and idempotent. It creates or updates roles, groups and group-role mappings; it does not create users, assign users, delete existing groups or alter client secrets. Export the production realm first and use a least-privilege realm-management automation identity.
| Profile family | Typical assignments |
|---|---|
/access-profiles/platform | Viewer, platform, system, organisation, governance and terminology administration. |
/access-profiles/clinical | Clinical, emergency, pharmacy, laboratory, community, maternity and neonatal users. |
/access-profiles/identity | MPI administrators and identity stewards. |
/access-profiles/privacy-and-release | Protected-record, break-glass, patient-release and SHR-release authorities. |
/access-profiles/design-and-integration | Clinical data, template, form and mapping modelers. |
/access-profiles/patients | Patient Portal users; never combine with staff groups. |
Operational Rule
Assign the smallest standard role first. Add access policies only when the standard role matrix is too broad or too narrow. Add protected-record clearances only for users who need access to VIP, sealed, national-security, witness-protected, very-high-risk, restricted-minor, or unknown protected-person records.
Do not make standard users platform_admin or super_admin to solve access problems. Those roles must remain exceptional control-plane roles.
OIDC and Local Sign-in
When Keycloak/OIDC is enabled and fully configured, AMCDR redirects unauthenticated users directly to the identity provider using authorization code with PKCE. The clinical workspace, internal API documentation, and standalone documentation use the same authentication gate and do not display the local username/password form first.
The public GET /auth/oidc/config response is authoritative. Local password sign-in is rendered only when password_enabled=true, which applies when OIDC is not configured and password authentication is enabled. If the authentication configuration cannot be checked, AMCDR shows a retry screen rather than offering a potentially disabled password workflow.
The browser client uses the exact callback https://<amcdr-public-origin>/oidc-callback. Configure that value under the Keycloak client's valid redirect URIs, configure the origin under web origins, enable Standard Flow and require PKCE S256. URL fragments such as #oidc-callback are invalid, while /oauth2/callback belongs only to a separate OAuth2 Proxy client.
Logout revokes the AMCDR bearer session and invokes Keycloak RP-initiated logout with an id_token_hint. The return page is marked explicitly signed out, so automatic SSO cannot immediately recreate the session. A new session starts only when the user selects Continue with Keycloak, which requires fresh identity-provider verification. Configure https://<amcdr-public-origin>/* as a valid post-logout redirect URI.
Interactive workspace and Patient Portal sessions terminate after 900 seconds (15 minutes) without keyboard, pointer, touch, focus, or activity in another same-origin AMCDR tab. Background refresh does not count as activity. Timeout revokes the AMCDR bearer token, clears patient and request context, invokes Keycloak logout, and returns to the explicitly signed-out page. AMCDR bearer tokens also default to 900 seconds and expired tokens cannot be refreshed.
Layers
| Layer | Purpose | Example |
|---|---|---|
| Authentication | Proves the caller identity. | Password login, OIDC bearer token, API key. |
| Membership scope | Places the user inside a tenant, organisation, environment, and facility. | Clinician at one hospital, platform admin across a tenant. |
| RBAC role keys | Grants broad workspace or API capability. | viewer, clinician, form_designer, governance_admin. |
| Route authorization | Protects route families before endpoint code runs. | /patients requires clinical roles; /admin requires admin roles. |
| Access policies | Allow or deny specific route areas, methods, path prefixes, roles, scopes, and purposes. | Deny broad patient reads for one role; allow a role to read one analytics route. |
| Protected-record controls | Adds classification, clearance, break-glass, and no-existence-leak handling. | VIP patient hidden from broad search unless cleared. |
| Resource/query controls | Filters outputs from AQL, saved queries, data browsers, reports, dashboards, and exports. | Protected records excluded from AQL by default. |
| Clinical relationship scope | Resolves service-only, care-team longitudinal, patient-self, system, administrative, or denied access. | A psychiatrist sees Mental Health records; an active care-team member may see clinically necessary cross-service information. |
| Audit | Records the decision, actor, scope, purpose, and reason. | Denied protected access, export, AQL execution, break-glass. |
Production queries remain inside the caller's tenant, organisation, facility and patient-relationship scope. Every patient row must resolve to an authorized service, care-team, self/proxy or system context. Queries that omit enough patient identity for row-level enforcement are rejected for ordinary clinical users; approved aggregate reporting uses governed reporting authority and disclosure controls.
Individual User Assignment
- Create or confirm the user account.
- Create the membership in the correct tenant and organisation.
- Assign the user's standard operational role.
- Add facility or environment scope where the deployment uses those boundaries.
- Add extra roles only for assigned duties: template design, terminology administration, reporting, integration, or protected-record review.
- Add access policies when the standard route matrix needs deployment-specific restriction or exception.
- For protected records, assign both the workspace role and the relevant clearance.
- Review role assignments, access events, and policy exceptions regularly.
Platform Setup: Policy & Access
Open Super-admin -> Platform configuration -> Policy & access. Follow this order:
- Create the tenant, organisation, and environment first.
- Create users and memberships inside that scope.
- Assign standard role keys before creating policy exceptions.
- Use access policies for executable route restrictions or narrow route exceptions.
- Use sharing policies for cross-organisation, cross-facility, partner, national-service, or reporting data movement.
- Use professional duty policies for purpose-of-use, care-team, practitioner-duty, service-line, or programme controls.
- Use jurisdiction policy packs for country, regional, cross-border, humanitarian, or national-program rules.
- Use protected-record clearances separately for VIP, sealed, witness-protected, national-security, restricted-minor, or unknown protected-person records.
Use Policy & Access to narrow permissions for specific duties. If many users need exceptions, review the role families or membership scopes first.
| Platform setup item | What it controls | Example |
|---|---|---|
| Access policy | Route family, HTTP method, path prefix, role, scope, purpose, and allow/deny decision. | Deny broad patient browsing for temporary users. |
| Sharing policy | Data allowed to leave a scope or be consumed by a partner/reporting destination. | Allow aggregate HMIS output but block identifiable export. |
| Professional duty policy | Whether the user's duty, service line, care-team relation, or purpose supports access. | Maternity clinician access to birth workflows is limited to assigned patients. |
| Jurisdiction pack | Legal, regional, or programme rules applied as a bundle. | National birth/death reporting or refugee programme rules. |
| Protected clearance | Classification-specific access on top of RBAC. | VIP_ACCESS, SEALED_RECORD_ACCESS, BREAK_GLASS_ACCESS. |
Recommended Role Families
| Role family | Typical role keys | Use |
|---|---|---|
| Basic read | viewer | Read allowed clinical and operational surfaces. |
| Clinical operations | clinician, nurse, doctor, clinical_admin | Patient workspace, encounters, forms, clinical capture, care workflows. |
| Registration and MPI | registration_clerk, mpi_admin, org_admin | Client registry, patient registration, identity review, merge and reconciliation tasks. |
| Modelling and forms | form_designer, template_admin, mapping_author, terminology_admin | Templates, forms, terminology bindings, FHIR/openEHR mappings. |
| Reporting and AQL | reporting_analyst, governance_admin, clinical_admin | AQL workbench, saved queries, HMIS, indicators, data browsers, exports. |
| Integration | integration_modeler, integration_admin, scoped API keys | External MPI, FHIR, terminology, subscriptions, outbound integration. |
| Protected records | protected_record_access plus clearances | VIP/protected record access, audit review, break-glass review, reclassification. |
| Platform operations | platform_admin, system_admin, super_admin | Tenants, organisations, users, modules, runtime configuration, high-risk administration. |
AQL, Saved Queries, And Data Browsers
AQL queries and data browsers can return more data than a patient screen. They must enforce RBAC, access policies, scope filters, protected-record filtering, export policy and audit.
| Surface | Minimum controls |
|---|---|
| AQL Workbench | Authenticated user, reporting/query role, tenant or organisation scope, audit event, query size and timeout limits. |
| Saved query execution | Query-specific permission, approved parameters, protected-record filtering, cache key includes role and scope. |
| Data Browser | Read role for the data domain, row-level scope filter, protected-record exclusion by default, export restrictions. |
| HMIS and reporting dashboards | Reporting role, aggregate-safe outputs, no protected identity leakage, saved-query governance. |
| CSV/XML/JSON export | Export permission, purpose of use, audit event, protected-record masking or exclusion, rate limits. |
| AQL over protected records | protected_record_access plus auditor/admin clearance, purpose of use, post-review where protected rows are permitted to appear. |
Access Policy Pattern
Access policies complement RBAC. They support deployment-specific restrictions and exceptions, for example blocking broad patient browsing for a temporary group or allowing a reporting role to use one approved analytics endpoint.
{
"enabled": true,
"effect": "deny",
"priority": 10,
"reason": "Temporary restriction during rollout",
"match": {
"route_policies": ["clinical-operations"],
"methods": ["GET"],
"paths": ["/patients"]
},
"conditions": {
"any_role_keys": ["viewer"]
}
}
Allow policies override standard route RBAC only when allow_route_override is explicitly true. High-risk route families such as API docs, authentication administration, metrics, platform administration, and protected-record administration remain non-overridable.
Policy Examples
| Need | Recommended implementation |
|---|---|
| Block broad patient browsing for a temporary group | Deny policy on clinical-operations, GET, /patients, matched to a temporary role. |
| Give analysts access to saved reports but not patient editing | Reporting role plus allow policy for saved-query routes; no clinical write roles. |
| Allow a clinician to run approved AQL only | Reporting/AQL role plus saved-query permission; no broad admin role. |
| Let a protected-record auditor review VIP access | protected_record_access role plus PROTECTED_RECORD_AUDITOR clearance. |
| Let emergency clinicians use break-glass | Clinical role plus BREAK_GLASS_ACCESS clearance, time limit, and mandatory review. |
| Restrict an integration partner | API key with explicit scopes and route policy; never reuse a human admin account. |
Audit Requirements
AMCDR must audit role assignment changes, policy changes, protected-record access decisions, AQL execution, saved-query execution, data-browser exports, protected-record AQL access, break-glass sessions, and administrative control-plane access.
For AQL and data browsers, the event must include query or saved-query key, parameters, actor, scope, role keys, row count where available, export format, cache hit or miss where relevant, and whether protected rows were filtered, masked, or included.
Implemented clinical relationship boundary
AMCDR applies one server-derived relationship decision across patient search, Patient Workspace, openEHR composition reads, governed FHIR patient-compartment operations, SHR/IPS, documents, medication and diagnostic operations, AQL, saved queries and patient-level operational modules. Patient references in paths, query parameters, EHR identifiers, persisted FHIR resource identifiers and JSON bodies resolve back to the authoritative MPI patient before access is granted.
The Patient Workspace displays Service scope or Care team ยท cross-service. Service scope loads service-attributed compositions and medication/allergy safety data without pre-loading the longitudinal overview. Care-team scope enables clinically necessary cross-service information. Protected-template policy, patient opt-out and governed break-glass remain additive controls.