How access is decided
Two separate questions are answered on every request, and it helps to keep them apart when debugging:
- Authentication: who is this caller, and which project are they acting in?
- Authorization: may this caller perform this operation on this resource type?
A token that passes the first can still be refused by the second. A denial naming your role and a resource type is always the second.
Identity
A bearer token is validated against the project's identity provider, and two claims are read out of it: an entity type (Patient, Practitioner, RelatedPerson, Device) and an entity id (a FHIR logical id). Together they are the caller's identity, and everything downstream operates on that pair. Confirm what your token resolved to with Me:
query {
Me {
reference
}
}
The request must also name a project, and the project named in the token must match the one in the X-Project-ID header. See the project binding.
Access is denied unless a rule grants it
Every permission on a resource exists because someone wrote a rule for that exact client_role / entity_name / operation triple, and a triple with no rule is refused. There is no permissive fallback and no implicit grant for "obviously safe" resources.
- A missing rule is a denial, not a gap to be discovered later. Searches come back
[]and reads come backnull, with no error to say why. If a screen in your application is empty, the first thing to check is whether the triple it needs has a rule. - Broad access is something you choose and can explain. Where a grant is deliberately wide, write it down next to the rule.
Rules
A rule matches on three fields and names the validator that decides:
{
"client_role": "Practitioner",
"entity_name": "Observation",
"operation": "read",
"validator": "legitimate_interest"
}
| Field | Meaning |
|---|---|
client_role | the caller's resolved entity type |
entity_name | the FHIR resource type being accessed |
operation | create, read, update, delete or search |
validator | which validator decides the request |
Matching is on the exact triple. All three are compared as literal strings, and there is no wildcard. A search with no search rule falls back to that triple's read rules; that is the only fallback in the system.
Every matching rule must pass. Two rules on the same triple mean the request must satisfy both, so a second rule always narrows access and never widens it. To grant access you remove the restrictive rule; you do not add a permissive one beside it.
No matching rule means denied. A rule naming a validator that does not exist is denied rather than ignored.
Rules may additionally require the caller to hold a specific clinical role. See Requiring a practitioner role.
The order of decision
- Platform checks, before any rule is read. Three of them, listed under Behaviour you cannot configure.
default_access: "Allowed", if set. Areadorsearchis granted here without reading a rule. Writes proceed to rule matching.- Rule matching, on the exact triple.
- The search fallback. A
searchwith nosearchrule is decided by the triple'sreadrules. default_access, when nothing matched."Forbidden"denies."Allowed"grants, which is why an unmatched write is permitted under it.- The validator named by each matching rule.
On reads and searches the validator runs twice: once before anything is fetched, deciding on the resource type alone, and again on each row that comes back. The second pass is what makes compartment scoping real. A refused request never reaches the FHIR store at all.
Validators
There are exactly ten. A rule naming anything else, including a differently cased spelling such as PatientCompartment, is not recognised and the request is denied.
| Validator | Decides access by |
|---|---|
patient_compartment | the resource being in the caller's patient compartment |
practitioner_compartment | the resource being linked to the caller as practitioner |
relatedperson_compartment | the resource being in the caller's RelatedPerson context |
organization_compartment | the caller's active organization relationships |
organization_consent | the caller's active organization relationships AND an active Consent naming the caller or their organization |
device_compartment | the device's own compartment, and optionally its organization |
general_practitioner | the patient's generalPractitioner references |
legitimate_interest | the platform's legitimate-interest table for that resource type and role |
allowed | nothing; it inspects no row, beyond refusing a create whose id already exists |
forbidden | nothing; it denies unconditionally |
Each has a page under Validators.
| Scenario | Validator |
|---|---|
| Patient accessing their own lab results | patient_compartment |
| Practitioner updating an order they authored | practitioner_compartment |
| Practitioner reaching everything in their clinic | organization_compartment |
| Practitioner reaching only patients who consented to them or their organization | organization_consent |
| A GP reaching the records of patients who name them | general_practitioner |
| Cross-organizational access under a regulatory basis | legitimate_interest |
| A device submitting the data it measures | device_compartment |
| A device reading organisation-level data it did not generate | device_compartment with organisation scoping, in preference to allowed |
| Genuinely shared reference data | allowed, chosen deliberately and documented |
allowed is a blanket grant, not a light checkIt inspects nothing. Pairing allowed with read on a resource type carrying patient data grants a read of every such resource in the project. That is occasionally what you want, but it should always be a deliberate choice rather than a way to make a stubborn rule pass.
Platform rules are merged into every project
A fixed set of platform rules is prepended to every project's own rules. They are not visible in the project's configuration and cannot be removed from it, but they can be narrowed: they merge in as ordinary rules, every rule matching a request has to pass, so a forbidden rule of your own on the same triple refuses it.
| Roles | Resource | Operations |
|---|---|---|
Patient, Practitioner, Device, RelatedPerson | Me | read |
Patient, Practitioner, Device, RelatedPerson | UploadFile | create, read |
Device | Communication | create, read, update |
All of them use the allowed validator. If your project must not permit device messaging, add Device / Communication rules with the forbidden validator for all three operations; the platform's read grant applies no compartment filter, so leaving it in place returns every Communication in the project to any of that project's devices.
Behaviour you cannot configure
Three things are decided in code and apply to every project regardless of its rules. They exist because the rule schema has no way to express them.
Meis always readable. It is not a FHIR resource type, so no rule can match it. It resolves from your own token and reads nothing.AuditEventis read-only. Any operation other thanreadorsearchis refused. Reads and searches ofAuditEventare decided by your rules in the normal way.Communicationwrites are checked for thread and sender forgery, so a caller cannot attach a message to a conversation they are not part of, or send one attributed to someone else. Ordinary clinicalCommunicationresources are left to your rules.
Configuration shape
{
"rbac": {
"default_access": "Forbidden",
"validators": {
"legitimate_interest": {
"role_inheritance_levels": 1,
"enabled": true
}
},
"validation_rules": []
}
}
default_access recognises exactly two values, "Forbidden" and "Allowed", compared literally. "Forbidden" is the secure default and what the shipped templates use.
"Allowed" grants anything your rules do not coverdefault_access is consulted only where no rule matches the role, resource and operation. Where a rule exists, that rule decides. Where none exists, "Allowed" grants reads, searches and writes that no rule covers. Do not use it in production; the publish step rejects it for new configurations. See Writing access rules for the full order.
Related
- Writing access rules: the rule structure in depth, what a compartment validator asks of a write, and the mistakes that deny everything silently
- Compartments
- Making authenticated requests
- Requiring a practitioner role