---
title: Operations and Audit
description: >-
  Understand permission rebuilds, cascades, dry runs, changesets, history, and
  audit logs for safe RBAC operations.
canonical_url: 'https://saaslayer.com/docs/permissions/operations-and-audit/'
last_updated: '2026-11-22T17:01:19-08:00'
---
# Operations and Audit

Authorization changes can have wide impact. SaaSLayer Permissions includes operational tools for previewing, applying, tracking, and auditing those changes.

## Permission rebuilds

Permission checks read a materialized permission document for the principal. Writes that affect access may rebuild or invalidate that document.

Common rebuild triggers:

* Role assignment or removal
* Role permission changes
* Role inheritance changes
* Policy attachment or update
* Boundary changes
* Membership or hierarchy changes
* Grant creation or revocation

You can inspect a user's materialized state:

```http
GET /users/user-alice/perm-state
```

Use this when debugging unexpected allows or denies.

## Cascades

Some changes affect many principals. For example, changing a widely used role can require rebuilding permissions for every principal with that role.

SaaSLayer Permissions supports asynchronous cascades for large fanout changes. API responses may indicate that a cascade was queued instead of completed synchronously.

Operational guidance:

* Avoid editing broad roles during high-traffic windows unless the change is urgent.
* Watch cascade job status after large updates.
* Prefer smaller scoped roles when possible.
* Use dry-run and impact previews before destructive changes.

## Dry runs

Some write endpoints support dry-run mode. Dry runs show what would change without persisting the mutation.

Use dry runs before:

* Deleting roles
* Deleting policies
* Updating high-impact entities
* Applying changes from admin tools

## Changesets

Changesets group multiple RBAC mutations into a staged workflow. They are useful when a change should be reviewed, previewed, approved, applied, and possibly rolled back as one unit.

Use changesets for:

* Workspace onboarding changes
* Role redesigns
* Policy migrations
* Large cleanup operations
* Changes that require approval before apply

## History and rollback

Roles and policies expose history endpoints and rollback operations. Use them when a configuration change had unintended effects.

Examples:

```http
GET /roles/role-admin/history
POST /roles/role-admin/rollback

GET /policies/policy-prod-guardrail/history
POST /policies/policy-prod-guardrail/rollback
```

Keep rollback procedures documented for your own admin operators. Rollback is most useful when your team knows which version was last known good.

Use `GET /users/{id}/history` to read snapshots of a principal's previous effective permissions. By default, a snapshot expires 90 days after it is superseded. For a long-term record of who changed what, use the audit log below.

## Audit logs

Audit logs record RBAC operations with actor, target, scope, event type, and details where available. Each entry also records who it is about, as known when it was written, so a line still names someone after they leave the org.

Useful queries:

```http
GET /audit/actor/user-admin
GET /audit/target/ROLE/role-billing-manager
GET /audit/scope/ws-acme-prod
GET /audit/org/org-acme?types=membership.removed,role.assigned
GET /audit/recent
GET /audit/events?eventType=cascade.*
```

Use audit logs to answer:

* Who changed this role?
* Which policies were edited recently?
* What changed in this workspace?
* Which operations caused a permission cascade?
* Was a denied support action attempted?

### What an entry records about people

Every entry carries `identities`: the people it is about (its actor, the real actor behind an impersonated or brokered action, and its subjects), keyed by principal id.

```json
{
  "actor": "usr_01alice",
  "eventType": "membership.removed",
  "targetType": "USER",
  "targetId": "usr_01bob",
  "identities": {
    "usr_01alice": { "kind": "user", "name": "Alice Example", "email": "alice@acme.com", "source": "membership" },
    "usr_01bob": { "kind": "user", "name": "Bob Example", "email": "bob@acme.com", "source": "membership" }
  }
}
```

