> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oasm.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Tenancy and access control

> How OASM keeps workspaces apart: authentication, the workspace permission check on every request, the no-escalation rule, and the database constraints that make a cross-workspace row impossible

A **workspace** is the tenant in OASM. Targets, assets, findings, jobs, workflows, projects, files, integrations and settings all belong to exactly one workspace, and nothing in the platform reads or writes across that boundary on a user's behalf. This page explains how that boundary is enforced, from the HTTP request down to the database row.

Managing members and permission groups from the console is covered in [Members](https://docs.oasm.io/members.md) and [Permissions](https://docs.oasm.io/permissions.md).

```mermaid theme={null}
flowchart TD
    Req["Request<br/>console, REST client, MCP client"] --> Auth{"Authentication<br/>session cookie or API key"}
    Auth -->|"no session"| R401["401"]
    Auth --> Admin{"/admin route?"}
    Admin -->|"yes"| AdminGuard["Platform role ADMIN<br/>+ admin IP allow-list"]
    Admin -->|"no"| WS{"Workspace permission check<br/>membership + permission keys"}
    WS -->|"not a member / missing key"| R403["403"]
    WS --> Svc["Service<br/>every query scoped by workspaceId"]
    Svc --> DB[("PostgreSQL<br/>composite FKs, row-level security")]
```

## Layers of the boundary

Isolation is not a single check. It is enforced at four layers, so a bug in one layer does not open the boundary on its own:

| Layer | What it does |
| - | - |
| **Authentication** | Establishes *who* is calling: a user session, a workspace API key (MCP only) or a worker token (gRPC only). |
| **Workspace permission check** | Establishes that the caller is a member of the workspace and holds the permission the route requires. |
| **Service queries** | Every read and write filters on the workspace, either through its own `workspaceId` column or through the path to it (for example finding → asset → target → workspace). |
| **Database constraints** | Composite foreign keys keep a child row in its parent's workspace, and the query engine runs under row-level security. |

## Identities

Three kinds of caller reach the core API, each over its own channel:

* **Users** sign in to the console. Authentication is handled by [better-auth](https://www.better-auth.com/): an httpOnly `session` cookie (`SameSite=Lax`, `Secure` behind https), with the database as the source of truth and a short-lived Redis cache in front of it. Revoking a session writes a revocation marker so the cache can never resurrect it.
* **MCP clients** send the workspace API key in the `x-oasm-api-key` header. The key is accepted only on the MCP endpoint and maps the request to the key's workspace. See [API keys](https://docs.oasm.io/api-keys.md) and [MCP](https://docs.oasm.io/settings/mcp.md).
* **Workers** never use a user session or the API key. They join with a single-use join key and then authenticate every gRPC call with their own worker token. See [Worker and connector runtime](https://docs.oasm.io/architecture/worker-runtime.md#identity-and-joining).

Each user also has a **platform role**: `user` or `admin`. The role controls the [administration](https://docs.oasm.io/users-and-role.md) area only; it does not grant access to anyone's workspace data. Admin endpoints live under a separate `/admin` prefix, require the admin role, and additionally check the client IP against the admin IP allow-list when one is configured.

### Sign-in protection

* **Rate limiting** — 100 requests per minute per client IP and path, with much stricter budgets on sign-in, sign-up and password changes. Counters live in Redis, so every API replica shares the same budget.
* **Origin checks** — cookie-carrying requests are accepted only from trusted origins (`BASE_URL` and `TRUSTED_ORIGINS`), which also form the CORS allow-list for the API and the storage buckets.
* **Gated sign-up** — public sign-up is off by default. When it is on, new accounts wait for admin approval. See [Authentication](https://docs.oasm.io/authentication.md).

## The workspace permission check

Every workspace-scoped route declares the permission it needs, in the form `<resource>.<action>`, for example `asset.read`, `target.write` or `workspace.apikey`. Before the handler runs, a guard:

1. resolves the workspace from the route or the `X-Workspace-Id` header,
2. loads the caller's membership and the **union** of the permission keys of all their groups,
3. passes the request only when the keys contain every required key (or the wildcard `*`).

Two rules keep the check predictable:

* **`write` implies `read`** for the same resource. Nothing else is implied.
* **Non-members get 403, never 404**, and an id that is not a UUID is a 400. The response never reveals whether a workspace exists.

The full list of keys is a fixed catalog; a permission group can only hold keys from it. See [Permissions](https://docs.oasm.io/permissions.md#all-permissions).

### No privilege escalation

Permission groups are how access is delegated, so the platform makes sure delegation cannot grow access:

* You can only grant permission keys — or assign groups — whose keys you already hold.
* The built-in **Admin** group (holding `*`) is a system group: it cannot be edited, deleted or handed out by invitation.
* You cannot change your own membership, the workspace owner's, or that of any holder of a system group.
* Invitations go only to existing accounts, and the response returns counts only, so it does not reveal which email addresses have accounts.

Some destructive operations — creating and deleting targets, managing internal networks — additionally require the caller to be the **workspace owner**, whatever their permission keys say.

## Scoping inside the core API

The workspace id a service works with always comes from the permission check (or, for workers and agents, from their authenticated context). It is never taken from a request body. From there:

* Tables that carry `workspaceId` filter on it directly (targets, projects, issues, workflows, files).
* Tables that do not are scoped through their parent. Jobs, for example, are scoped through asset → target → workspace.
* A lookup of another workspace's id returns **404**, so ids from one tenant are indistinguishable from ids that do not exist.
* User data returned by the API is limited to `id`, `name` and `image`; email addresses and account fields are visible to platform admins only.

The [Security Agent](https://docs.oasm.io/architecture/ai-agent.md) and the [MCP endpoint](https://docs.oasm.io/settings/mcp.md) go through the same services, so they inherit the same scoping. An agent tool runs with the workspace of the conversation, never a workspace the model names.

## Scoping in the database

The attack surface tables — assets, services, HTTP responses and their TLS, technology, IP and status-code facets, DNS records, discovered URLs, tags and vulnerabilities — each carry their own `workspaceId` column. Three mechanisms keep it correct:

* **Composite foreign keys.** A child references its parent by `(parentId, workspaceId)`, and the parent is unique on `(id, workspaceId)`. A service row whose workspace differs from its asset's is rejected by Postgres.
* **Fill triggers.** When a writer leaves the column empty, a `BEFORE INSERT` trigger copies it from the parent, so older code paths stay correct.
* **Row-level security.** Queries from the [Attack Surface Query engine](https://docs.oasm.io/architecture/attack-surface-query-engine.md) run as a dedicated `asq_reader` role with the workspace set on the transaction. Row-level security policies on these tables then hide every row of other workspaces, even if a compiled query were wrong.

## Scoping on the real-time stream

The console keeps one Server-Sent Events connection open (`GET /events/stream`) for live updates. Because any member can open it regardless of permissions, it follows two rules:

* **Allowlist.** Only a small set of event families (notifications, workers, targets, workflows) reach browsers. Every other event on the [event bridge](https://docs.oasm.io/architecture/event-bridge.md) stays server-side.
* **Ids only.** A browser receives the event name, ids and time — never a payload. It then refetches through REST, which applies the permission check above.

## Accountability

Membership, permission and configuration changes are recorded in the [audit log](https://docs.oasm.io/audit-log.md). The audit table is append-only at the database level; see [Secrets and encryption](https://docs.oasm.io/architecture/secrets-and-encryption.md#audit-trail-integrity).

## Related

> [card] [Secrets and encryption](https://docs.oasm.io/architecture/secrets-and-encryption.md)
>
> How credentials are encrypted per workspace and released to workers

> [card] [Permissions](https://docs.oasm.io/permissions.md)
>
> Permission groups and the full list of permission keys

> [card] [Data model](https://docs.oasm.io/architecture/data-model.md)
>
> The tables the boundary protects

> [card] [Attack Surface Query engine](https://docs.oasm.io/architecture/attack-surface-query-engine.md)
>
> How tenant scope is compiled into every query


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.