Policies
Write policies that grant identities, users and API keys exactly the actions and resources they need, and use the built-in policies.
A policy is a named list of statements. Every statement allows one action in one module, optionally limited to some resources. Policies are attached to identities, users and API keys, and a request is allowed when at least one attached statement matches it.
{
"name": "Blog Reader",
"description": "Read published blog posts",
"statement": [
{
"action": "bucket:data:index",
"module": "bucket:data",
"resource": {"include": ["6b0b1968a5611972c29c25f7"], "exclude": []}
},
{
"action": "bucket:data:show",
"module": "bucket:data",
"resource": {"include": ["6b0b1968a5611972c29c25f7"], "exclude": []}
}
]
}
Statements
| Field | Description |
|---|---|
action | The operation, such as bucket:data:index. |
module | The module the action belongs to, such as bucket:data. |
resource | Optional. include and exclude lists of resource ids. Leave it out for actions that have no resources. |
Resources
"*"matches every resource.- A resource with several parts is written with
/, for example<functionId>/<handlerName>forfunction:invoke. excluderemoves resources from theincludelist. Whenexcludeis used, everyincludeentry must end with*.
{"include": ["*"], "exclude": ["6b0b19cea5611972c29c260f"]}A statement whose resource doesn't fit the action's format makes requests fail with 409 and a message such as Policy "Blog Reader" contains a statement [0] whose resource does not match the resource definition. Expected 1 arguments.
Actions by module
| Module | Actions | Resource |
|---|---|---|
bucket | index, show, create, update, delete, stream | Bucket id |
bucket:data | index, show, create, update, delete, stream, profile | Bucket id |
function | index, show, create, update, delete, stream | Function id |
function:invoke | function:invoke | <functionId>/<handlerName> |
function:logs | index, delete | |
function:env-var, function:secret | inject, eject | |
env-var, secret | index, show, create, update, delete, stream | Id |
storage | index, browse, show, create, update, delete | Object id or name |
passport:identity | index, show, profile, create, update, delete, stream | Identity id |
passport:identity:policy, passport:user:policy, passport:apikey:policy | add, remove | |
passport:user | index, show, profile, create, update, delete, stream | User id |
passport:apikey | index, show, create, update, delete, stream | API key id |
passport:policy | index, show, create, update, delete, stream | Policy id |
passport:strategy | index, show, insert, update, delete | |
passport:refresh-token | index, show, update, delete, stream | |
dashboard | index, show, create, update, delete, stream | Dashboard id |
webhook, webhook:logs | index, show, create, update, delete / index, delete | |
activity | index, delete | |
asset | index, show, install, export, download, delete | |
preference | show, update | Scope, such as bucket |
config | index, show, update | |
status | index, show |
Actions are written with their module prefix, for example passport:user:update. GET /passport/identity/statements returns every statement that applies to the caller.
Built-in policies
Every module has a full access and a read-only policy. Their ids are their names, and they can't be changed.
| Policy | Grants |
|---|---|
ActivityFullAccess, ActivityReadOnlyAccess | Activity stream |
ApiKeyFullAccess, ApiKeyReadOnlyAccess | API keys |
AssetFullAccess, AssetReadOnlyAccess | Assets |
BucketFullAccess, BucketReadOnlyAccess | Bucket schemas and data |
ConfigFullAccess, ConfigReadOnlyAccess | Configuration |
DashboardFullAccess, DashboardReadOnlyAccess | Dashboards |
EnvVarFullAccess, EnvVarReadOnlyAccess | Environment variables |
FunctionFullAccess, FunctionReadOnlyAccess | Functions, logs and invocation. Read-only also reads env vars; full access also manages env vars and secrets |
IdentityFullAccess, IdentityReadOnlyAccess | Identities |
PassportFullAccess, PassportReadOnlyAccess | Identities, strategies, API keys, policies, refresh tokens and users |
PolicyFullAccess, PolicyReadOnlyAccess | Policies |
PreferenceFullAccess, PreferenceReadOnlyAccess | Preferences |
RefreshTokenFullAccess, RefreshTokenReadOnlyAccess | Refresh tokens |
SecretFullAccess, SecretReadOnlyAccess | Secrets |
StatusFullAccess | Status and usage |
StorageFullAccess, StorageReadOnlyAccess | Storage |
StrategyFullAccess, StrategyReadOnlyAccess | Login strategies |
UserFullAccess, UserReadOnlyAccess | Users |
WebhookFullAccess, WebhookReadOnlyAccess | Webhooks |
Manage policies
| Endpoint | Action |
|---|---|
GET /passport/policy | passport:policy:index |
GET /passport/policy/:id | passport:policy:show |
POST /passport/policy | passport:policy:create |
PUT /passport/policy/:id | passport:policy:update |
DELETE /passport/policy/:id | passport:policy:delete |
Changes take effect immediately for everyone the policy is attached to, without new tokens.
Examples
Example: content editor
Lets editors manage the entries of two content buckets and upload images, without touching schemas, functions or users:
{
"name": "Content Editor",
"description": "Manage posts and authors, upload media",
"statement": [
{"action": "bucket:index", "module": "bucket", "resource": {"include": ["*"], "exclude": []}},
{"action": "bucket:show", "module": "bucket", "resource": {"include": ["<postsId>", "<authorsId>"], "exclude": []}},
{"action": "bucket:data:index", "module": "bucket:data", "resource": {"include": ["<postsId>", "<authorsId>"], "exclude": []}},
{"action": "bucket:data:show", "module": "bucket:data", "resource": {"include": ["<postsId>", "<authorsId>"], "exclude": []}},
{"action": "bucket:data:create", "module": "bucket:data", "resource": {"include": ["<postsId>", "<authorsId>"], "exclude": []}},
{"action": "bucket:data:update", "module": "bucket:data", "resource": {"include": ["<postsId>", "<authorsId>"], "exclude": []}},
{"action": "bucket:data:delete", "module": "bucket:data", "resource": {"include": ["<postsId>", "<authorsId>"], "exclude": []}},
{"action": "preference:show", "module": "preference", "resource": {"include": ["bucket"], "exclude": []}}
]
}Combine it with StorageFullAccess so that editors can upload images.
Example: everything except one bucket
{
"name": "All Data Except Customers",
"description": "Read every bucket but customers",
"statement": [
{"action": "bucket:data:index", "module": "bucket:data", "resource": {"include": ["*"], "exclude": ["<customersId>"]}}
]
}Example: call one HTTP function
For HTTP triggers with authorize: true:
{
"name": "Order API",
"description": "Create orders",
"statement": [
{"action": "function:invoke", "module": "function:invoke", "resource": {"include": ["<functionId>/createOrder"], "exclude": []}}
]
}Designing policies
- Start from the built-in read-only policies and add write access deliberately.
- Create policies per role ("Content Editor", "Support") instead of per person.
- Give API keys their own narrow policies.
- For users, combine a policy that opens the endpoints with bucket rules that filter the documents.
- Keep policies in git with the CLI, so changes are reviewed.