systemprompt-users 0.21.1

User management for systemprompt.io AI governance infrastructure. 6-tier RBAC, sessions, IP bans, and role-scoped access control for the MCP governance pipeline.
Documentation

Production infrastructure for AI agents

Website · Documentation · Guides · Core · Template · Discord


systemprompt-users

Crates.io Docs.rs License: BSL-1.1 codecov

Your users, your database, your access rules. Role-based access control (UserRole: Admin, User, Anonymous), sessions, API keys, device certificates, federated identities, and IP bans, all held in your PostgreSQL rather than a third-party directory.

Layer: Domain — business-logic modules that implement systemprompt.io features. Part of the systemprompt-core workspace.

Overview

Capabilities · Compliance

This crate provides user management functionality including:

  • User CRUD operations with typed identifiers
  • Session management (list, end, cleanup, existence checks)
  • Role-based access control with policy-aware promotion/demotion
  • API key issuance, hashing, and verification
  • Device certificate enrollment and rotation
  • IP banning with expiration and metadata tracking
  • Anonymous user lifecycle management and scheduled cleanup
  • Bulk operations and aggregate statistics

Usage

[dependencies]
systemprompt-users = "0.21"
use systemprompt_database::DbPool;
use systemprompt_users::{UserService, UserRole, UserStatus};

let user_service = UserService::new(&db_pool)?;

let user = user_service.find_by_email("user@example.com").await?;

let admins = user_service.find_by_role(UserRole::Admin).await?;

let stats = user_service.get_stats().await?;

Module Layout

Module Purpose
models/ User, UserSession, UserActivity, UserStats, UserApiKey, UserDeviceCert, and related records.
repository/ Compile-time-verified persistence: user/ (find, list, stats, operations, merge, session), api_key, device_cert, federated_identity, and banned_ip/.
services/ UserService (primary), UserAdminService, ApiKeyService, and DeviceCertService.
jobs/ CleanupAnonymousUsersJob scheduled anonymous-user cleanup.

Schema DDL lives in schema/*.sql (users, user_sessions, user_api_keys, user_device_certs, federated_identities, banned_ips, and the analytics views) with migrations in schema/migrations/.

Public Exports

Models

  • User — Core user entity with id, name, email, roles, status
  • UserSession — Session with timestamps and device info
  • UserActivity — User activity summary (last active, counts)
  • UserWithSessions — User with active session count
  • UserStats — Aggregate statistics (totals, breakdowns)
  • UserCountBreakdown — Counts by status and role
  • UserApiKey — Stored API key record
  • NewApiKey — Plaintext key returned at issuance
  • UserDeviceCert — Stored device certificate record
  • UserExport — Export-friendly user representation

Enums

  • UserStatus — Active, Suspended, Deleted (re-exported from systemprompt-models)
  • UserRole — Admin, User, Anonymous (re-exported from systemprompt-models)

Services

  • UserService — Primary service implementing UserProvider and RoleProvider
  • UserAdminService — Admin operations (promote, demote)
  • ApiKeyService — Issue, hash, and verify API keys
  • DeviceCertService — Enroll and rotate device certificates

Repositories

  • UserRepository — User database operations
  • BannedIpRepository — IP ban management

Types

  • UpdateUserParams — Multi-field user update struct
  • MergeResult — Result of merging two users
  • IssueApiKeyParams — Parameters for ApiKeyService::issue
  • EnrollDeviceCertServiceParams — Parameters for DeviceCertService::enroll
  • CreateApiKeyParams — Repository-level API key creation parameters
  • EnrollDeviceCertParams — Repository-level device cert parameters
  • BanDuration — Hours, Days, or Permanent
  • BanIpParams — Basic ban parameters
  • BanIpWithMetadataParams — Ban with offense tracking
  • BannedIp — Active ban record
  • PromoteResult / DemoteResult — Outcomes of admin role transitions
  • API_KEY_PREFIX — Canonical user-facing key prefix

Extension

  • UsersExtension — Schema and job registration entry point

Traits (re-exported)

  • UserProvider — User lookup and creation
  • RoleProvider — Role management

Error Handling

  • UserError — Domain-specific errors (NotFound, EmailAlreadyExists, …)
  • Result<T> / UserResult<T> — Aliases for std::result::Result<T, UserError>

Dependencies

Crate Purpose
systemprompt-database DbPool for database access
systemprompt-extension Extension trait for schema/job registration
systemprompt-traits UserProvider, RoleProvider, Job traits
systemprompt-identifiers UserId, SessionId typed identifiers (sqlx feature)
systemprompt-models UserRole, UserStatus enums
systemprompt-provider-contracts Job registration macro

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

Domain layer · Own how your organization uses AI.