SaaS 部署指南
以 SaaS 模式部署 Arkloop:网关安全加固、TLS 终止、CI/CD 流水线集成与多实例扩展。
SaaS Deployment Guide
This guide covers deploying Arkloop in SaaS mode (--mode saas), which is intended for the official Arkloop SaaS service. SaaS mode differs from standard self-hosted deployment in several ways:
| Dimension | Self-hosted | SaaS |
|---|---|---|
| Authentication | Local registration + bootstrap admin | OAuth / SSO integration |
| Billing | No credit system | Credit deduction enabled |
| Models | User-configured API keys | Platform-managed providers |
| Domain | localhost / internal network | Public internet + TLS |
| Upgrade | Manual setup.sh upgrade | CI/CD pipeline auto-deploy |
| Scale | Single machine | Multi-instance + PGBouncer + S3 |
Quick Start
SaaS mode automatically enables:
- PGBouncer — Connection pooling for high concurrency
- SeaweedFS — S3-compatible object storage for persistent files
- Full Console — Management UI with billing/credit pages
- Turnstile placeholders — Bot protection env vars pre-configured
- Fake-IP trust disabled —
ARKLOOP_OUTBOUND_TRUST_FAKE_IP=false
Bootstrap admin URL generation is skipped — SaaS deployments handle admin provisioning through the CI/CD pipeline or OAuth/SSO integration.
1. Gateway Security Hardening
When exposing Arkloop to the public internet, configure the Gateway for production security.
IP Mode
Set the Gateway IP detection mode to match your infrastructure:
Rate Limiting
The Gateway uses a token-bucket algorithm with per-user rate limiting via Redis:
For SaaS deployments with high traffic, consider adjusting these values. The Gateway uses Redis DB 1 (ARKLOOP_GATEWAY_REDIS_URL) for rate limit state.
Cloudflare Turnstile (Bot Protection)
Configure Turnstile to protect public-facing authentication endpoints:
These can also be managed via the Console UI under platform settings.
CORS Configuration
Restrict allowed origins to your actual domain(s):
Important: Wildcard (
*) origins are rejected by the Gateway.
GeoIP Filtering
Optional MaxMind GeoIP integration for geographic access control:
Risk Scoring
Set a threshold to automatically reject requests with high risk scores (0–100):
Security Hardening Checklist
- Set
ARKLOOP_GATEWAY_IP_MODEto match your infrastructure - Configure rate limiting appropriate for your traffic
- Set up Cloudflare Turnstile for bot protection
- Restrict CORS origins to your domain(s)
- Set
ARKLOOP_OUTBOUND_TRUST_FAKE_IP=false(done by--mode saas) - Set
ARKLOOP_GATEWAY_TRUST_INCOMING_TRACE_ID=0(default) - Configure GeoIP filtering if needed
- Set a risk reject threshold
2. TLS Termination
Arkloop does not handle TLS directly. Use a reverse proxy or tunnel service in front of the Gateway.
Option A: Nginx
When using Nginx, set:
Option B: Caddy
Caddy automatically provisions and renews TLS certificates via Let's Encrypt. Set:
Option C: Cloudflare Tunnel
Or with a configuration file:
When using Cloudflare Tunnel, set:
CORS Update
After configuring TLS, update the CORS origins to use https://:
3. CI/CD Pipeline Integration
Use setup.sh with --non-interactive and --mode saas for automated deployments.
GitHub Actions Example
Environment Variables
For CI/CD, pre-set secrets as environment variables before running setup.sh. The installer will use existing values instead of generating new ones:
| Secret | Generator | Description |
|---|---|---|
ARKLOOP_POSTGRES_PASSWORD | openssl rand -hex 16 | Database password |
ARKLOOP_REDIS_PASSWORD | openssl rand -hex 16 | Redis auth |
ARKLOOP_AUTH_JWT_SECRET | openssl rand -base64 48 | JWT signing key (≥32 chars) |
ARKLOOP_ENCRYPTION_KEY | openssl rand -hex 32 | AES-256-GCM key (64 hex chars) |
ARKLOOP_S3_SECRET_KEY | openssl rand -hex 32 | Object storage auth |
ARKLOOP_SANDBOX_AUTH_TOKEN | openssl rand -hex 32 | Worker↔Sandbox auth |
ARKLOOP_TURNSTILE_SECRET_KEY | Cloudflare dashboard | Bot protection |
Upgrade Pipeline
The install command is idempotent — it updates .env and restarts services with the latest configuration. For zero-downtime upgrades, use rolling restarts:
4. Multi-Instance Scaling
For high-traffic SaaS deployments, consider horizontal scaling:
API / Worker
Run multiple instances of api and worker behind a load balancer. PGBouncer handles connection pooling across instances:
PGBouncer Tuning
Adjust pool sizes for your workload:
Application Connection Pools
When using PGBouncer, tune the per-instance application pool:
External Database
For production SaaS, consider using a managed PostgreSQL service (e.g., AWS RDS, Supabase). Update the connection strings:
When using an external database, PGBouncer can be disabled as managed services typically include their own connection pooling.
External Object Storage
Replace SeaweedFS with a managed S3 service: