Multi-tenancy and security¶
artifactr serves many tenants from one process and one storage. It keeps them apart by construction, and it attributes every change to an actor your application authenticated. Authentication itself is yours. This page describes what the library enforces, what it leaves to you, and where to be careful.
Tenants and workspaces¶
A tenant is the top-level isolation boundary: an organization, a customer, or a single user, as your application defines it. Each tenant has any number of workspaces, and each workspace has its own artifacts, threads, proposals and log.
Isolation comes from scoped handles (ADR-0011). Workspaces.open(tenant_id, workspace_id, actor=...) is the only place a tenant id enters. The Workspace it returns carries its scope, and every storage call it makes is scoped to that tenant and workspace. Nothing below the handle accepts a tenant id, so application code cannot write a query that crosses tenants by mistake. A database-level guard, such as PostgreSQL row-level security, can be layered underneath as defence in depth.
Reading or writing another tenant's data through the public API is a vulnerability; please report it if you find a way.
Authentication is the host's¶
Each surface asks your application who is calling:
| Surface | Hook | Returns |
|---|---|---|
| WebSocket and REST | resolve_actor(connection) |
The tenant and the actor, or raises Unauthorized |
| MCP | resolve(ctx) |
The tenant and the ExternalAgentActor |
The tenant and actor come from these hooks, never from the client's frames or tool arguments, so a client cannot act for another user or reach another tenant by changing its request. That makes the hooks the boundary: verify a session, token or API key there, and derive the tenant from the verified identity rather than from anything the client supplies. Headers, query parameters and names are claims until you have checked them.
The reference implementation trusts an x-user header, to stay short. Do not copy that part.
Authorization¶
Within a tenant, decide who may do what with an authorize(tenant_id, workspace_id, actor, access) hook, which Workspaces holds (ADR-0056). Every Workspace method asks it before it reads or writes anything, with the action it takes (access.action, one of artifactr.workspace.ACTIONS) and the thread or artifact it names. Every surface reaches storage through those methods, so every REST request, WebSocket command, MCP tool call, resource read and subscription, and in-process call is asked by the same hook; none takes a hook of its own. Over REST, a refusal answers 403; the WebSocket closes with 4403 if it may not open the workspace or read its log, and answers a refused command with a forbidden result; MCP fails the tool call, or the read or subscription with INVALID_PARAMS, with the same message. Without it, any authenticated actor may do anything in every workspace of its own tenant.
Listing a tenant's workspaces (Workspaces.list, GET /workspaces, the list_workspaces tool) spans the tenant, so it asks authorize for artifactr:read_workspaces with workspace_id=None. It then asks artifactr:open in each workspace it finds, and lists only those allowed, so a caller never learns the id of a workspace it can't open (ADR-0058). Listing opens nothing, and doesn't call on_open.
A subscription, the WebSocket's or an MCP client's, is asked when it opens. Each command on it is asked as it arrives, so a revoked actor's next command is refused, but events keep flowing until the subscription closes.
An agent's run acts for the person whose message or answer started it, AgentActor.on_behalf_of, and a turn takes messages from one author only, so one person's message never rides on another's rights (ADR-0057). An MCP client that carries a person's token should act for them: set ExternalAgentActor(on_behalf_of=UserActor(...)) in resolve. authorize can then decide on the person. The runner's own work is asked as SystemActor(name="runner").
Finer rules come from the library itself:
- Type allowlist.
Workspaces(storage, types=[...])rejects creating any artifact type not listed, even one registered elsewhere in the process. - Proposals need a second participant. A proposal must be answered by someone other than its author, so an agent cannot approve its own change, a person cannot approve their own through an agent's run or an MCP client acting for them, and cannot approve in person what their own client proposed.
- Run facts belong to the agent. Only a thread's own agent, or the system, may record facts about that thread's runs; clients cannot forge
run_startedortool_returned. - Attribution cannot be borrowed. A handle acts as the actor it was opened for. The agent's handle is derived from yours with
as_actor, and only your code chooses the actor.
Checking what a command carries¶
authorize decides who may send a command, not what it carries. To refuse a command for its content, such as an answer that doesn't fit a form, give Workspaces checks by command type (ADR-0073):
from artifactr.core import Command, CreateArtifact, ValidationFailed
from artifactr.workspace import Workspace, Workspaces
async def briefs_have_titles(workspace: Workspace, command: Command) -> None:
if isinstance(command, CreateArtifact) and command.kind == "brief":
if not command.data.get("title"):
raise ValidationFailed("a brief needs a title", [])
workspaces = Workspaces(storage, checks={"create_artifact": briefs_have_titles})
- A check runs in
commit, onceauthorizeallows the command, and before its transaction. A command an actor may not send never reaches it. - It reads as the command's actor: the handle it is given is the committing one, so it sees what the actor may see, and no more.
- It refuses with a rejection, such as
ValidationFailed, whose errors name the fields, orInvalidState; the client gets it typed, as core's own (422 or 409 over REST). Anything else it raises fails the command as an error. - A command is checked under its own type: a
propose_changeunder"propose_change", whatever it wraps. Facts, whichrecordwrites for runs, are not checked. - A check is not a lock. What it read may change before the command commits.
Restricted threads and artifacts¶
An application that restricts some threads or artifacts to some of a workspace's members gives Workspaces a hidden(tenant_id, workspace_id, actor) hook, which returns what the actor may not see there: an artifactr.core.Visibility, or any object with its threads and artifacts sets (ADR-0062). Every read leaves them out:
- A hidden item is missing. Reading one, or a command or claim that names one, raises
NotFound, 404 over REST, as for one that doesn't exist; so is a run in a hidden thread, and a proposal on a hidden artifact, and answering either. A hidden thread's runs and history are empty, as a missing thread's are. - Listings leave them out, and a thread's focus its hidden artifacts.
- The log drops what is about them. An artifact or proposal event from a hidden thread is kept without its thread and run, and a hidden thread's agent is named with no thread, so a visible artifact's history stays whole. A page of the log is full whatever was hidden.
- A handle asks the hook at most once every
hidden_refresh(Workspaces(hidden_refresh=), 30 seconds by default), so an open subscription, or a run the WebSocket forwards, learns of a new restriction within that time. - The agent reads as its turn's actor, so the hook sees whom the turn acts for, through
on_behalf_of.
Without a hook, nothing is hidden. grantr's Grants.hooks(subject_of).hidden is one.
Integrations switched off¶
An application whose artifact types belong to an integration, such as diagrams or native files, gives Workspaces a gate, usually integration_gate(integrations, key_of) on lattice-core's Integrations port (ADR-0081). While an integration is off in a workspace, making, changing and accepting a proposal about one of its artifacts is refused with not_enabled, 409 over REST, on every surface; archiving and rejecting a proposal pass, and reads are kept. A command is checked in this order: a NUL character, the workspace's membership, what it names and implies against hidden, the gate, then authorize. So a hidden artifact is missing whether its integration is on or off, and "not available in this workspace" says nothing about a person's grants.
Keeping agents in bounds¶
- Write policies. Give sensitive types
write_policy = "propose", or put a thread in suggest mode, and every agent change waits for a person. This covers external agents over MCP as well as the built-in agent. - Approvals. Declare tools with side effects outside the workspace (publishing, sending email, spending money) with
requires_approval=True. The run pauses until a person approves or declines the call. - Least privilege in your tools. Application tools run with your application's dependencies (
ctx.deps.app). Give them only what they need, and check permissions in the tool, not only in the prompt. - Artifacts are untrusted input to the model. Anything a person or another agent writes into an artifact reaches your agent's context, through its instructions, change notes and reads. Treat it like any user message when you decide what the agent's tools may do.
A NUL character¶
Text can't hold a NUL character. Every Workspaces and Workspace method refuses one in an id, a name or a command's text with validation_failed, before authorize hears it, so a client can't reach PostgreSQL, or your hook, with a string neither can take (ADR-0061).
Resource limits¶
The WebSocket surface closes connections that do not say hello within hello_timeout (10 seconds), and disconnects clients whose outbox exceeds outbox_size frames (1,000) instead of buffering without bound. A disconnected client resumes from the log without losing anything. The library does not limit request sizes, message lengths or command rates; enforce those in your application or at your proxy.
Reporting vulnerabilities¶
Report vulnerabilities privately, as described in the security policy.