Skip to Content
AgentShield
Architecture

Control Plane Architecture

The NestJS management API. Modules, authentication and role guards, organization isolation, and what it owns.

The control plane is the management API for humans. It is the only writer of users, organizations, memberships, agents, credentials, and policy documents, and it records human decisions on approvals and alerts. It is never on the tool-call path.

Modules

ModuleRoutesResponsibility
sessions/api/v1/sessionsSign-in, current session, sign-out, password change
members, invitations/api/v1/members, /api/v1/invitationsMembership administration, invitations, first sign-in
agents/api/v1/agentsRegister, list, suspend, resume, revoke, rotate
policies/api/v1/policiesCreate policies and append immutable versions
approvals/api/v1/approvalsList pending requests, approve, reject
events/api/v1/events, /api/v1/events/streamRedacted events, server-sent event stream
audit/api/v1/auditHash-chain links and head exports
incidents/api/v1/incidentsBehavioral incidents
alerts/api/v1/alertsContent-analysis alerts and their status
evidence/api/v1/evidenceHash-verified evidence bundles from MinIO
metrics/api/v1/metrics/reliabilityPer-tool reliability from relay minute rows
chaos/api/v1/chaosRun catalog scenarios against gateway behavior
health/health/live, /health/readyLiveness and database readiness

The full contract is in the Control plane API reference.

Request pipeline

Every request passes through, in order:

  1. Metrics middleware. Counts requests by method, matched route pattern, and status.
  2. Security headers. nosniff, X-Frame-Options: DENY, Referrer-Policy: no-referrer, Cache-Control: no-store.
  3. Agent credential rejection. Any /api/ request with X-AgentShield-Signature or X-AgentShield-Agent-Id returns 401 ("agent signatures are not accepted on the control plane").
  4. JSON body parser limited to 256 KiB. Larger bodies return 413.
  5. HumanSessionGuard. Resolves Authorization: Bearer <token> by its SHA-256 through agentshield_resolve_session. A session with a pending temporary password is limited to a few routes.
  6. RolesGuard. Checks the route's @Roles(...) against the member's role.
  7. Validation. Request bodies are parsed with strict Zod schemas. Unknown fields fail with 400 validation_failed.

Errors always use the shared envelope: error.code, error.message, and error.request_id. Messages never include stack traces, SQL, or secrets.

Organization isolation

The organization is always taken from the authenticated membership. There is no route that accepts an organization id as a parameter.

When DATABASE_URL connects as agentshield_app, the control plane enforces isolation in the database as well: it sets app.organization_id on each transaction, and row level security policies filter tenant tables by that setting. Login and session resolution, which happen before the organization is known, use narrow SECURITY DEFINER functions. In production, startup is refused unless the app role is in use.

Writes and events

Every state change appends a security event and its audit link in the same transaction:

ChangeEvent type
Agent registered, suspended, resumed, revokedagent.registered, agent.suspended, agent.resumed, agent.revoked
Credential rotatedcredential.rotated
Approval approved or rejectedapproval.decided
Alert acknowledged or resolvedalert.acknowledged, alert.resolved
Evidence readevidence.viewed, or evidence.integrity_failed on a hash mismatch
Member added, invited, role or status changed, password changedmember.added, member.invited, member.invitation_accepted, member.role_changed, member.enabled, member.disabled, member.password_changed

Policies are versioned

POST /api/v1/policies creates a policy and its first immutable version. PUT /api/v1/policies/{policyId} appends a new version and moves current_version_id. Versions cannot be updated or deleted, so every past decision can be traced to the exact document that produced it. An organization may have one active organization policy; each agent may have one active agent policy.

Mail

With SMTP_URL, invitations are emailed as single-use links that expire in 72 hours. In production the mail URL must use smtps:// or require_tls=true, and DASHBOARD_URL must be HTTPS. Without mail, a new member receives a one-time temporary password.

Bootstrap

npm run bootstrap --workspace @agentshield/control-plane (or node apps/control-plane/dist/bootstrap.js in the image) creates the first organization and owner from AGENTSHIELD_BOOTSTRAP_*. There is no public registration route. Bootstrap refuses to run in production mode.

Was this page helpful?

On this page