| Field | Meaning |
|---|---|
| `kind` | `user`, `operator` (the deployment's support staff, or an IAM administrator), `service` (an agent, service account or service key) or `system` |
| `name`, `email` | as known when the entry was written; later renames don't rewrite history. Names are at most 200 characters, emails are lowercased |
| `source` | where they came from: `token` (the caller's verified sign-in token), `membership` (the person's membership record in the entry's org), or for older entries `backfill:membership`, `backfill:principal` or `legacy:actorName` |
| `resolvedAt` | backfilled identities only: when the person was looked up, not when the event happened |
| `supportLabel` | operators only: how customers see them (see [Staff in the audit log](#staff-in-the-audit-log)) |
| `erased` | the person was erased: name and email are gone, `kind` stays |

An id missing from `identities` is recorded by id only. An entry about more than 25 people names the first 25 and carries `identitiesTruncated: true`. An entry that could only be stored with ids carries `identitiesWithheld: true`.

Entries no longer carry `actorName` or `actorType`: read `identities[actor]` instead.

### Where names come from

A name or email is recorded only from evidence the service trusts:

* The caller acting for themselves: their membership record in the entry's org, else the name and email in their verified token. An API key is recorded by the key's name; an IAM caller as `SaaSLayer administrator`.
* A staff member viewing as someone: the staff member from their own verified token; the person viewed from their membership record in the org.
* Every other person (the person viewed, a brokered actor, a subject): only from their membership record in the entry's org. Without one, they are recorded by id only.
* Never from a request body. A user's account email is used only to fill in entries written before entries named people, and only when that org's own log shows the person joined it (`backfill:principal`).

Who counts as a subject is fixed per event:

| Event | Subjects |
|---|---|
| `membership.added`, `membership.removed` | `details.memberId`, when the member is a user |
| `membership.batch_added`, `membership.batch_removed` | the users in `details.members` |
| `role.assigned`, `role.removed` | `targetId`, when `targetType` is `USER` |
| `role.batch_assigned`, `role.batch_removed` | `affectedUsers` |
| `ownership.transfer_*`, `access_admin.transfer_*` | `details.targetId`, else `targetId` when `targetType` is `USER` |
| Product events (`POST /audit/org/:orgId/events`), impersonation and account events | none: only the actor is named |

Other ids in `details` are never looked up, so naming someone in a product event's `details` can't make the service disclose who they are.

### Details hold no personal data

An entry's `details` never holds personal data, except the invited address of `invitation.create` (`details.email`, which erasure replaces with `"[erased]"`). Changes to a person's own record (a user, or a personal workspace, which is named for its owner) are recorded by field name only: `user.created` carries `details.fields` and `user.updated` `details.changedFields` (for example `["email", "name"]`), never the old or new values; a team org, group, role or agent keeps its values. An email address or phone number anywhere else in `details`, product events included, is dropped when the entry is written, and `detailsRedacted` lists the paths removed.

### Staff in the audit log

When support staff view as a member (see [Support Staff](https://saaslayer.com/docs/permissions/support-staff)), the entry's actor is the person viewed and `realActor` is the staff member. The staff member is stored with `kind: operator`, their name and email, and `supportLabel`: the deployment's `permissions-service.SupportLabel` at the time of the entry (default `Support`).

Customers should only ever see the label. The audit API returns the stored identity, name and email included, to anyone who can read that org's audit log, so:

* `<sl-audit-log>` shows staff only as their label, e.g. "Support (as Jane Doe)".
* A product rendering its own feed must do the same. If staff identities must not reach customers' browsers at all, read the feed from your backend and replace each operator identity with its label before sending it on.

### Showing people in your product

* Show `identities[id].name`, with `email` as hover or tap text. With no name, show the email.
* An entry without `identities` for that id (written before entries named people, or recorded by id only): fall back to your live member list, else "a former member".
* `erased: true`: show "a deleted user (…" plus the id's last 5 characters ")", and skip every fallback, so lines about the same person can still be matched without naming them.
* `kind: operator`: show `supportLabel` only. An erased operator shows as a deleted user.
* Show `kind` apart from the name (a badge, for example): anyone can name themselves "System".
* Render names and emails as text, never HTML. If you export to CSV, escape cells that start with `=`, `+`, `-` or `@`.

`<sl-audit-log>` follows these rules.

### Retention

Entries are kept for `permissions-service.AuditRetentionDays` days: default 365, from 30 to 2555.

* The expiry is stamped on each entry when it is written, so a change applies to entries written afterwards. Existing entries keep theirs.
* On prod and staging, records of required access-change operations are kept at least 400 days, whatever the setting.
* Reads never return an entry past its expiry. DynamoDB deletes expired entries a few days later.

### Erasure

When a person's account is deleted, the deployment's Users service erases them from the audit log before it purges the account. An operator can also erase a person, for example to retry after an interrupted delete:

```bash
saaslayer permissions audit erase usr_01bob --deployment prod --email bob@acme.com --email bob.old@acme.com
```

Both call `POST /audit/identities/:personId/erase` (`audit:person:erase`, held by the deployment's Users service key and platform administrators, never by org admins or the person themselves), with every address the person had in `emails` (at most 50).

Erasure redacts, it doesn't delete:

* every entry, and every undelivered required-audit record, that names the person keeps `identities[id]` as `{ kind, erased: true }`;
* invitation entries for any of the given addresses get `details.email` set to `"[erased]"`. Pass every address with `--email`, including ones the deployment never knew (an invitation sent to an address the person never signed in with);
* ids, event types, scopes and times stay, so the record of what happened is intact;
* entries written afterwards record the person as `{ kind, erased: true }`;
* an `audit.identity_erased` entry is written (ids only), readable at `GET /audit/target/USER/<personId>`.

Erasure can't be undone. Data a product puts in its own events' `details` is not touched: keep names and emails out of `details`.

The call answers `202` with `status: "requested"` or `"done"`. `requested` means the erasure is recorded and no new entry can store the person's name or email; the scheduled audit worker finishes it within minutes. Repeating the call is safe at any time and can add more addresses; each repeat records another `audit.identity_erased`.

### Settings

| Setting | Default | Meaning |
|---|---|---|
| `permissions-service.SupportLabel` | `Support` | how staff appear to customers, 1-60 characters |
| `permissions-service.AuditRetentionDays` | `365` | days an entry is kept, 30-2555; applies to new entries |

```bash
saaslayer deployment settings set --env prod --set permissions-service.SupportLabel="Acme support" --set permissions-service.AuditRetentionDays=730
```

Permissions needs foundation 8.1.0 or later (audit writes, including the deploy-time seed's, use `dynamodb:ConditionCheckItem`): upgrade the foundation first.

## Safe-change checklist

Before a broad authorization change:

1. Identify affected roles, policies, workspaces, and principals.
2. Run a dry run or impact preview where available.
3. Use a changeset for multi-step changes.
4. Apply during an operationally safe window.
5. Watch cascade jobs and audit logs.
6. Test representative permission checks with explain mode.
7. Keep rollback information close to the change record.
