# Access in the manifest

> Ship your app's permission sets, roles and restrictions in its manifest: the install creates them in one step, upgrades keep the workspace's edits and never widen access without an admin's approval, and uninstalling removes them.

Source: https://docs.ligament.ai/guides/building-apps/access-in-the-manifest/

An app can ship its **access model** in its manifest, under `access`: the permission sets, roles and restrictions that decide who sees and does what in the app. Installing the app creates them in the workspace’s [spec store](https://docs.ligament.ai/guides/building-apps/index.md), owned by the app, in the same step as its records, pages and workflows. Nobody has to apply anything after the install.

The HR app is built this way: its sets, roles and restrictions (pay for HR and the managers above an employee, leave reasons for the employee and HR only, no approving your own leave) are in its manifest. See [HR › Set it up](https://docs.ligament.ai/guides/hr/index.md#set-it-up).

## What goes in it

| Key | What it holds |
| --- | --- |
| `permissionSets` | Grants on the app’s entities and fields, and capabilities. Keys are `<app>.<name>`, for example `hr.employee` |
| `roles` | Roles that hold permission sets. Keys are `<app>_<name>`, for example `hr_admin` |
| `restrictions` | Rules that take access away whatever grants it: forbidden actions, field caps, and field caps per record with `unlessWhere` (for example: pay is masked except on your own record) |
| `appAdminRole` | The role whose holders administer the app’s access without being workspace admins. It must hold a set with the capability `app.admin@<app>` |

Field classifications stay on the fields (`classification: 'pii'` or `'sensitive'`), and follow the same rules as the rest of the access model.

The documents have the same shape as the spec store’s `permissionSet`, `role` and `restriction` artefacts (`GET /api/spec/schema/<type>`), without `app`: it’s the app that ships them. Every field is in the [manifest reference](https://docs.ligament.ai/reference/app-manifest/index.md#field-access).

```ts
export default defineApp({
  key: 'leave',
  version: '1.0.0',
  releaseNotes: '1.0: leave requests with manager approval.',
  entities: [/* leave_request … */],
  access: {
    permissionSets: [
      { key: 'leave.staff', label: 'Leave: my requests',
        grants: [{ entity: 'leave_request', ops: ['read', 'create', 'update'], where: { left: '{{employee_user}}', op: 'eq', right: '@me' } }] },
      { key: 'leave.admin', label: 'Leave: administer',
        grants: [{ entity: 'leave_request', ops: ['read', 'update', 'delete', 'transition'] }],
        capabilities: ['app.admin@leave'] },
    ],
    roles: [
      { key: 'leave_staff', name: 'Leave: staff', permissionSets: ['leave.staff'] },
      { key: 'leave_admin', name: 'Leave: admin', permissionSets: ['leave.staff', 'leave.admin'] },
    ],
    restrictions: [
      { key: 'leave.reason_private', entity: 'leave_request', fields: { reason: 'hidden' },
        unlessWhere: { left: '{{employee_user}}', op: 'eq', right: '@me' }, enforceOnAdmins: true,
        message: 'The reason is for the employee only.' },
    ],
    appAdminRole: 'leave_admin',
  },
})
```

`ligament app validate` and publishing check the access model against the manifest: the keys carry the app’s name, a role’s sets exist, restrictions are on the app’s own entities, an app can’t ship `workspace.admin` or administer another app, and the app-admin role holds `app.admin@<app>`. The install then checks every document against the workspace, as any apply would (entities, fields, conditions, capabilities), and refuses an access model that doesn’t fit.

## Install

Installing the app (from the App Store, `POST /api/apps/install` or `ligament app install`) creates the access model in one step:

-   each set, role and restriction is applied through the spec store, with a version row and an access audit entry, and its address names the app: `leave/role/leave_admin`;
-   what this version shipped is kept as the artefact’s `base` layer, so the next upgrade knows what you changed;
-   deleting one of the app’s artefacts is refused (`spec.delete_base`): change it, or uninstall the app.

After the install, give people the app’s roles in **Settings › Access › Assignments**.

## Change it in your workspace

The app’s access model is yours to adjust like any access artefact: in **Settings › Access**, or by planning and applying it in the spec store. The artefact then shows as customised: what’s in effect differs from what the app shipped.

## Upgrade

An upgrade compares three versions of every artefact: what the installed version shipped, what is in effect in your workspace, and what the new version ships.

| Situation | Result |
| --- | --- |
| You never changed it | The new version applies. |
| You changed it, the app changed something else | Your change is kept and the app’s change is merged in. |
| You and the app changed the same value | Your value is kept, and the plan says so. |
| You deleted it | It stays deleted. |
| The new version no longer ships it | Removed if you never changed it; otherwise kept as the workspace’s own. |

**Nothing widens access silently.** Every change is simulated against your members, the same way as the [effective-access diff](https://docs.ligament.ai/guides/access/reviewing-access-changes/index.md) of any access change, and also checked for what the simulation can’t see: a restriction removed or relaxed, a forbidden action or transition dropped, a capability or a permission set added, a classification removed. A change that would give anyone more access needs your approval:

-   the upgrade summary lists it under **Access** as *widens access: needs your approval*, with the reason;
-   `POST /api/apps/upgrade` answers `409` with `code: "access_widening"` and the `pending` addresses until you decide on each one;
-   send `approveAccess` (a list of addresses, or `"all"`) to apply them, or `keepAccess` to keep your version for good. `takeAccess` takes the new version of something you changed (still subject to approval if it widens).

Changes that only take access away, or change nothing anyone can do, apply without asking. If an install runs without your decision (for example from the CLI), a widening change is held: nothing changes, and the next upgrade plan offers it again.

```json
POST /api/apps/upgrade
{ "appKey": "leave", "version": "1.1.0", "approveAccess": ["permissionSet/leave.staff"], "keepAccess": ["restriction/leave.reason_private"] }
```

## Uninstall

Uninstalling the app removes its roles and permission sets. `{ "preview": true }` on the uninstall (`POST /api/store/<app>/unsubscribe` or `POST /api/apps/uninstall`) returns the plan first: who loses what, member by member.

The app’s records stay after an uninstall, so nothing is removed that would open them up. These are kept, as the workspace’s own and held by nobody, unless you approve their removal with `approveAccess`:

-   restrictions (pay masked, leave reasons private, no approving your own leave);
-   permission sets that keep the app’s records closed to everyone else. Without any set granting on an entity, every seat would get the default access to it.

A role that someone holds as their seat role is kept too, with the sets it holds. The plan’s diff shows only what is actually removed. Role assignments stay, and apply again if you install the app again; installing it again creates the access model afresh.

## Built-in modules

Built-in modules such as People and Customers upgrade the same way, from **App Store › Updates available** or `POST /api/apps/upgrade` with the module’s key. The summary compares the module’s new version with what your workspace’s tables hold: its entities and fields, the money conversions with their dry run, and access. `"preview": true` changes nothing.
