Skip to content

Admin impersonation ("View as User")

An administrator can temporarily view the app as one of their users to reproduce what that user sees for support — their navigation, feature gates, role, plan, and settings. Impersonation is an administrative, cookie-plane capability: the operator acts within the admin API as the target, every action is attributed to both the real administrator and the target, and the session ends the moment the operator stops — or sooner if their right to impersonate lapses. (If the server-side record cannot be ended because of a database fault, the stop answers 503 and the record runs out at its 30-minute expiry; see impersonation_stop_failed below.)

⚠️ This is act-as, not read-only — but the user's personal data is hidden. While impersonating, the operator's admin-API requests carry the target's identity and scope, but the target's private content is refused (403), not shown: chats, memories, uploads and knowledge-file downloads, personal keywords, slash commands, the personal data export, wallet / billing, approvals, scheduled tasks, devices, MCP connectors, and project conversations. See Personal data is refused. Creating durable credentials is likewise refused — see Durable credentials are blocked. Every permitted mutation is audited against both identities (below).


Session model

Starting impersonation issues a second, short-lived cookie — aig_imp — alongside the operator's own aig_admin session (the operator's session is never destroyed, so stopping restores it with no re-login). aig_imp is a signed JWT (HttpOnly; Secure; SameSite=Strict, Path=/admin, 30-minute lifetime) that carries the target id, the real administrator id, and an impersonation-session id.

The token is never trusted for scope. On every request the server re-reads the target's live account row (role, tenant) and re-checks that the operator is still allowed to impersonate that target — so the impersonated scope is always exactly the target's current scope, re-derived server-side, never asserted by the client.

