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
| Module | Routes | Responsibility |
|---|---|---|
sessions | /api/v1/sessions | Sign-in, current session, sign-out, password change |
members, invitations | /api/v1/members, /api/v1/invitations | Membership administration, invitations, first sign-in |
agents | /api/v1/agents | Register, list, suspend, resume, revoke, rotate |
policies | /api/v1/policies | Create policies and append immutable versions |
approvals | /api/v1/approvals | List pending requests, approve, reject |
events | /api/v1/events, /api/v1/events/stream | Redacted events, server-sent event stream |
audit | /api/v1/audit | Hash-chain links and head exports |
incidents | /api/v1/incidents | Behavioral incidents |
alerts | /api/v1/alerts | Content-analysis alerts and their status |
evidence | /api/v1/evidence | Hash-verified evidence bundles from MinIO |
metrics | /api/v1/metrics/reliability | Per-tool reliability from relay minute rows |
chaos | /api/v1/chaos | Run catalog scenarios against gateway behavior |
health | /health/live, /health/ready | Liveness and database readiness |
The full contract is in the Control plane API reference.
Request pipeline
Every request passes through, in order:
- Metrics middleware. Counts requests by method, matched route pattern, and status.
- Security headers.
nosniff,X-Frame-Options: DENY,Referrer-Policy: no-referrer,Cache-Control: no-store. - Agent credential rejection. Any
/api/request withX-AgentShield-SignatureorX-AgentShield-Agent-Idreturns401("agent signatures are not accepted on the control plane"). - JSON body parser limited to 256 KiB. Larger bodies return
413. HumanSessionGuard. ResolvesAuthorization: Bearer <token>by its SHA-256 throughagentshield_resolve_session. A session with a pending temporary password is limited to a few routes.RolesGuard. Checks the route's@Roles(...)against the member's role.- 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:
| Change | Event type |
|---|---|
| Agent registered, suspended, resumed, revoked | agent.registered, agent.suspended, agent.resumed, agent.revoked |
| Credential rotated | credential.rotated |
| Approval approved or rejected | approval.decided |
| Alert acknowledged or resolved | alert.acknowledged, alert.resolved |
| Evidence read | evidence.viewed, or evidence.integrity_failed on a hash mismatch |
| Member added, invited, role or status changed, password changed | member.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.
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.
Implementation references
Was this page helpful?