# Access rules

URL: https://lyeve.com/docs/features/access-rules/

> **Included free** on every install, with rules for up to three roles. More roles need a license with the `rbac-pro` feature. See [pricing](https://lyeve.com/pricing/).

An access rule says what one role may do with one resource. It names the role,
the resource, the actions allowed, and the fields removed from what that role
reads. Rules apply to people who sign in, in LyEve Console or with a
session token, and to API keys through the roles each key carries. The
exception is an admin in the console's content screens, as
[the fixed answers](#how-rules-combine) say.

:::tip[Best for]
- **Editors who must not delete.** Give `editor` `read` and `update` on
  `articles` and nothing else.
- **Hiding a sensitive field.** A `support` role reads customer records without
  ever receiving `internal_notes`.
- **Locking one content type.** An empty rule on `payroll` shuts a role out of
  it while a `*` rule still opens everything else.
- **Who may publish a flow.** Let a role edit flows but keep `activate`, which
  publishes and runs them, for admins.
:::

:::note[Use something else when]
- You want to limit a program further than its roles. An
  [API key](https://lyeve.com/docs/features/api-keys/) also carries scopes and a list of content types.
- You want to know what each role can do before any rule exists. See
  [roles and permissions](https://lyeve.com/docs/guides/user/roles-and-permissions/).
:::

## In the console

Open **Access > Permissions**. Only a super admin sees the page. Each role is a
row, and expanding it lists its rules: **Every content type** for the `*` rule, then
one row per content type or flow. A filled dot is an action the rule allows,
and **Field mask** lists the fields the role does not read.

- **New role** adds a role. It starts with no actions anywhere, and it counts
  toward the [role ceiling](#the-role-ceiling) at once. At the ceiling the
  page says **3 of 3 roles** and offers no **New role**.
- The plus button on a role's row adds a rule, and the pencil edits one. The
  rule form has a checkbox per action and a **Field mask** box for
  comma-separated field names.
- **Show resources with no rule** lists the content types and flows a role has
  no rule for.

(Image: Access > Permissions with a support role that reads every content type and updates author, and a viewer role with an empty Every content type rule that reads post without its body.)

## How it works

A rule is four fields:

```json
{
  "role": "editor",
  "schema_name": "articles",
  "actions": ["read", "update"],
  "field_mask": ["internal_notes"]
}
```

| Field | Meaning |
|---|---|
| `role` | The role the rule applies to. Required. |
| `schema_name` | The resource. Required. |
| `actions` | What the role may do: `create`, `read`, `update`, `delete`, and `activate` on flows and reviews. |
| `field_mask` | Fields removed from what this role reads. |

The resource is one of:

| Resource | Written as |
|---|---|
| One content type | Its name, such as `articles` |
| Every content type | `*` |
| Flows | `flows` for every flow in the tenant, or `flow:<slug>` for one |
| Reviews | `reviews` for every review definition, or `review:<slug>` for one |

`activate` publishes, disables, rolls back, runs, tests and invokes a flow, and
moves an entry through a review. On a content type it is refused with `422`.

### How rules combine

- **Specific beats general.** A rule for `articles` replaces the `*` rule for
  that content type. A rule for `flow:<slug>` replaces the `flows` rule for
  that flow. The `*` rule never applies to flows or reviews.
- **An empty action list denies.** A rule for `articles` with no actions blocks
  that role on articles, even when the `*` rule allows it everywhere else.
- **Field masks add up.** When a specific and a general rule both apply, both
  masks apply. A user holding two roles has every field hidden that either
  role hides.

Four answers are fixed:

- A super admin is allowed everything and reads every field.
- An admin is allowed every flow and review until a rule names `admin` on that
  resource. From then on the rule decides.
- In the console's content screens, an admin reads and writes every content
  type, and no rule or field mask limits an admin there. A rule that names
  `admin` on a content type, and its field mask, apply on the Content API.
- Any other role with no rule is refused. Only admins and super admins open
  the console's content screens, so the rules bind every other role
  everywhere.

A fresh install has no rules, so on the Content API only super admins read or
write content until you write some.

## Try it

This gives a `viewer` role the titles of the `post` content type from the
[quickstart](https://lyeve.com/docs/getting-started/quickstart/), with the body hidden, and
creates an account that holds only that role. `viewer` has no rights of its
own on the engine, and it is one of the four roles the console's user form
offers. Sign in as a super admin first.

<div class="paths">
<div data-path="console">

1. Open **Access > Permissions**. If the page says **3 of 3 roles**, the
   instance is at its [role ceiling](#the-role-ceiling) and takes no new role.
2. Choose **New role**, enter `viewer` in **Role name** and choose **Create**.
   The role's row appears with an empty **Every content type** rule.
3. Choose the plus button on the `viewer` row. In **Resource**, pick `post`.
   Tick **Read**, enter `body` in **Field mask** and choose **Create**. The row
   now says **2 rules**.
4. Open **Access > Users** and choose **New user**. Enter `viewer@example.com`
   in **Email** and `Viewer-Account-2026` in **Password**. Under **Roles**,
   untick **editor**, tick **viewer** and choose **Create**.

</div>
<div data-path="api">

You need a super admin token in `TOKEN`. The quickstart shows how to get one.

1. Check how many roles may still hold rules:

   ```bash
   curl http://localhost:3001/api/admin/permissions/limits \
     -H "Authorization: Bearer $TOKEN"
   ```

   ```json
   { "roles": { "limit": 3, "current": 0 } }
   ```

   A `limit` of `0` means no ceiling.

2. Write the rule:

   ```bash
   curl -X POST http://localhost:3001/api/admin/permissions \
     -H "Authorization: Bearer $TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"role": "viewer", "schema_name": "post", "actions": ["read"], "field_mask": ["body"]}'
   ```

   ```json
   {
     "id": "72a42ef6-948b-445b-80df-b315e1480f8f",
     "role": "viewer",
     "schema_name": "post",
     "actions": ["read"],
     "field_mask": ["body"],
     "created_at": "2026-10-01T09:30:00Z",
     "tenant_id": ""
   }
   ```

   The answer is `200`. Sending a rule for the same role and resource again
   replaces it.

3. Create an account that holds only the `viewer` role:

   ```bash
   curl -X POST http://localhost:3001/api/admin/users \
     -H "Authorization: Bearer $TOKEN" \
     -H "Content-Type: application/json" \
     -d '{"email": "viewer@example.com", "password": "Viewer-Account-2026", "roles": ["viewer"]}'
   ```

   The answer is `201` with the new user.

</div>
</div>

Then read posts as that account. Reading content is a Content API call, so
both paths end here. Sign in as the account and keep its token:

```bash
curl -X POST http://localhost:3001/api/admin/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email": "viewer@example.com", "password": "Viewer-Account-2026"}'
```

Copy `token` into `VIEWER_TOKEN`, then read:

```bash
curl http://localhost:3002/api/v1/content/post \
  -H "Authorization: Bearer $VIEWER_TOKEN"
```

Every entry comes back with `title` and without `body`. A role that no rule
names gets `403` with `permission denied` instead.

## Shut a role out of one content type

Write a rule for that content type with no actions. It overrides any `*` rule
for the same role.

<div class="paths">
<div data-path="console">

On **Access > Permissions**, choose the plus button on the role's row and pick
the content type in **Resource**. Leave every action clear and choose
**Create**. Before you create it, the form says **This rule blocks** the role,
and that the role is denied every action on that content type.

</div>
<div data-path="api">

Send the rule with an empty `actions` list to `POST /api/admin/permissions`:

```json
{ "role": "editor", "schema_name": "payroll", "actions": [] }
```

</div>
</div>

The empty rule needs a `*` rule or another grant to override. On a role with
none, the console says **This rule would do nothing** and keeps **Create**
off.

To open it again, delete the rule or write it again with the actions you want.

## Rules and tenants

A rule on a flow or review belongs to the tenant it was written in. A content
type rule and the `*` rule apply in every tenant. A tenant's own rule on a
resource takes the place of the shared one.

Renaming a flow keeps its access. Deleting a flow deletes its rules, so a new
flow with the same slug starts with none. Deleting a tenant deletes the rules
it wrote.

## When a change takes effect

A change applies at once on the replica that saved it. Other replicas apply it
when they are told of the change, or at the latest after `CACHE_TTL`. See
[scaling](https://lyeve.com/docs/scaling/) for running more than one replica.

## Settings

| Variable | What it does | Default |
|---|---|---|
| `CACHE_TTL` | How long a replica keeps rules it has read. `0s` reads them on every request. | `60s` |

Access rules run on every install. If you set `LYEVE_PLUGINS`, include
`permissions` in it. See [licensing and tiers](https://lyeve.com/docs/concepts/licensing-and-tiers/).

## The role ceiling

Without `rbac-pro`, the rules a tenant sees may name three different roles, and
a license without `rbac-pro` does not raise that number. A rule for a fourth
role answers `402`:

```json
{ "error": "cap_exceeded", "cap": "rbac.roles", "limit": 3, "current": 3, "upgrade_url": "https://app.lyeve.com/pricing?skus=plugin-rbac-pro&utm_campaign=rbac.roles&utm_medium=product&utm_source=admin" }
```

Editing a rule for a role that already has one is always allowed, because it
adds no role. An install already past the ceiling keeps every role it has.

## Routes

Every route needs a super admin with a signed-in session. An admin token is
refused with `403 This route needs a signed-in session.`

<details>
<summary>Rule routes</summary>

| Method | Path | Result |
|---|---|---|
| `GET` | `/api/admin/permissions` | Every rule your tenant sees. `[]` when there are none. |
| `POST` | `/api/admin/permissions` | Creates the rule for that role and resource, or replaces it. `200`. |
| `DELETE` | `/api/admin/permissions/{id}` | `204`, or `404 permission not found`. |
| `GET` | `/api/admin/permissions/limits` | The role ceiling and how many roles hold rules. |

</details>

## Errors

| Status | Message | Cause |
|---|---|---|
| `403` | `permission denied` | A content request from a role no rule allows. |
| `402` | `cap_exceeded` | A new role would pass the role ceiling. |
| `422` | `invalid action: <action>` | The action is unknown, or `activate` on a content type. |

<details>
<summary>Every error the rule routes return</summary>

| Status | Message | Cause |
|---|---|---|
| `400` | `invalid request body` | The body is not JSON. |
| `400` | `invalid id` | The id in the path is not a UUID. |
| `402` | `cap_exceeded` | A new role would pass the role ceiling. |
| `403` | `This route needs a signed-in session.` | An admin token called a rule route. |
| `404` | `permission not found` | No rule has that id in your tenant. |
| `422` | `role and schema_name are required` | A required field is empty. |
| `422` | `invalid resource: a schema name, *, flows, flow:<slug>, reviews or review:<slug>` | `flow:` or `review:` with no slug, or a slug that is not valid. Any other name is stored as given. |
| `422` | `invalid action: <action>` | The action is unknown, or `activate` on a content type. |

</details>

## Related

- [Roles and permissions](https://lyeve.com/docs/guides/user/roles-and-permissions/): what each
  role may do before any rule.
- [Flows](https://lyeve.com/docs/features/flows/#who-may-do-what): which flow route needs which action.
- [API keys](https://lyeve.com/docs/features/api-keys/): what a key's scopes and content types add to its roles.
- [Editorial review](https://lyeve.com/docs/features/editorial-review/): the review definitions a rule can
  name.