Impersonation ends — reverting the operator to their own session on the next request — when any of these becomes true: the operator stops it (and the record is ended — a stop that hits a database fault answers 503 impersonation_stop_failed and leaves the record to its expiry), the 30-minute token expires, the impersonation record is ended, the operator loses the right to impersonate (their account is disabled, or they are demoted below administrator/tenant-administrator), the operator's own admin session was revoked (its iat is at or before the operator's sessions_valid_after floor — a disabled and later re-enabled operator's old cookie can neither impersonate nor mint a fresh impersonation), or the target's sessions were ended (the impersonation token predates the target's sessions_valid_after floor).


Endpoints

Method Path Auth Description
POST /admin/auth/impersonation/start aig_admin session (admin / tenant-admin) Begin viewing as a user. Body: { "user_id": "<id>", "reason": "<why>" }. reason is required (1-500 characters after trimming; free text, shown to the target in the notice mail and stored on the impersonation record). No token is issued unless the session and its impersonation.start row committed: 503 when nothing was written (including a lock wait behind a tenant purge), 500 { "error": "could not start impersonation" } for any other fault. On success sets the aig_imp cookie and returns { "ok": true, "impersonating": { "actor": {...}, "target": {...}, "expires_at": <unix-seconds> } }.
POST /admin/auth/impersonation/stop Public (idempotent) End impersonation. Always clears the aig_imp cookie; ends the server-side record when the real administrator session and the impersonation id can be identified, and returns { "ok": true } (also when there was nothing to end — safe to call when not impersonating). If the server-side record cannot be ended, the cookie is still cleared — the browser is back on the administrator's own identity — and the answer is 503 { "error": "temporarily unavailable", "code": "impersonation_stop_failed" } when nothing ended (lock wait, every attempt conflicted, no connection) or 500 { "error": "internal error", "code": "impersonation_stop_failed" } when the audit row was refused or the outcome is unknown. Neither carries Retry-After (with the cookie gone a retry cannot reach the record); an impersonation.stop_failed audit event is written instead of impersonation.stop, and the record may stay active until its own expiry (at most 30 minutes). impersonation.stop is audited only when the call actually ended an active record.

While impersonating, GET /admin/auth/me returns the target's account payload plus an impersonating block ({ actor, target, expires_at }) that the UI uses to render a persistent on-screen banner. That block is advisory (display only) — the server re-derives and re-checks impersonation on every request and never trusts the client's copy.

Accepted and rejected input

user_id is validated at the trust boundary and every disallowed target is refused fail-closed (the client is never the authorization boundary). Each denial is recorded as an impersonation.denied security-audit event.

Condition Result
Valid, permitted target 200 + aig_imp cookie
user_id absent / not a string / empty 400 { "error": "user_id required" }; audited as impersonation.denied
user_id present but not 1-36 printable, non-space ASCII bytes (0x21-0x7E): longer than 36 bytes, or containing a space, a control character or a non-ASCII byte 400 { "error": "invalid user_id", "code": "invalid_user_id" }; audited as impersonation.denied (status 400) without the value - the probed value is deliberately not recorded. Checked before any lookup, so it is not an existence oracle. This is a length and charset rule, not a UUID check: ids that exist but are not UUIDs remain valid targets
Body is not valid JSON, or holds a non-finite number 400 malformed_body; audited as impersonation.denied (status 400)
Body has more than 262,144 JSON values (body_too_complex) 413 body_too_complex; audited as impersonation.denied (status 413)
Body cannot be read (server-side read fault) 503 with Retry-After; not audited (a server fault, not a denial)
Not signed in (aig_admin missing/invalid) 401
Caller is not an administrator or tenant-administrator 403 — checked first, for any target (existing or not), before the body is read
Caller holds sys:admin, admin_mfa_enforced is on, and the caller's session lacks password plus a second factor (its amr is not pwd with otp, hwk, swk or rc) 403 { "error": "a session with password and second factor is required", "code": "mfa_session_required" }; audited as impersonation.denied (status 403). Checked after the administrator check and before the body is read; nothing is started. Sign in again with password and second factor. See password and second factor
admin_mfa_enforced unreadable or malformed, or the caller's roles cannot be read, while deciding the row above 503; not audited, nothing is started
Target is a platform administrator and the caller is not 403 (rank guard — no privilege escalation)
Target's role is at or above the caller's — a tenant-administrator may impersonate only users whose role it could assign (never another tenant-administrator; only a platform administrator can) 403 (out-rank rule, the same as for every other action on another user). Re-checked on every request, so an impersonation started before the rule ends on its next request
Target is in a different tenant than a tenant-administrator caller 404 (tenant scope; same body as an unknown id, and both audited as impersonation.denied with status 404 and the requested id as entity)
Target is the shared demo user, or the caller is 403 (the demo ghost is never an actor or a target)
Target is the caller themselves 403 (no self-impersonation)
reason absent, null, blank or only invisible characters 400 { "error": "a reason is required", "code": "reason_required" }; audited as impersonation.denied (status 400) with the target's tenant. Checked after the target and permission checks, so the existing refusal codes above are unchanged
reason not a string, not valid UTF-8, containing control or format characters, or longer than 500 characters 400 { "code": "invalid_reason" }; audited as impersonation.denied
The target's tenant has turned impersonation off (impersonation_allowed = 0, see Tenants); applies to platform administrators too 403 { "code": "impersonation_disabled" }; audited as impersonation.denied with the target's tenant. Checked after reason validation
The tenant policy cannot be read (database fault) 503; fail-closed, no cookie
Target does not exist (an id that differs from a real user id only in letter case counts as not existing: the id is matched byte-exact, so a session is only ever started and audited under the stored user id; the impersonation.denied row records the id as it was requested), or its organisation was purged while the request was in flight 404 ({ "error": "not found" }; audited as impersonation.denied with status 404)
aig_admin (start) or aig_imp / aig_admin (stop) appears more than once in the Cookie header, or the header is malformed 400 { "error": "ambiguous session cookie", "code": "ambiguous_cookie" } — no cookie is issued. On stop the aig_imp cookie is still cleared (stop never leaves you stuck) but no server-side record is ended. Cookies are matched by exact name (x_aig_admin is never read as aig_admin) and empty values are ignored
Already impersonating (no nesting) 409 — stop first
Backing-store fault, or the durable impersonation.start audit write fails 503 / 500 — no cookie is issued (fail-closed)

A tampered, forged, expired, or replayed-after-stop aig_imp cookie is silently ignored: the request is served as the operator's own session and GET /admin/auth/me reports no impersonating block — a forged cookie can never fabricate an impersonated identity.

While impersonating: the admin-auth surface

To avoid editing the wrong account, PATCH /admin/auth/me (self-profile update) returns 409 while impersonating — the operator must stop first (the SPA tolerates this on its background one-shot-flag writes). POST /admin/auth/logout (and SAML single-logout) always clear both the aig_admin and aig_imp cookies, so logging out never leaves an orphaned impersonation cookie.


Personal data is refused

Impersonation exists for support, not for reading a user's private content. While impersonating, every personal-data admin route is refused with 403 { "error": "impersonation_forbidden", "code": "impersonation_forbidden" } — the refusal is the first thing each handler does, before any lookup, so it holds for reads and act-as writes. (GDPR: an administrator must not be able to read or export an employee's private data by "viewing as" them.) One exception to the order: GET /me/security first answers its 404 when the viewed person is not on the password_mfa sign-in (as for anyone else), and only then the 403 (account security).

Refused while impersonating (representative — the guard covers every route in these areas):

Area Examples
Conversations list / search (POST /conversations/search and the deprecated GET) / single / comments / live session; messages, attachments, images, knowledge files including download
Memories list / create / reorder / feedback
Personal PII keywords & export GET/POST /me/pii-keywords, GET /me/export
Personal API tokens & devices GET/POST /me/tokens, DELETE /me/tokens/{id}, /me/device-token, device families
Slash commands personal /chat-commands (incl. POST /chat-commands/search) and /me/shared-commands
Feedback per-conversation feedback / summaries, GET /my-feedback
Billing & wallet /billing/*, /billing/wallet/*
Approvals /me/approvals*
Scheduled tasks /scheduled-tasks*
Tenant knowledge /tenant-knowledge*, /me/tenant-knowledge*
Prompt library (member picker) GET /me/tenant-prompts
MCP connectors /mcp* including GET /mcp/{id}/credential and /mcp/{id}/call
Projects project conversations / feed / knowledge (incl. download), and project / membership / knowledge mutations
Self-destruct DELETE /me, DELETE /me/erase
Sign-in security GET /me/security (password, second factors, recovery codes left)

Still available for support (role / plan / access context, never private content): GET /me/roles, GET /me/groups, GET /projects (membership list) and GET /projects/{id}/members/candidates, GET /mcp/catalog, and the FEEDBACK_TRIAGE-gated /feedback triage routes.

GET /admin/auth/me masks the target's personal fields

While impersonating, GET /admin/auth/me returns the target's account for support (role, permissions, plan, tenant & branding config, feature gates) but masks or omits the target's personal fields: the email is masked (a***@domain, keeping the domain); name, preferred_name, work_category, model_instructions, default_model, the account-creation time and the workspace identifier tenant_slug (a self-service workspace's is derived from its owner's email address) are omitted; and favorite_models, failing_runs, expiring_tokens, handover_pending, protection_paused and config_approval_outcomes are returned empty. The target email shown in the impersonating banner block is masked the same way.

Run content is not the owner's view

Under impersonation the session user is the target, but the impersonating administrator is never treated as the owner of the target's content. On the agent run detail (GET .../agents/{id}/runs/{run}) and the delegation steps route the result and result_expired fields are absent, and the trace steps are cut to metadata unless the viewed user holds REQUEST_LOGS_VIEW and the request carries a valid X-Read-Reason; that read is audited with both ids (impersonator_id). On a workflow run the outputs of the steps stay withheld in a run that handled personal data, as for any non-owner. On the runs list (GET .../agents/{id}/runs) the question field is absent on every row. The session still opens the run (200) for support: only the private content is held back.

GET /admin/v1/me/notifications (the bell and banner re-poll) masks exactly like /me: it is built by the same code, so the four personal lists are [] (not even read) and budget alerts are masked the same way.

A CI lint (scripts/lint_impersonation_personal_guard.sh) fails the build if a new personal-data route is added to a guarded file without the guard (or an explicit, justified exemption), so the boundary cannot silently drift. Note: these impersonation_forbidden refusals are expected in the error-triage queue (they are the control working), not regressions.


Durable credentials are blocked

Creating any durable credential or persistent out-of-band effect is refused with 403 impersonation_forbidden while impersonating, because it would live on a plane the aig_imp cookie does not gate — it would survive Stop (defeating stop-revocation) and be usable out-of-band with no per-use audit. Refusing every such site keeps every act-as action on the cookie plane, which is stop-revocable and audited with both identities. The blocked sites are:

Method Path What it would mint
POST /admin/v1/playground/token short-lived inference bearer (chat / agents / playground)
POST /admin/v1/me/tokens the caller's persistent inference API token
POST /admin/v1/users/{id}/tokens a user's persistent inference API token
POST /admin/v1/gateways/{id}/tokens a gateway inference token
POST /admin/v1/tenants/{id}/scim-credential the tenant's SCIM provisioning bearer
POST /admin/v1/conversations/{id}/share a public /shared/{token} conversation link
POST /admin/v1/gateways/{gw}/agents/{id}/webhook-triggers a public /hooks/{token} agent trigger + secret
POST /admin/v1/gateways/{gw}/workflows/{id}/webhook a public /hooks/{token} workflow trigger + secret
POST /admin/v1/gateways/{gw}/workflows/{id}/form (and the PATCH token-regenerate) a public /forms/{token} trigger URL

The platform product-analytics plane is refused while impersonating too — the account-group override (PUT /admin/v1/tenants/{id}/account-group, and the Insights endpoint): no tenant ever sees these numbers, and under impersonation the session carries the target's identity (an administrator may impersonate another administrator), so the refusal runs before the permission check with the same typed 403 impersonation_forbidden. It is enforced by its own drift lint, scripts/lint_impersonation_insights_guard.sh.

A CI lint (scripts/lint_impersonation_mint_guard.sh) fails the build if a new secret-minting admin route is added without this guard, so the boundary cannot silently drift. Consequently the chat composer is read-only while viewing as a user. Opening a chat trips the refused token mint and shows a banner; the chat app ships the localised text Chat is unavailable while you are viewing the app as this user. Use "Stop viewing as user" to chat again. — the refusal carries the typed code next to the legacy error string ({ "error": "impersonation_forbidden", "code": "impersonation_forbidden" }), and every other refused mint (personal tokens, SCIM credentials, share links) carries the same pair — see Error codes. (Full act-as inference is out of scope for this capability.)


Tenant switch and notice to the target

Each tenant has an impersonation_allowed switch (default on). While it is off, no administrator can start an impersonation of that tenant's users. The switch is re-checked on every request of a running session: turning it off ends an impersonation already in progress on its next request, and an unreadable policy ends the session as well (fail-closed).

After a successful start the target receives a notice by email (best-effort, sent in the background, in the target's language): who started the session, when, until when, and the stated reason. A missing address or a mail failure is logged and never blocks or fails the start; the audit log is the durable record. There is no in-app notice and no retry.

Audit trail (both identities)

Every impersonated action records both the real administrator (actor) and the target:

  • impersonation.start — written before the cookie is issued; if this durable write fails, no token is granted.
  • impersonation.action — written ahead of every impersonated mutation (actor_id = the real administrator, entity_id = the target, plus method/path). If this write fails, the mutation is refused with 503 { "error": "temporarily unavailable; retry later" } (nothing was written — the mutation never ran; retry) — no impersonated mutation is ever performed unaudited. The read-only search POSTs (/conversations/search, /chat-commands/search, /users/search, …, see Search and lookup values travel in the request body) only carry their search term in the body; they are reads and are treated like a GET here.
  • impersonation.denied — a refused start attempt (the lateral-movement signal).
  • impersonation.stop — impersonation ended: written only when the stop call actually ended an active record (a repeated stop, or one carrying another administrator's impersonation id, ends nothing and writes nothing).
  • impersonation.stop_failed — the stop could not end the record (database fault, answered 503 or 500 impersonation_stop_failed); the cookie is still cleared and the record stays active until its expiry.

Atomic with the record. The impersonation record and its audit row are written in one database transaction: a start answers 200 only when both the record and the impersonation.start row committed, and a stop reports the record ended only when the impersonation.stop row committed with it. If the audit row cannot be written, neither change is kept: a failed start leaves no record (and no notice mail), a failed stop leaves the record active until its expires_at (at most 30 minutes; the cookie is cleared, so the client does not retry). The stop_failed row and the server error log are the signal. A start or stop that waited on a database lock (for example a concurrent tenant purge) and timed out answers 503 with nothing written. Any other write fault answers 500 (start: could not start impersonation; stop: internal error with code impersonation_stop_failed) and may have written nothing or everything: re-read before repeating.

A permission denial (403) that occurs during impersonation is attributed to the real administrator, with the target as the entity. See Audit log.

Impersonation session records are kept for 730 days after they started and then deleted; erasing the administrator or the target keeps the records younger than 730 days (the erased person's account no longer exists; the record keeps only its id), and ends any still-open session.