plugins/admin
The operator API under /admin: users, sessions, MFA, organizations, the audit trail, audit drains,
statistics, operator grants and operator API keys (pak_…), for a dashboard, a support tool or an
integration. Every operator action is recorded in the audit trail as admin.<action>. It
needs plugins/audit registered too (any order — Init fails without it).
Install
Section titled “Install”import ( "github.com/univeros/polaris.go/plugins/admin" "github.com/univeros/polaris.go/plugins/audit")
cfg, err := polaris.FromEnv(db, audit.New(audit.Config{}), admin.New(admin.Config{}))p, err := polaris.New(cfg)_, err = p.Migrate(ctx) // creates polaris_admin_grant, polaris_admin_key (and audit's tables)
// the first operator (or CLI: polaris admin:grant <email> <role>, polaris admin:key <name> <role>)_, err = admin.Of(p.Graph()).Grants().Grant(ctx, admin.Grant{UserID: id, Role: admin.RoleOwner})_, secret, err := admin.Of(p.Graph()).Keys().Create(ctx, admin.Key{Name: "dashboard", Role: admin.RoleViewer})// secret is shown once: send it as "Authorization: Bearer pak_…"Config
Section titled “Config”admin.Config{} has no options: the zero value is the full behaviour.
Operators
Section titled “Operators”A caller is an admin.Principal: a user with core’s superadmin role (owner on the instance, no
grant), a user with a live admin.Grant (one per user: role, scope, optional expiry) calling with
their access token, or an admin.Key (pak_, role, scope, optional IP allowlist and expiry, stored
as a keyed hash). Scope is admin.ScopeInstance or one organization id; an organization-scoped
operator acts on that organization only. Roles, each including the ones before it:
| Role | Adds capability |
|---|---|
RoleViewer | Read: users, sessions, MFA, organizations, audit, stats |
RoleSupport | Support: revoke sessions |
RoleAdmin | Manage (ban, passwords, MFA, member roles, deletions), Impersonate |
RoleOwner | Own: grants, operator keys, drains, other plugins’ /admin routes |
Manage on an account (ban, unban, password, MFA removal and reset, delete) stops at operators:
an operator below RoleOwner gets 403 admin/forbidden when the account is a superadmin’s or
belongs to an operator whose grant is of the caller’s role or above. Only an owner manages those.
Routes
Section titled “Routes”| Method | Path | Purpose |
|---|---|---|
| GET | /admin/users, /admin/users/{id} | list (filters email, status) / read users |
| POST | /admin/users/{id}/ban, /admin/users/{id}/unban | disable / enable an account (Manage) |
| POST | /admin/users/{id}/password | set a user’s password (Manage) |
| DELETE | /admin/users/{id} | delete a user (Manage) |
| POST | /admin/users/{id}/impersonate | access token for the user, no session (Impersonate) |
| GET, DELETE | /admin/users/{id}/sessions | list / revoke every session (Support to revoke) |
| DELETE | /admin/users/{id}/sessions/{sessionId} | revoke one session (Support) |
| GET, DELETE | /admin/users/{id}/mfa | list factors / reset MFA (Manage to reset) |
| DELETE | /admin/users/{id}/mfa/{factorId} | remove one factor (Manage) |
| GET | /admin/organizations, /admin/organizations/{id} | list / read organizations |
| DELETE | /admin/organizations/{id} | delete an organization (Manage) |
| PATCH | /admin/organizations/{id}/members/{userId}/roles | set a member’s roles (Manage) |
| GET, POST | /admin/organizations/{id}/drains | list / create audit drains (Own to create) |
| DELETE | /admin/organizations/{id}/drains/{drainId} | delete a drain (Own) |
| POST | /admin/organizations/{id}/drains/{drainId}/test | send a test delivery (Own) |
| GET | /admin/audit | query the audit trail |
| GET | /admin/stats | instance statistics |
| GET, POST | /admin/keys | list / create operator API keys (Own) |
| DELETE | /admin/keys/{id} | delete a key, effective at once (Own) |
| GET, POST | /admin/grants | list / create operator grants (Own) |
| DELETE | /admin/grants/{id} | revoke a grant (Own) |
Lists are cursor-paginated: cursor (the previous page’s next_cursor), limit (a positive
integer written in digits only, default admin.DefaultLimit, at most admin.MaxLimit; 1.5,
1e1 or 2 answer 422). Times are RFC 3339 in UTC (2026-09-11T10:00:00Z); a time sent with an
offset is accepted and answered in UTC.
Events and permissions
Section titled “Events and permissions”Records one audit name per action (admin.AuditUserBanned … admin.AuditGrantDeleted, added to the
catalog by Plugin.AuditNames); routes that change core state also emit core’s event
(user.disabled, user.deleted, org.deleted, mfa.factor_removed, …). Contributes no core
permissions: access is the role matrix above, not RBAC.
Problems
Section titled “Problems”https://polaris.univeros.io/problems/admin/unauthorized (401, no operator, lapsed grant or key),
…/admin/forbidden (403, role or scope too small), …/admin/impersonation_denied (403, an
impersonation token), …/admin/not_found (404), …/admin/conflict (409),
…/admin/invalid_input (422, errors lists the fields), …/audit/invalid_query (422, /admin/audit).
Host integration
Section titled “Host integration”- Erasing a user deletes its operator grant inside the erasure’s transaction (
wiring.UserEraser). - An impersonation token carries
amr ["impersonation"], noauth_time, and theadmin.ClaimImpersonatedBy/admin.ClaimImpersonatorTypeclaims; it cannot be refreshed and is never an operator. It reads as the user and does what the user’s permissions allow, but it is not the account holder: every route that needs no permission and writes, destroys or is a step-up route answers 403 (pipeline.DeniesImpersonation: password, factors, passkeys, API keys, sessions, organizations created or joined, deletion).token.Token.ImpersonatedByreads the claim in your own handlers, and audit rows written while serving such a token carryimpersonated_by. A superadmin cannot be impersonated, and belowRoleOwnerneither can an operator of the caller’s role or above (the reach rule above). - A session an organization’s identity provider opened (
plugins/sso,Principal.OrganizationBound) is never an operator:/adminanswers it 401 whatever grant or role its user holds. Operators sign in to the account itself. - An organization-scoped owner grants roles on its organization, to users who hold no grant or one
on that organization. Replacing a grant on the instance or on another organization, or granting
to a superadmin, is for an instance owner (403
admin/forbidden). - A drain’s
endpointis an https URL of a public host without credentials; a literal private, loopback or link-local address andlocalhostare refused (422), and delivery itself connects to public addresses only (plugins/audit).last_erroris a category:refused,timeout,unreachableorHTTP <status>. - Your own admin route: declare it with tag
admin.Tagandauth: public, then start the endpoint withop, res, ok := admin.Authorize(ctx, admin.Own, orgID)and record withadmin.Of(g).Record(ctx, name, op, subjectID, orgID, data). - Outside
/admin:Plugin.OperatorOf(r),Plugin.IsOperator(ctx, credential),Plugin.Resolve(ctx, bearer, ip). A plugin that does not import this package type-assertsg.Plugin("admin")to an interface withAuthorizeOperator/OperatorID. - An operator’s access token is checked against the denylist when enabled (a session that ended is
no operator’s);
a drain’s
filtermust be a JSON list; dates are ISO 8601 only. - One grant per user is enforced by the database (
polaris_admin_grant_user_uniqueonuser_id): a grant replaces the user’s previous one, and of two concurrent first grants the second is applied as that replacement. A database from v0.4.1 or earlier may already hold two grants for one user (only that race made them);Migratethen stops with an error namingpolaris_admin_grantanduser_id. List them withSELECT user_id, id, role, scope FROM polaris_admin_grant WHERE user_id IN (SELECT user_id FROM polaris_admin_grant GROUP BY user_id HAVING COUNT(*) > 1), revoke the grants you do not want (DELETE /admin/grants/{id}orGrants().Revoke(ctx, id)) and runMigrateagain.
Example
Section titled “Example”Example in example_test.go — go doc github.com/univeros/polaris.go/plugins/admin.