AccessPolicy best practices
Access policies creating and maintaning recommendations
Naming
Access policy naming is an important aspect as good name makes it is easier to understand and manage policies.
Add as-
prefix to describe the audience of the policy
as-
prefix to describe the audience of the policyName should describe the intended user, user group or application who was granted permissions, such as "practitioner" in the example provided. This way, anyone looking at the name can quickly identify the intended audience for the policy.
For example, as-practitioner-use-graphql
Explain what resources is granted access to
Additionally, it's helpful to include information about the resource being accessed in the policy name. For example, "use-graphql" in the example above gives context to the type of resource being accessed.
Several good names examples
as-patient-upload-profile-photo
as-practitioner-get-user-notifications
as-anoymous-verify-one-time-password
as-smart-app-read-patient-details
.
path should be tested for present?
.
path should be tested for present?
Path parameter is useful, but there is a corner case with it. If both values are absent, then the check evaluates to true statement.
This policy allows the following request.
Fixed version requires .user.data.patient
exists
complex
engine with or
operator
complex
engine with or
operatorWhen using only the or
operator in the complex
policy, it is recommended to create several access policies rather than combining all conditions into a single policy.
It gives profits:
Tiny policies give well grained access control
Small policies are easy to maintain
Aidbox logs access policy which granted access. If you have "fat" policy, it is not transparent what exact rule let a request in. When there are tiny policies, it is clear who passed the request.
For example, we have such an access policy.
That policy should be splitted to two ones.
Needless RegEx usage
Replacing RegEx patterns with plain string comparison can improve policy readability.
$one-of
instead of |
operator
$one-of
instead of |
operatorDisable unsafe search parameters
By default access policy in Aidbox allows all the search parameters. Access policies checks only fields, specified in the policy and ignore others. It do nothing with semantic of the operation.
Let's say you want to make GET /Practitioner publicly available, and you make the following AccessPolicy.
This policy accepts GET /Practitioner request with any search parameter, including unsafe ones (e.g. _include
, _revinclude
, _with
, _assoc
).
You may explicitly restrict unsafe search parameters.
Now the policy accepts GET /Practitioner request with any search parameters except _include
, _revinclude
, _with
, _assoc
.
Last updated