Skip to content

Commit 4999772

Browse files
fylornclaude
andcommitted
feat: dynamic config, setup wizard, API key lifecycle, observability, and security hardening
Major platform improvements across all layers: Backend: - Dynamic configuration system (system_settings table + DynamicConfig service + Redis Pub/Sub sync) - First-run setup wizard API (POST /api/setup/initialize with rate limiting and race condition protection) - API key lifecycle: rotation with grace period, inactivity timeout, auto-disable, background enforcement task - Prometheus metrics endpoint (GET /metrics on gateway port) - Enhanced health checks (/health/live, /health/ready with 503 on failure, /api/health with latency stats) - Three-state circuit breaker (Closed → Open → HalfOpen) with metrics - Retry with exponential backoff and jitter - Data retention background task (daily cleanup of expired records) - Settings CRUD API (GET/PATCH /api/admin/settings) with input validation Security: - JWT secret minimum 32 chars with entropy check, 30s clock skew leeway - CSP headers on console port - Startup dependency validation (PG/Redis/keys) with clear error messages - Setup endpoint rate limiting (5/min) and DB double-check against race conditions - Team membership validation on API key creation - Content filter pattern validation (500 max, severity enum, size limits) - PII pattern regex compilation check (100 max, 1000 char limit) - Soft-delete for users/providers/api_keys (deleted_at column) - API key auth supports rotation grace period + deleted_at filter - Account deletion changed to soft-delete with session revocation Frontend: - Setup wizard page (5-step onboarding with i18n) - Editable settings page (7 tabs: General, Auth, Gateway, Security, Budget, API Keys, Data) - API key lifecycle UI (rotate, edit, status badges, expiry warnings, expiring-soon filter) Testing: - 121 backend tests (config validation, settings validation, JWT TTL, content filter, PII redactor, retry) - 25 frontend tests across 5 files (setup wizard, API keys, settings, API client, login) Documentation: - Updated all 16 doc files (README, architecture, API reference, configuration, security, deployment guide) - New: secret-rotation.md, rewritten web/README.md - Updated .env examples with dynamic config notes Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fe202c9 commit 4999772

63 files changed

Lines changed: 6671 additions & 520 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.env.example‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
DATABASE_URL=postgres://postgres:postgres@localhost:5432/agent_bastion
22
REDIS_URL=redis://:devredispass@localhost:6379
3-
JWT_SECRET= # REQUIRED: openssl rand -hex 32
4-
ENCRYPTION_KEY= # REQUIRED: openssl rand -hex 32
3+
JWT_SECRET= # REQUIRED: min 32 chars, openssl rand -hex 32
4+
ENCRYPTION_KEY= # REQUIRED: exactly 64 hex chars, openssl rand -hex 32
55
SERVER_HOST=0.0.0.0
66
GATEWAY_PORT=3000
77
CONSOLE_PORT=3001
@@ -12,11 +12,20 @@ RUST_LOG=info,agent_bastion=debug
1212
QUICKWIT_URL=http://localhost:7280
1313
QUICKWIT_INDEX=audit_logs
1414

15-
# Log forwarding (Syslog, Kafka, Webhook) is now configured via the Web UI
16-
# Navigate to Admin > Log Forwarding in the console
17-
1815
# OIDC / SSO (Zitadel dev instance)
1916
OIDC_ISSUER_URL=http://localhost:8080
2017
OIDC_CLIENT_ID=
2118
OIDC_CLIENT_SECRET=
2219
OIDC_REDIRECT_URL=http://localhost:3001/api/auth/sso/callback
20+
21+
# --- Dynamic Settings (configured via Web UI after first run) ---
22+
# The following are now managed through Admin > Settings in the console:
23+
# - JWT access/refresh token TTLs
24+
# - Response cache TTL
25+
# - Content filter patterns
26+
# - PII redactor patterns
27+
# - Budget alert thresholds & webhook URL
28+
# - API key policies (default expiry, rotation, inactivity timeout)
29+
# - Data retention policies
30+
# - Signature verification parameters
31+
# Log forwarding (Syslog, Kafka, Webhook) is configured via Admin > Log Forwarding

‎.env.production.example‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22
# Copy to .env.production and fill in ALL values before deploying.
33
# Generate secrets: openssl rand -hex 32
44

5+
# --- Required (static, env-only) ---
56
DATABASE_URL=postgres://bastion:CHANGE_ME@postgres:5432/agent_bastion
67
REDIS_URL=redis://redis:6379
7-
JWT_SECRET=CHANGE_ME_USE_openssl_rand_hex_32
8-
ENCRYPTION_KEY=CHANGE_ME_USE_openssl_rand_hex_32
8+
JWT_SECRET=CHANGE_ME_USE_openssl_rand_hex_32 # Min 32 chars
9+
ENCRYPTION_KEY=CHANGE_ME_USE_openssl_rand_hex_32 # Exactly 64 hex chars
910
SERVER_HOST=0.0.0.0
1011
GATEWAY_PORT=3000
1112
CONSOLE_PORT=3001
1213
CORS_ORIGINS=https://console.yourdomain.com
1314
RUST_LOG=info,agent_bastion=info
1415

15-
# Quickwit
16+
# Quickwit (audit log search engine)
1617
QUICKWIT_URL=http://quickwit:7280
1718
QUICKWIT_INDEX=audit_logs
1819

19-
# Syslog (optional)
20-
# SYSLOG_ADDR=syslog.internal:514
21-
2220
# OIDC / SSO
2321
OIDC_ISSUER_URL=https://auth.yourdomain.com
2422
OIDC_CLIENT_ID=CHANGE_ME
@@ -31,3 +29,15 @@ DB_PASSWORD=CHANGE_ME
3129
DB_NAME=agent_bastion
3230
RUSTFS_USER=rustfs
3331
RUSTFS_PASSWORD=CHANGE_ME
32+
33+
# --- Dynamic Settings (configured via Web UI after first run) ---
34+
# On first start, visit the console to complete the setup wizard.
35+
# After setup, the following are managed through Admin > Settings:
36+
# - JWT access/refresh token TTLs
37+
# - Response cache TTL
38+
# - Content filter & PII redactor patterns
39+
# - Budget alert thresholds & webhook URL
40+
# - API key policies (default expiry, rotation, inactivity timeout)
41+
# - Data retention policies (usage records, audit logs)
42+
# - Signature verification parameters
43+
# Log forwarding is configured via Admin > Log Forwarding.

‎Cargo.lock‎

Lines changed: 133 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ url = "2"
6464
# Observability
6565
tracing = "0.1"
6666
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
67+
metrics = "0.24"
68+
metrics-exporter-prometheus = { version = "0.16", default-features = false }
6769

6870
# Config
6971
dotenvy = "0.15"

‎README.md‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ AgentBastion solves all of this with a single deployment.
4848
- **Automatic format conversion** — Anthropic Messages API, Google Gemini, and more, all behind a single OpenAI-compatible interface
4949
- **Streaming SSE pass-through** — zero-overhead forwarding with real-time token counting
5050
- **Virtual API keys** — issue scoped `ab-` keys per team, per project, per developer; revoke in one click
51+
- **API key lifecycle management** — automatic rotation with grace periods, per-key inactivity timeout, expiry warnings, and background policy enforcement
5152
- **Sliding-window rate limiting** — RPM and TPM limits via Redis, per key or per user
53+
- **Circuit breaker** — three-state (Closed/Open/HalfOpen) circuit breaker with configurable failure threshold and recovery period
54+
- **Retry with exponential backoff** — configurable retries with jitter for network errors and upstream rate limits
5255
- **Real-time cost tracking** — per-model pricing with budget alerts and team attribution
5356

5457
### MCP Gateway
@@ -64,12 +67,24 @@ AgentBastion solves all of this with a single deployment.
6467
- **SSO/OIDC** — plug into Zitadel, Okta, Azure AD, or any OIDC-compliant provider
6568
- **AES-256-GCM encryption** — provider API keys and secrets encrypted at rest
6669
- **SHA-256 key hashing** — virtual API keys stored as hashes; plaintext shown exactly once
70+
- **Content Security Policy** — CSP headers on the console port to prevent XSS and injection attacks
71+
- **JWT entropy enforcement** — minimum 32-character secret with entropy validation at startup
72+
- **Startup dependency validation** — verifies PostgreSQL, Redis, and encryption key availability with clear error messages before accepting traffic
6773
- **Security headers** — X-Content-Type-Options, X-Frame-Options, CORS whitelisting, request timeouts
74+
- **Soft-delete** — users, providers, and API keys use soft-delete (`deleted_at` column) with automatic purge after 30 days
6875
- **Distroless containers** — minimal attack surface in production (2MB runtime image, no shell)
6976

