Production infrastructure for AI agents
Website · Documentation · Guides · Core · Template · Discord
systemprompt-security
Security infrastructure for systemprompt.io AI governance: JWT, OAuth2 token extraction, scope enforcement, the four-layer tool-call governance pipeline, the unified authz decision plane (deny-overrides resolver + AuthzDecisionHook) shared by gateway and MCP enforcement, Ed25519 bridge manifest signing, and bot/scanner detection.
Layer: Infra — infrastructure primitives (database, security, events, etc.) consumed by domain crates. Part of the systemprompt-core workspace.
Overview
This crate provides security primitives for the systemprompt.io platform. It handles JWT token generation and validation, multi-method token extraction, the unified authorization decision plane (resolver, repository, hook surface, audit sinks), Ed25519 manifest signing for the bridge, and bot/scanner classification.
Architecture
src/
├── lib.rs # Module exports and public API
├── error.rs # AuthError, JwtError, ManifestSigningError
├── manifest_signing.rs # Ed25519 signing + RFC 8785 JCS canonicalisation
├── auth/
│ ├── mod.rs # Auth module re-exports
│ ├── validation.rs # AuthValidationService, AuthMode
│ └── hook_token.rs # HookTokenValidator, ValidatedHookClaims
├── extraction/
│ ├── mod.rs # Extraction module re-exports
│ ├── token.rs # TokenExtractor with fallback chain
│ ├── header.rs # HeaderExtractor/HeaderInjector for context propagation
│ └── cookie.rs # CookieExtractor for cookie-based auth
├── jwt/
│ └── mod.rs # JwtService for admin token generation
├── session/
│ ├── mod.rs # Session module re-exports
│ ├── generator.rs # SessionGenerator for session token creation
│ └── claims.rs # ValidatedSessionClaims data structure
├── services/
│ ├── mod.rs # Services module re-exports
│ └── scanner.rs # ScannerDetector for bot detection
└── authz/
├── mod.rs # Authz module re-exports
├── config.rs # AccessControlConfig, RuleEntry, DepartmentEntry
├── error.rs # AuthzError, AuthzBootstrapError
├── extension.rs # AuthzExtension (registers schemas + migrations)
├── hook.rs # AuthzDecisionHook trait + Allow/Deny/Webhook impls
├── ingestion.rs # AccessControlIngestionService
├── repository.rs # AccessControlRepository, UpsertRuleParams
├── resolver.rs # Deny-overrides resolve() entrypoint
├── runtime.rs # global_hook / install_global_hook
├── types.rs # Access, AccessRule, AuthzDecision, AuthzRequest, EntityKind
├── audit/
│ ├── mod.rs # AuthzAuditSink, AuthzSource
│ ├── db_sink.rs # DbAuditSink (Postgres)
│ └── repository.rs # GovernanceDecisionRepository, insert_governance_decision
└── schema/ # SQL DDL + migrations
auth
Authentication validation with configurable enforcement modes plus bridge hook-token verification.
| Export | Type | Purpose |
|---|---|---|
AuthValidationService |
Struct | Validates JWT tokens and constructs RequestContext |
AuthMode |
Enum | Required, Optional, Disabled enforcement levels |
HookTokenValidator |
Struct | Verifies short-lived hook tokens minted for the bridge |
ValidatedHookClaims |
Struct | Claims extracted from a verified hook token |
extraction
Token extraction from multiple sources with fallback chain support.
| Export | Type | Purpose |
|---|---|---|
TokenExtractor |
Struct | Extracts tokens from headers/cookies with configurable fallback |
ExtractionMethod |
Enum | AuthorizationHeader, McpProxyHeader, Cookie |
TokenExtractionError |
Enum | Specific error types for extraction failures |
HeaderExtractor |
Struct | Extracts trace_id, context_id, agent_name from headers |
HeaderInjector |
Struct | Injects RequestContext fields into outgoing headers |
HeaderInjectionError |
Struct | Error type for header injection failures |
CookieExtractor |
Struct | Dedicated cookie-based token extraction |
CookieExtractionError |
Enum | Cookie-specific error types |
jwt
JWT token generation for administrative access.
| Export | Type | Purpose |
|---|---|---|
JwtService |
Struct | Generates admin JWT tokens with HS256 |
AdminTokenParams |
Struct | Configuration for admin token creation |
services
Security services for request classification.
| Export | Type | Purpose |
|---|---|---|
ScannerDetector |
Struct | Detects bot/scanner requests by path, user-agent, velocity |
session
Session token generation and claim validation.
| Export | Type | Purpose |
|---|---|---|
SessionGenerator |
Struct | Generates session-scoped JWT tokens |
SessionParams |
Struct | Configuration for session token creation |
ValidatedSessionClaims |
Struct | Extracted claims after JWT validation |
authz
Unified authorization decision plane shared by the gateway /v1/messages proxy and the MCP RBAC middleware.
| Export | Type | Purpose |
|---|---|---|
resolve |
Fn | Deny-overrides resolver against access_control_rules |
AuthzDecisionHook |
Trait | Pluggable decision surface installed as a global hook |
AllowAllHook / DenyAllHook / WebhookHook |
Struct | Built-in AuthzDecisionHook implementations |
AccessControlRepository |
Struct | CRUD over access_control_rules |
AccessControlIngestionService |
Struct | Loads rule sets from configuration |
AuthzExtension |
Struct | Registers schemas and migrations via the extension framework |
AuthzAuditSink / DbAuditSink / NullAuditSink |
Trait + impls | Sinks for governance decision audit records |
GovernanceDecisionRepository |
Struct | Reads governance_decisions audit rows |
Access / AccessRule / AuthzDecision / AuthzRequest / Decision / EntityKind / RuleType |
Types | Authz request and decision data model |
global_hook / install_global_hook / install_from_governance_config / clear_global_hook |
Fns | Process-wide hook installation |
manifest_signing
Ed25519 signing for bridge manifests, keyed independently of the JWT HMAC secret.
| Export | Type | Purpose |
|---|---|---|
sign_value<T: Serialize> |
Fn | RFC 8785 canonicalise + Ed25519 sign |
canonicalize<T: Serialize> |
Fn | RFC 8785 JCS canonical JSON |
signing_key |
Fn | Loads the Ed25519 signing key from manifest_signing_secret_seed |
Usage
[]
= "0.9.2"
Token Extraction
use ;
let extractor = standard;
let token = extractor.extract?;
let browser_extractor = browser_only
.with_cookie_name;
Authentication Validation
use ;
let service = new;
let context = service.validate_request?;
Admin Token Generation
use ;
let params = AdminTokenParams ;
let token = generate_admin_token?;
Session Token Generation
use ;
use ;
let generator = new;
let params = SessionParams ;
let token = generator.generate?;
Dependencies
| Crate | Purpose |
|---|---|
systemprompt-models |
Shared models (JwtClaims, UserType, Permission) |
systemprompt-identifiers |
Typed identifiers (UserId, SessionId, TraceId) |
systemprompt-config |
Profile and secrets access for signing keys |
systemprompt-database |
DbPool for authz repositories and audit sinks |
systemprompt-extension |
Extension trait used by AuthzExtension |
jsonwebtoken |
JWT encoding/decoding with HS256 |
ed25519-dalek + serde_jcs |
Ed25519 signing and RFC 8785 canonical JSON |
axum |
HTTP types (HeaderMap, HeaderValue) |
sqlx |
Authz repository and audit sink queries |
reqwest |
WebhookHook outbound calls |
inventory |
Extension registration |
chrono |
Timestamp handling |
tracing |
Structured logging |
License
BSL-1.1 (Business Source License). Source-available for evaluation, testing, and non-production use. Production use requires a commercial license. Each version converts to Apache 2.0 four years after publication. See LICENSE.
systemprompt.io · Documentation · Guides · Live Demo · Template · crates.io · docs.rs · Discord
Infra layer · Own how your organization uses AI.