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.

JSON
{
  "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": []}
    }
  ]
}
The policies page listing built-in full access and read only policies

Statements

FieldDescription
actionThe operation, such as bucket:data:index.
moduleThe module the action belongs to, such as bucket:data.
resourceOptional. 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> for function:invoke.
  • exclude removes resources from the include list. When exclude is used, every include entry must end with *.
JSON
{"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

ModuleActionsResource
bucketindex, show, create, update, delete, streamBucket id
bucket:dataindex, show, create, update, delete, stream, profileBucket id
functionindex, show, create, update, delete, streamFunction id
function:invokefunction:invoke<functionId>/<handlerName>
function:logsindex, delete
function:env-var, function:secretinject, eject
env-var, secretindex, show, create, update, delete, streamId
storageindex, browse, show, create, update, deleteObject id or name
passport:identityindex, show, profile, create, update, delete, streamIdentity id
passport:identity:policy, passport:user:policy, passport:apikey:policyadd, remove
passport:userindex, show, profile, create, update, delete, streamUser id
passport:apikeyindex, show, create, update, delete, streamAPI key id
passport:policyindex, show, create, update, delete, streamPolicy id
passport:strategyindex, show, insert, update, delete
passport:refresh-tokenindex, show, update, delete, stream
dashboardindex, show, create, update, delete, streamDashboard id
webhook, webhook:logsindex, show, create, update, delete / index, delete
activityindex, delete
assetindex, show, install, export, download, delete
preferenceshow, updateScope, such as bucket
configindex, show, update
statusindex, 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.

PolicyGrants
ActivityFullAccess, ActivityReadOnlyAccessActivity stream
ApiKeyFullAccess, ApiKeyReadOnlyAccessAPI keys
AssetFullAccess, AssetReadOnlyAccessAssets
BucketFullAccess, BucketReadOnlyAccessBucket schemas and data
ConfigFullAccess, ConfigReadOnlyAccessConfiguration
DashboardFullAccess, DashboardReadOnlyAccessDashboards
EnvVarFullAccess, EnvVarReadOnlyAccessEnvironment variables
FunctionFullAccess, FunctionReadOnlyAccessFunctions, logs and invocation. Read-only also reads env vars; full access also manages env vars and secrets
IdentityFullAccess, IdentityReadOnlyAccessIdentities
PassportFullAccess, PassportReadOnlyAccessIdentities, strategies, API keys, policies, refresh tokens and users
PolicyFullAccess, PolicyReadOnlyAccessPolicies
PreferenceFullAccess, PreferenceReadOnlyAccessPreferences
RefreshTokenFullAccess, RefreshTokenReadOnlyAccessRefresh tokens
SecretFullAccess, SecretReadOnlyAccessSecrets
StatusFullAccessStatus and usage
StorageFullAccess, StorageReadOnlyAccessStorage
StrategyFullAccess, StrategyReadOnlyAccessLogin strategies
UserFullAccess, UserReadOnlyAccessUsers
WebhookFullAccess, WebhookReadOnlyAccessWebhooks

Manage policies

EndpointAction
GET /passport/policypassport:policy:index
GET /passport/policy/:idpassport:policy:show
POST /passport/policypassport:policy:create
PUT /passport/policy/:idpassport:policy:update
DELETE /passport/policy/:idpassport: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:

JSON
{
  "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

JSON
{
  "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:

JSON
{
  "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.