Access Policies
AccessPolicy is an Aidbox custom resource representing a set of checks for the request. AccessPolicy resources are used to check request objects against a set of rules. If there are no AccessPolicy resources defined in Aidbox, all requests will be denied.
If AccessPolicies exist, Aidbox iterates through them, evaluating each AccessPolicy against the request object. As soon as one of them passes the validation (the evaluation result is true), the request is considered authorized, and Aidbox stops further policy evaluation. If all policies fail to validate it (all of them evaluated to false), then Aidbox denies the request and responds with 403 Forbidden.
The structure of the AccessPolicy resource and the request object are described below.
AccessPolicy resource structure
AccessPolicy resource has the following structure:
It supports various evaluation engines: Allow, JSON Schema, SQL, Matcho, and Complex, as well as Allow-RPC and Matcho-RPC. They specify how checks are implemented — with an SQL statement, with a JSON Schema, or as a list of allowed endpoints.
Request object structure
Aidbox evaluates AccessPolicy against a request object that represents an incoming HTTP request. It has the following structure:
AccessPolicy links
AccessPolicy instance can be linked to User, Client or Operation resources with the AccessPolicy.link field. If AccessPolicy has no links, it’s considered a global policy. To authorize a request, Aidbox uses global policies in addition to all AccessPolicy rules linked to User, Client, and Operation associated with the current request.
TODO Tutorials
Best practice - use Access Policies for complex access control logic
Debugging Access Policies
Evaluation engines
Aidbox provides several ways to specify rules for AccessPolicy resources — so-called evaluation engines. They come with their syntax and offer varying degrees of flexibility and convenience for writing those rules.
There are five evaluation engines:
Allow
Simplest engine that allows everything for certain User
, Client
or makes Operation
public
- Testing and development environments - Superuser/admin access - Public endpoints
Matcho
Mathes request context with a set of rules
- Most common access control scenarios (90% of cases)
JSON Schema
Uses JSON Schema validation for request objects
- For those familiar with JSON Schema
SQL
Uses SQL queries for access control logic
- Complex data-dependent rules - When you need to join multiple tables - Performance-critical scenarios
Complex
Combines multiple engines and conditions
- Multi-step validation workflows - When you need to combine different types of checks - Advanced access control scenarios
It is recommended to pick the Matcho engine. In 90% of cases, it is enough. Sometimes, the complex access policy can only be written by SQL or Complex engines.
Allow engine
The Allow engine is the simplest. It allows all requests.
The allow engine always evaluates true regardless of the request object. Use it if you want to provide unrestricted access to everything.
Example:
Matcho engine
Example
In this example, the request is allowed only if:
Uri is related to Encounter. E.g.
/fhir/Encounter
or/Encounter
,HTTP request is either
GET
orPOST
, notPUT
,practitioner
parameter provided as a query string in case of theGET
request or body params in case of thePOST
request must be equal topractitioner_id
of the user,
User data, which is fetched from the "user" table, must contain the inpatient
department and practitioner.
See also
TODO: How to write & debug accesspolicies tutorial
Last updated
Was this helpful?