Skip to content

Gateway & Routing

APISIX serves as the single entry point for all platform traffic, handling authentication, routing, rate limiting, and request validation.

Architecture

External Traffic


┌─────────────────────────────────────────────────────┐
│                 APISIX Gateway (port 9080)           │
│                                                      │
│  ┌──────────────────────────────────────────────┐   │
│  │              Plugin Pipeline                  │   │
│  │                                               │   │
│  │  1. CORS          → Origin/method validation  │   │
│  │  2. Rate Limit    → Profile-based throttling  │   │
│  │  3. OIDC          → JWT validation (Keycloak) │   │
│  │  4. Request Valid. → Headers, body size       │   │
│  │  5. Idempotency   → Replay protection        │   │
│  │  6. Correlation    → X-Correlation-Id mgmt    │   │
│  │  7. Claim Project. → JWT → HTTP headers       │   │
│  │  8. Proxy         → Route to upstream         │   │
│  └──────────────────────────────────────────────┘   │
└────────────────────────┬────────────────────────────┘

        ┌────────────────┼────────────────┐
        ▼                ▼                ▼
   Control Plane    Keycloak     Web Console

Route Table

Route PatternPriorityUpstreamAuthRate Profile
/v1/platform/*100Control PlanePlatform adminplatform_control
/v1/tenants/*100Control PlanePlatform admintenant_control
/v1/workspaces/*100Control PlaneWorkspace scopeworkspace_control
/v1/auth/*90KeycloakPublic / authauth_control
/v1/iam/*100Control PlanePlan-gatedplatform_control
/v1/postgres/*100Control PlaneWorkspace scopeworkspace_control
/v1/mongo/*100Control PlaneWorkspace scopeworkspace_control
/v1/events/*100Event GatewayWorkspace scopeevent_gateway
/v1/functions/*100Control PlaneWorkspace scopeworkspace_control
/v1/storage/*100Control PlaneWorkspace scopeworkspace_control
/realtime/*80Control PlaneWebSocket authrealtime
/control-plane/*100Control PlanePlatform adminplatform_control
/auth/*90KeycloakPass-throughauth_control
/health200Control PlaneNone
/*10Web ConsoleNone

OIDC Configuration

yaml
oidc:
  discoveryUrl: http://keycloak:8080/realms/in-falcone-platform/.well-known/openid-configuration
  clientId: in-falcone-gateway
  clientType: bearer-only
  claimProjection:
    X-Auth-Subject: sub
    X-Auth-Tenant-Id: tenant_id
    X-Auth-Workspace-Id: workspace_id
    X-Auth-Plan-Id: plan_id
    X-Auth-Roles: realm_access.roles
    X-Auth-Scopes: scope

CORS Policy

yaml
cors:
  allowOrigins:
    - "https://console.{environment}.in-falcone.example.com"
  allowMethods:
    - GET, POST, PUT, PATCH, DELETE, OPTIONS
  allowHeaders:
    - Authorization
    - Content-Type
    - Idempotency-Key
    - X-API-Version
    - X-Correlation-Id
    - X-Auth-Subject
  allowCredentials: true
  maxAge: 3600

Rate Limiting

Rates are enforced per-client (based on JWT subject):

ProfileRequests/minBurstWindow
platform_control2406060s
tenant_control2406060s
workspace_control2406060s
auth_control1804060s
provisioning1203060s
observability3008060s
event_gateway60015060s
realtime1203060s
native_admin601560s

Response when rate-limited:

HTTP/1.1 429 Too Many Requests
Retry-After: 5
X-RateLimit-Limit: 240
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1705312800

Idempotency

Mutating requests (POST, PUT, PATCH, DELETE) support idempotency via the Idempotency-Key header:

SettingValue
Key headerIdempotency-Key
TTL86400 seconds (24 hours)
Replay headerX-Idempotency-Replayed: true
Key formatFree-form string

When a duplicate key is received within the TTL, the original response is replayed without re-executing the operation.

Request Validation

Required Headers

HeaderPatternRequired On
X-API-VersionDate format (e.g., 2024-01-01)All /v1/* requests
X-Correlation-Id^[A-Za-z0-9._:-]{8,128}$All requests (auto-generated if missing)

Body Size Limits

Route FamilyMax Body
Default262 KB
Provisioning1 MB
Native admin512 KB

Spoofed Header Protection

The gateway strips any client-provided headers that match internal context headers:

  • X-Auth-Subject
  • X-Auth-Tenant-Id
  • X-Auth-Workspace-Id
  • X-Auth-Plan-Id
  • X-Auth-Roles
  • X-Auth-Scopes

These headers are only set by the gateway itself after JWT validation.

Health Check

GET /health

No authentication required. Returns 200 OK when the gateway is operational.

json
{
  "status": "ok",
  "timestamp": "2024-01-15T10:00:00.000Z"
}

Released under the MIT License.