ReskSafety · Documentation

Self-hosted LLM firewall

ReskSafety is the deployable part of the RESK stack: an OpenAI- and Anthropic-compatible firewall you host yourself, with capability-based RBAC, editable policies, optional logits-level filtering and reversible masking of secrets and PII.

  • Version 0.1.1
  • FastAPI + React
  • Python 3.11+
  • Apache-2.0

What it is

ReskSafety sits between your application and an LLM provider. Applications keep calling a familiar chat API; RESK decides what is allowed to leave, what the model is allowed to emit, and records what happened.

Architecture

client / agent / SDK
        │  Bearer JWT · cookie · x-api-key
        ▼
┌──────────────────────────────────────────────┐
│ ReskSafety backend (FastAPI :8000)           │
│                                              │
│  auth ─▶ RBAC mask ─▶ policy compile         │
│            │                                 │
│            ├─ input scans (injection, jailbreak, banned phrases)
│            ├─ ENV Match  (secrets/PII → flags)
│            ├─ provider routing (X-Provider-Id)
│            ├─ upstream call ─▶ OpenAI / vLLM / Ollama / Anthropic
│            ├─ output filter · logits (local)
│            └─ ENV Match restore (flags → values)
│                                              │
│  SQLAlchemy ─▶ PostgreSQL (or SQLite)        │
└──────────────────────────────────────────────┘
        ▲
        │ admin console (React :3000)
        └─ users · roles · policies · providers · sessions · logs

Quick start

Docker Compose (production shape)

git clone https://github.com/Resk-Security/ReskSafety.git resk
cd resk

cat > .env <<'EOF'
JWT_SECRET_KEY=$(openssl rand -hex 32)
CSRF_SECRET=$(openssl rand -hex 32)
PROVIDER_ENCRYPTION_KEY=$(openssl rand -base64 32)
DB_PASSWORD=$(openssl rand -hex 16)
LLM_BACKEND_URL=https://api.openai.com/v1
LLM_BACKEND_API_KEY=sk-...
EOF

docker compose up -d --build

Backend on http://localhost:8000, console on http://localhost:3000, PostgreSQL in the db service. The first startup seeds the schema, an admin account with password changeme, the capability catalogue and default roles — change that password immediately.

Local development

./start.sh        # creates backend/.venv, seeds SQLite, starts FastAPI + Vite

Check that the backend is alive:

curl -s http://localhost:8000/health

Endpoints

EndpointPurpose
POST /v1/chat/completionsOpenAI-compatible chat with policy enforcement (streaming supported)
POST /v1/chat/completions/batchSubmit tool results and get the model's continuation
POST /v1/messagesAnthropic Messages API, for the Anthropic SDK (x-api-key)
POST /v1/tokenizeInspect tokenisation and the banned phrases a policy would apply
GET /v1/modelsOpenAI-compatible model listing
GET /healthLiveness probe
POST /api/auth/loginConsole login (JWT cookie + CSRF token)
/api/users, /api/roles, /api/policies, /api/providersAdmin CRUD used by the console
GET /api/admin/stats, /api/admin/logsSupervision and audit

The security layers, in order

  1. Authentication — JWT cookie for the console, bearer token or x-api-key for API clients. A user's roles are resolved on every request.

  2. RBAC — the merged capability mask is checked against what the request asks for. Tool calling requires bit 0; PII access is its own bit.

  3. Policy compilation — banned phrases, jailbreak patterns and logit rules are compiled once per request for the active policies.

  4. Input screening — resk2 semantic scanning (configurable per policy), jailbreak substring list and policy phrase matching. A hit returns 403 and is logged.

  5. ENV Match — secrets and PII are replaced by stable flags before the payload leaves the process. See ENV Match.

  6. Generation — provider call, or in-process generation with resklogits when the backend is local. Token bans happen during decoding.

  7. Output control — post-filtering for distant providers; for local generation the logits processor already prevented banned tokens. ENV Match restores flags in the text and tool arguments.

  8. Audit — status, model, backend, policy, blocked phrase, masked prompt hash and request metadata are persisted.

Limits and license

Where to go next

Firewall API

Request shapes, provider routing, status codes and the exact enforcement order.

Deployment

Every environment variable, secrets, TLS, backups and the production checklist.

ENV Match

Reversible masking of API keys, digests, emails, phones and card numbers.