Skip to content

evalops/gate

Repository files navigation

Gate

Gate is a multi-protocol, policy-driven privileged access gateway. It sits between users and upstream databases, APIs, and servers, evaluates OPA/Rego policies, masks sensitive data, and centralizes audit, webhook, and recording workflows in a control plane.

                         ┌─────────────────────────────────┐
                         │          gate-control           │
                         │  Admin UI + HTTP + gRPC + DB    │
                         │                                 │
                         │  Resources  Policies  Audit     │
                         │  Identities Groups  Webhooks    │
                         │  Organizations  Recordings      │
                         └──────────────┬──────────────────┘
                                        │ gRPC / Protobuf
                         sync / audit / │ registration / heartbeat
                                        │
                         ┌──────────────▼──────────────────┐
   ┌──────────┐          │         gate-connector          │          ┌──────────┐
   │  Clients  │────────▶│ Policy evaluation + proxying    │────────▶│ Upstream │
   │ psql/curl │◀────────│ PostgreSQL / MySQL / HTTP / SSH │◀────────│ services │
   └──────────┘          │ Audit / masking / TLS / metrics │          └──────────┘
                         └─────────────────────────────────┘

Highlights

  • PostgreSQL, MySQL, HTTP, and SSH proxying.
  • Rego v1 policy evaluation at session, pre_request, and post_request stages.
  • Central management for resources, policies, identities, groups, organizations, scoped API keys, webhooks, access requests, audit logs, and recordings.
  • gRPC/Protobuf control-plane contracts with generated Go stubs.
  • Embedded admin UI plus HTTP /api/v1/* compatibility endpoints over the same backend RPC logic.
  • Dedicated connector health, readiness, and Prometheus metrics endpoints.
  • Durable dead-letter storage for async delivery paths and optional session recording storage.

Transport Model

gate-control exposes three surfaces on the same listener:

  • Embedded admin UI at /
  • HTTP health and admin endpoints such as /health and /api/v1/*
  • gRPC services gate.v1.ControlPlaneService and gate.v1.ConnectorService

The HTTP admin handlers are thin compatibility adapters over the gRPC services, so the web UI, HTTP clients, and Go RPC clients all share the same business logic and auth rules.

Connector-to-control-plane traffic now uses gRPC/Protobuf for:

  • Policy sync
  • Audit ingestion
  • Connector registration
  • Connector heartbeat
  • Connector deregistration

Relevant sources:

  • Protobuf contracts: proto/gate/v1/*.proto
  • Generated Go stubs: internal/gen/gate/v1
  • Shared Go admin client: internal/controlplaneclient

Quick Start

Docker Compose

For the fastest local stack:

docker compose up --build

This starts:

  • gate-control on http://localhost:8080
  • gate-connector PostgreSQL listener on localhost:6432
  • connector health and metrics on :8081 inside the container (not published by default)
  • control-plane Postgres on localhost:5433
  • sample upstream Postgres on localhost:5434

The checked-in docker-compose.yml is a local dev setup and currently runs the control plane without an API key. The sample connector config already points at the compose services and loads policies/example.rego for all three policy stages.

Example connection through the connector:

PGPASSWORD=app psql -h localhost -p 6432 -U app -d appdb

Run Manually

Both checked-in config files support environment-variable expansion:

  • configs/control.yaml
  • configs/connector.yaml

Run the binaries directly:

go run ./cmd/gate-control -config configs/control.yaml
go run ./cmd/gate-connector -config configs/connector.yaml

Authentication And Tenancy

  • HTTP and gRPC both use Bearer auth.
  • api_key in the control-plane config is the system/root key.
  • Scoped organization API keys support roles such as readonly, editor, admin, and connector.
  • System callers can apply org scope with X-Org-ID on HTTP requests or x-org-id gRPC metadata.
  • If api_key is empty, the control plane runs unauthenticated. That is useful for local development, not production.

Configuration

The sample configs in configs/ are the best starting point. The fields below are the ones that matter most when wiring a real deployment.

Control Plane

listen_addr: ":8080"
api_key: "${GATE_API_KEY}"

database:
  dsn: "postgres://${GATE_DB_USER}:${GATE_DB_PASSWORD}@${GATE_DB_HOST}:${GATE_DB_PORT}/${GATE_DB_NAME}?sslmode=disable"
  max_open_conns: 25
  min_conns: 5
  migrations_path: "internal/store/migrations"

recording:
  dir: ".data/recordings" # optional

delivery:
  dead_letter_dir: ".data/control-deadletters" # optional

logging:
  level: "info"
  format: "json"

Connector

listen_addr: ":6432"
health_addr: ":8081"

control_plane:
  url: "http://localhost:8080"
  token: "${GATE_CONTROL_TOKEN}"
  sync_interval: "30s"

resources:
  - name: "primary-db"
    protocol: "postgres"
    host: "localhost"
    port: 5432
    database: "appdb"

policies:
  - path: "policies/example.rego"
    stage: "session"
  - path: "policies/example.rego"
    stage: "pre_request"
  - path: "policies/example.rego"
    stage: "post_request"

tls:
  enabled: false # optional

recording:
  dir: ".data/recordings" # optional

delivery:
  dead_letter_dir: ".data/connector-deadletters" # optional

logging:
  level: "info"
  format: "json"

Policy Model

Gate evaluates Rego policies in three stages:

  • session: allow or block a connection/session before it is established
  • pre_request: allow, block, or rewrite a request/query before forwarding upstream
  • post_request: allow or transform the upstream response, including masking

Managed policies in the control plane move through draft, dry_run, and active states.

Minimal example:

package formal.v2

import rego.v1

default pre_request := {"action": "allow"}

pre_request := {"action": "block", "reason": "destructive queries are not allowed"} if {
	input.query.type == "drop"
}

post_request := {
	"action": "mask",
	"masks": [
		{"column": "email", "strategy": "partial"},
		{"column": "ssn", "strategy": "redact"},
	],
}

Masking strategies include redact, partial, hash, and encrypt.

See policies/example.rego for the sample policy used by the local connector config.

API Surface

Top-level HTTP admin areas under /api/v1/ include:

  • resources
  • policies
  • organizations
  • identities
  • groups
  • connectors
  • webhooks
  • access-requests
  • audit
  • recordings

The gRPC contracts are defined in:

  • proto/gate/v1/controlplane.proto
  • proto/gate/v1/connector.proto

Domain messages are split across:

  • proto/gate/v1/resource_policy.proto
  • proto/gate/v1/identity_group.proto
  • proto/gate/v1/tenant.proto
  • proto/gate/v1/webhook_access.proto
  • proto/gate/v1/audit.proto
  • proto/gate/v1/recording.proto

Development

Prerequisites:

  • Go 1.25+
  • Docker for local compose and integration tests
  • golangci-lint v2 for make lint

Common commands:

make build
make test
make test-race
make lint
make generate-proto
make verify-generated
make docker
make test-e2e

Notes:

  • make generate-proto regenerates all Go stubs from proto/gate/v1/*.proto.
  • make verify-generated is what CI uses to ensure generated files are up to date.
  • make test-e2e brings up docker-compose.test.yml, runs integration tests with the integration build tag, then tears the stack down.

Repository Layout

gate/
├── cmd/
│   ├── gate-connector/              # Connector binary entrypoint
│   ├── gate-control/                # Control-plane binary entrypoint
│   └── gate-policy/                 # Policy tooling
├── configs/                         # Sample runtime configs
├── internal/
│   ├── connector/                   # Proxy runtime, routing, TLS, health, metrics
│   ├── controlplane/                # HTTP server, gRPC services, embedded UI bridge
│   ├── controlplaneclient/          # Shared Go admin client for ControlPlaneService
│   ├── enforcement/                 # Masking, filtering, rewrite helpers
│   ├── gen/gate/v1/                 # Generated protobuf and gRPC stubs
│   ├── policy/                      # OPA/Rego policy engine
│   ├── protocol/                    # Postgres, MySQL, HTTP, SSH protocol handlers
│   ├── recording/                   # Session recording storage/replay primitives
│   ├── store/                       # Postgres and in-memory stores + migrations
│   ├── sync/                        # Connector policy sync and audit shipping
│   └── webhooks/                    # Webhook dispatch and retry/dead-letter handling
├── policies/                        # Example local policies
├── proto/gate/v1/                   # Protobuf contracts
├── scripts/                         # Helper scripts, including protobuf generation
├── Dockerfile                       # Multi-stage connector/control image build
├── docker-compose.yml               # Local dev stack
└── docker-compose.test.yml          # Integration test dependencies

License

Business Source License 1.1. See LICENSE for the current terms.

About

Multi-protocol, policy-driven privileged access management proxy. PostgreSQL, MySQL, HTTP, and SSH proxying with OPA/Rego policies, data masking, query rewriting, OIDC/SSO auth, and comprehensive audit logging.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors