OpenKor — API Gateway. The single external entry point of the platform.
korapi is the sole gateway through which all client traffic (korcli, web UI, curl) flows. Backend services (korauth, korvm, korvol) are never exposed directly. The gateway handles routing, JWT validation, rate limiting, audit logging, and request ID propagation — it contains no business logic.
Stack: Go 1.22+ · Gin · Redis (rate limiting + JWKS cache)
License: Apache 2.0 · Org: OpenKorProject
# 1. Configure environment
cp .env.example .env
# Update KORAUTH_URL, KORVM_URL, KORVOL_URL with downstream service addresses
# 2. Start development environment (Redis + gateway)
docker-compose up -d
# 3. Gateway is running at http://localhost:8080
curl http://localhost:8080/healthz| Path | Target | Auth |
|---|---|---|
/v1/auth/login |
korauth | ❌ |
/v1/auth/refresh |
korauth | ❌ |
/v1/auth/.well-known/jwks.json |
korauth | ❌ |
/v1/auth/* |
korauth | ✅ |
/v1/vm/* |
korvm | ✅ |
/v1/vol/* |
korvol | ✅ |
/healthz, /readyz |
korapi | ❌ |
Routing is declarative (.env + code) — adding a new service requires minimal code changes.
- Request ID — generate if missing, propagate as
X-Request-IDheader - Logging — start/end, duration, status (stdout JSON)
- CORS + security headers
- Rate limiting — per tenant/IP (Redis sliding window)
- JWT validation — skipped for public paths; validated against korauth JWKS (cached)
- RBAC context injection — extract tenant_id/roles from token →
X-Tenant-ID,X-User-ID,X-Rolesheaders - Audit log — mutations (POST/PUT/PATCH/DELETE) → stdout JSON
- Reverse proxy — forward to target service
cmd/korapi/ # entrypoint
internal/
config/ # env-based configuration
handler/ # HTTP handlers (healthz, readyz, 404)
middleware/ # middleware (request-id, JWT, rate-limit, audit, CORS, etc.)
proxy/ # reverse proxy logic
audit/ # audit logging
api/openapi.yaml # API contract (routing, middleware, error format)
# Run tests
go test ./...
# Vet
go vet ./...
# Build
go build -o bin/korapi ./cmd/korapidocker build -t korapi:latest .
docker run -p 8080:8080 \
-e KORAUTH_URL=http://korauth:8081 \
-e REDIS_URL=redis://redis:6379/0 \
korapi:latestAll OpenKor services must share a Docker network so they can reach each other by hostname:
docker network create openkor
# Add openkor network to each service's docker-compose.yamlThe service unit file is kept in the repo at systemd/korapi.service.
1. Build the binary
go build -o /opt/openkor/korapi/bin/korapi ./cmd/korapi2. Create the environment file
sudo mkdir -p /opt/openkor/korapi/config
sudo cp .env.example /opt/openkor/korapi/config/korapi.env
# Edit /opt/openkor/korapi/config/korapi.env with production values3. Install the service unit
sudo cp systemd/korapi.service /etc/systemd/system/korapi.service4. Enable and start
sudo useradd --system --no-create-home korapi
sudo systemctl daemon-reload
sudo systemctl enable --now korapi
sudo systemctl status korapiSee api/openapi.yaml — endpoints, error envelope, JWT claims, audit log format.
Conventional Commits. License: Apache 2.0.