77+
### Operations & Configuration
78+
- **Dynamic configuration** — most settings stored in database (`system_settings` table), configurable via Web UI (Admin > Settings with 7 category tabs)
79+
- **First-run setup wizard** — guided `/setup` wizard creates the super_admin account, configures the site, and optionally adds the first provider and API key
80+
- **Multi-instance sync** — configuration changes propagated across instances via Redis Pub/Sub
81+
- **Data retention policies** — configurable retention periods for usage records and audit logs with automatic daily purge
82+
7083
### Observability
84+
- **Prometheus metrics** — `GET /metrics` endpoint on the gateway port (3000) exposing `gateway_requests_total`, `gateway_request_duration_seconds`, `gateway_tokens_total`, `gateway_rate_limited_total`, `circuit_breaker_state`, and more
85+
- **Enhanced health checks** — `/health/live` (liveness probe), `/health/ready` (readiness probe with PostgreSQL and Redis checks), `/api/health` (detailed latency and pool statistics)
7186
- **Quickwit-powered audit logs** — full-text search across all API calls and tool invocations
72-
- **Syslog forwarding** — RFC 5424 compliant; integrate with your existing SIEM
87+
- **Audit log forwarding** — multi-channel delivery: UDP/TCP Syslog (RFC 5424), Kafka, and HTTP webhooks — route audit events to any SIEM, data lake, or alerting pipeline
7388
- **Usage analytics** — token consumption by user, team, model, and time period
7489
- **Cost analytics** — MTD spend, budget utilization, per-model cost breakdown
7590
- **Health dashboard** — real-time status of PostgreSQL, Redis, Quickwit, and all MCP servers
@@ -100,7 +115,7 @@ cargo run -p agent-bastion-server
100115
# 3. Start frontend dev server
101116
cd web && pnpm install && pnpm dev
102117

103-
# 4. Open http://localhost:5173
118+
# 4. Complete the setup wizard at http://localhost:5173/setup
104119
```
105120

106121
See the **[Deployment Guide](docs/en/deployment-guide.md)** for production setup with Docker Compose or Kubernetes.
@@ -119,7 +134,7 @@ See the **[Deployment Guide](docs/en/deployment-guide.md)** for production setup
119134

120135
| Port | Server | Exposure | Purpose |
121136
|------|--------|----------|---------|
122-
| `3000` | Gateway | **Public** — expose to AI clients | `/v1/chat/completions`, `/v1/models`, `/mcp` |
137+
| `3000` | Gateway | **Public** — expose to AI clients | `/v1/chat/completions`, `/v1/models`, `/mcp`, `/metrics`, `/health/*` |
123138
| `3001` | Console | **Internal** — behind VPN/firewall | `/api/*` management endpoints, Web UI |
124139

125140
> In production, **only port 3000** should be reachable from the internet. Port 3001 should be restricted to your admin network.
@@ -134,8 +149,8 @@ AgentBastion/
134149
│ ├── mcp-gateway/ # MCP proxy: JSON-RPC, tool aggregation, access control
135150
│ ├── auth/ # JWT, OIDC, API key, password hashing, RBAC
136151
│ └── common/ # Config, DB, models, crypto, audit logger
137-
├── migrations/ # 7 PostgreSQL migration files
138-
├── web/ # React frontend — 15 page components
152+
├── migrations/ # 12 PostgreSQL migration files
153+
├── web/ # React frontend — ~20 page components
139154
├── deploy/
140155
│ ├── docker/ # Dockerfile.server (distroless), Dockerfile.web (nginx)
141156
│ ├── docker-compose.yml # Production deployment

0 commit comments

Comments
 (0)