GebSecure Docs v0.1.0

Architecture

Architecture

Components, the gateway request pipeline, data flow, trust boundaries and deployment topology.

GebSecure sits between AI agents and everything they act on. Every action an agent wants to take is authenticated, authorized against deployed policy, risk-scored, optionally sent for human approval, executed with brokered credentials, and audited — in that order, on every request.

Decisions that are expensive to change are recorded as ADRs in docs/adr; this document is the map that ties them together.

Components#

Component Path Role Scales by
API (control plane) apps/api (:4000) Humans and admin tooling: auth/SSO sessions, tenancy, agents & credentials, policies (write → test → simulate → deploy), approvals, vault, connections, audit query/export, webhooks replicas (stateless)
Gateway (data plane) apps/gateway (:4100) Agents and SDKs: POST /v1/authorize (ALLOW / DENY / APPROVAL_REQUIRED) and POST /v1/execute (brokered connector execution) — the latency-critical path replicas + GATEWAY_WORKERS (Node cluster)
Worker apps/worker (:4200) Background loops: audit hash chaining, outbox dispatch, webhooks, notifications, approval expiry/escalation, execution resume/recovery, vault refresh/rewrap, retention replicas (rows claimed with SKIP LOCKED)
Console apps/console (:5173) Web UI (Vite SPA, served by nginx in production) replicas
Shared packages packages/* core (domain services), authz + policy (GSL engine), risk, db (pool, RLS transactions, migrations), crypto (tokens, KMS), net (SSRF-safe HTTP), connectors + connector-sdk, http (Fastify server), config, logger, common —
PostgreSQL 16 System of record, RLS-enforced tenancy, audit hash chain, outbox/job tables vertical + read replica
Redis 7 Policy/version-stamp cache, rate limits, token revocation, risk velocity replication group
KMS AWS/GCP/Azure/local Key-encryption keys for vault envelope encryption managed

Request pipeline (gateway hot path)#

Diagram (Mermaid source)
sequenceDiagram
    autonumber
    participant A as Agent / SDK
    participant G as Gateway
    participant R as Redis
    participant P as PostgreSQL
    participant B as Credential broker
    participant S as Sandbox worker thread
    participant X as External API / MCP / DB

    A->>G: POST /v1/authorize or /v1/execute (Bearer EdDSA access token)
    G->>G: verify token signature (JWKS key ring)
    G->>R: 1 pipeline: rate-limit counter + revocation check
    G->>G: compiled policy set (in-process cache, version-stamped)
    G->>R: 1 pipeline: risk history + policy version stamp
    G->>G: evaluate GSL (forbid > approval > permit, limits, ReBAC), score risk
    G->>P: 1 statement: gs_record_decision (risk + audit ingest + outbox)
    alt APPROVAL_REQUIRED
        G-->>A: 202 approval pending (approvers notified by worker)
    else DENY
        G-->>A: 403 decision + explanation
    else ALLOW (execute)
        G->>B: action + connection (credential stays in parent)
        B->>S: run connector code (no fetch, heap/time limits)
        S->>B: ctx.http request (message passing)
        B->>X: allowed host only, SSRF checks, credential injected, signed
        X-->>B: response
        B-->>S: response
        S-->>G: result → sanitized (credentials/secret shapes removed)
        G-->>A: 200 result
    end

Target: P95 < 20 ms for a simple authorization decision (ADR 0007).

Data flow#

Diagram (Mermaid source)
flowchart LR
    subgraph Clients
      H[Humans<br/>browser]
      AG[AI agents<br/>SDK / MCP]
    end
    subgraph Edge["Ingress (TLS)"]
      ING[Ingress controller<br/>public paths only]
    end
    subgraph Cluster["Kubernetes namespace (default-deny NetworkPolicies)"]
      C[Console<br/>nginx]
      API[API]
      GW[Gateway]
      W[Worker]
      MJ[Migration Job<br/>pre-upgrade hook]
    end
    subgraph Data["Isolated database subnets"]
      PG[(PostgreSQL 16<br/>RLS)]
      RD[(Redis 7<br/>TLS + AUTH)]
    end
    KMS[[Cloud KMS<br/>envelope key]]
    SM[[Secrets Manager<br/>via External Secrets]]
    EXT[(Customer systems<br/>APIs, MCP, clouds)]

    H --> ING --> C
    ING --> API
    AG --> ING --> GW
    API -- gebsecure_app role --> PG
    GW -- gebsecure_app role --> PG
    API --> RD
    GW --> RD
    W -- system connection --> PG
    W --> RD
    MJ -- schema owner --> PG
    API & GW & W -- IRSA --> KMS
    SM -. synced Secrets .-> API & GW & W
    GW -- brokered HTTPS 443 --> EXT
    W -- webhooks / email --> EXT
  • Writes go through Database.tenant() transactions that set app.org_id; RLS confines every row.
  • Audit: decisions and changes are written to audit_ingest in the same transaction; the worker chains them into a per-organization SHA-256 hash chain (ADR 0005).
  • Events: an outbox table written transactionally; the worker fans out to webhooks, notifications and approvals (ADR 0008).
  • Secrets in the vault are envelope-encrypted: a fresh DEK per secret version (AES-256-GCM) wrapped by the KMS key, with {orgId, secretId, version} bound as AAD on both layers (ADR 0010).

Trust boundaries#

# Boundary Controls
TB1 Internet → ingress TLS only; only /v1, /.well-known, /docs (API) and /v1, /.well-known (gateway) are routed — /metrics and /readyz stay internal; body limits; per-principal rate limits
TB2 Caller → service Every request authenticated (EdDSA access tokens, rotating refresh tokens, hashed machine secrets or private_key_jwt); revocation checked in Redis; CSRF header + SameSite cookies for browser refresh
TB3 Tenant ↔ tenant PostgreSQL RLS on every tenant table (gs_enable_tenant_rls), composite foreign keys, explicit org_id filters; runtime role is neither owner nor BYPASSRLS (ADR 0003)
TB4 Agent ↔ credentials Agents never receive credentials; connector code runs in a sandboxed worker thread and can reach only allowed hosts through the broker, which injects credentials and sanitizes outputs (ADR 0009)
TB5 GebSecure → customer-controlled URLs SSRF-safe networking: https only, non-public addresses (RFC 1918, loopback, link-local, metadata) rejected, connection pinned to the validated IP, no implicit redirects, bounded responses (ADR 0011); NetworkPolicy egress excludes 169.254.0.0/16
TB6 Services → data stores Separate DB roles: gebsecure_app (api, gateway), system/owner connection only in the worker and the migration Job; TLS to RDS (rds.force_ssl) and Redis (rediss:// + AUTH)
TB7 Platform → secrets/keys Secrets only in Kubernetes Secrets synced from Secrets Manager (never in values/ConfigMaps); the envelope KMS key is usable only by the app IRSA role; IMDS unreachable from pods
TB8 Supply chain → runtime npm ci --ignore-scripts, dependency/secret/SAST/container scanning, images built once, SBOM + provenance, cosign-signed and verified before deploy; non-root, read-only, capability-less containers

Deployment topology#

  • Local: docker-compose.yml (Postgres, Redis, Mailpit; full profile adds every service from the production images) — see README.
  • Cloud: AWS via infra/terraform (VPC, EKS, RDS, ElastiCache, KMS, Secrets Manager, CloudWatch) and the Helm chart infra/helm/gebsecure; promotion development → staging → production is described in infra/environments/README.md and docs/operations/deployment.md.
  • Reliability stack: infra/reliability — 3 PostgreSQL nodes (Patroni), Redis + Sentinel, HAProxy and N replicas of every service; used for the scaling, failover, chaos, DR and upgrade exercises in docs/operations/reliability-evidence.md.
  • Deployment models (multi-tenant cloud, dedicated, customer VPC, self-hosted/air-gapped): one artifact set, per-model Helm profiles and Terraform environments — docs/operations/private-deployment.md, ADR 0017; multi-region design in docs/operations/multi-region.md.

Reliability model#

Stateless replicas behind health-checked load balancers; PostgreSQL is the single source of truth for every cross-request invariant; Redis holds only rebuildable state with explicit, tested degradation (rate limits fail open; revocation, limits and sensitive actions fail closed); graceful drain on SIGTERM; readiness gated on schema compatibility for zero-downtime upgrades — ADR 0016, runbooks in docs/operations/runbooks.