Security¶
Authentication¶
The AI service does not perform JWT validation directly. Authentication is handled by the IAM service at the gateway layer:
- Client sends request with JWT Bearer token to Nginx gateway
- Nginx forwards the request to
loryth-iamfor validation - IAM validates the token and sets the
X-User-Idheader - The request is forwarded to
loryth-aiwith the trustedX-User-Idheader
All API endpoints that require user context extract the user ID from this header:
Authorization¶
Conversation Ownership¶
- Conversations have an
owner_idfield set at creation - Message append operations validate that
x_user_id == conversation.owner_id - Unauthorized access raises 403 Forbidden
Space Scoping¶
All list queries are scoped by space_id:
GET /conversations?space_id=...POST /conversations/searchrequiresspace_idin body- Embedding vectors are stored with
space_idand filtered during search
This ensures tenants cannot access data from other spaces.
SpacePolicy Feature Gates¶
Each space has a SpacePolicy that controls feature availability:
| Gate | Default | Effect |
|---|---|---|
runs_enabled | true | Allows/blocks run creation |
tool_calls_enabled | true | Allows/blocks tool execution within runs |
ingestion_enabled | true | Allows/blocks web content ingestion |
Safety Limits¶
Per-space safety limits prevent resource abuse:
| Limit | Default | Description |
|---|---|---|
max_model_calls | 12 | Max model API calls per run |
max_tool_calls | 20 | Max tool executions per run |
max_wall_time_s | 120 | Max wall-clock seconds per run |
max_ingest_bytes | 25 MB | Max bytes per ingestion request |
The LoopBreaker detects repeated identical tool calls (threshold: 3) to prevent infinite loops.
Data Protection¶
API Key References¶
Model bindings store api_key_ref — a reference to the key in a secrets manager — not the raw API key. The actual key is resolved at runtime when making provider API calls.
Model Binding Isolation¶
Each ModelBinding belongs to a SpacePolicy, which belongs to a space. A run can only use model bindings configured for its space.
Network Security¶
Service-to-Service Communication¶
All inter-service communication occurs within the Docker network:
- PostgreSQL: Internal port 5432, credentials via environment variables
- RabbitMQ: Internal port 5672, used for async event processing
- MinIO: Internal port 9000, credentials via
MINIO_ACCESS_KEY/MINIO_SECRET_KEY - Nginx Gateway: Only external-facing entry point (port 5000)
Services are not directly accessible from outside the Docker network.
External API Calls¶
Outbound connections to LLM providers (OpenAI, Anthropic) are made from the AI service container. These connections:
- Use HTTPS with TLS verification
- Authenticate with API keys resolved from
api_key_ref - Are subject to per-run safety limits (max calls, max wall time)
Input Validation¶
- All request bodies validated via Pydantic models
- URL length limited to 4096 characters (ingestion)
- Query text limited to 2048 characters (embedding search)
- Embedding search limit capped at 100 results
- Message role restricted to enum values (
user,system,assistant,tool)