Operations & Security

Security Hardening

Trust boundaries, least privilege roles, credential handling, network controls, and security checklists.

Security & Hardening Guide

The gateway reduces direct database credential exposure, but it remains a critical SQL execution service. A secure deployment depends on network isolation, careful PostgreSQL grants, protected secrets, and conservative client retry policies.


Trust Model

The gateway operates under the following trust assumptions:

  • Operators: Individuals with filesystem or environment access to gateway.yaml and .env are fully trusted.
  • Admin Password Holders: Possess full cluster authority (can create databases, drop tables, issue keys). Must be tightly restricted.
  • API Key Holders: Authenticated clients are trusted strictly within the PostgreSQL role scope assigned to their key.
  • PostgreSQL Administrator: The role in DATABASE_URL is trusted to manage internal gateway tables and provision restricted logins.

Network Isolation

  1. Keep PostgreSQL and Redis Private: PostgreSQL and Redis must never be directly exposed to the public internet. Restrict them to the gateway host's private subnet or VPC security group.
  2. Restrict /admin Routes: Admin endpoints should never be publicly reachable. Restrict /admin/* using firewall rules, a private VPC ingress, VPN, or reverse proxy IP allowlisting.
  3. Loopback Binding: When deployed behind a local reverse proxy on the same host, bind server.host to 127.0.0.1 in gateway.yaml.
  4. Trusted Proxies: Only configure trusted reverse proxies to forward X-Forwarded-For. Accepting arbitrary forwarding headers allows callers to spoof client IPs and bypass rate limits.

PostgreSQL Least Privilege

1. The Administrative Connection

The administrator connection configured in database.url requires:

  • CONNECT and ownership rights on the http_postgres_gateway persistence schema.
  • CREATEROLE privilege to create and configure scoped logins.
  • Session visibility on pg_stat_activity to verify query connection health.
  • CREATE DATABASE privilege only if the database creation API is utilized.

2. Scoped Query Roles

  • The gateway provisions separate PostgreSQL users with randomly derived passwords for each unique key scope.
  • Scoped roles must have no superuser privileges, no elevated role memberships, and no access to databases other than their assigned targets.
  • Audit and revoke default PUBLIC connection rights on all sensitive databases.

Credential & File Handling

  • Store DATABASE_URL, REDIS_URL, and admin secrets in a secure secret manager (e.g., AWS Secrets Manager, HashiCorp Vault) rather than source control.
  • Protect data/data.json. It contains key metadata and the secret seeds used to derive database credentials for scoped roles. Set filesystem mode to 0600.
  • Never log raw API keys, passwords, or bound SQL parameter values.
  • Do not commit .env, data/, or logs/ to container images or git repositories.

Security Review Checklist

Before opening the gateway to production traffic, verify each requirement:

  • TLS 1.2+ is enforced on all ingress routes.
  • /admin/* routes are unreachable from the public internet.
  • PostgreSQL and Redis are isolated on private subnets.
  • Default PUBLIC connection and schema creation privileges are revoked on target databases.
  • Runtime files (data/data.json, logs/) are readable only by the service account (0600).
  • API keys use minimal CRUD scopes (c, r, u, d) restricted to specific tables where possible.
  • Reverse proxies have automatic POST retries disabled.
  • Dynamic SQL parameterization is strictly enforced; untrusted string concatenation is prohibited.
  • Error detail exposure (database.exposeErrorDetails) is disabled in production.

Reporting Vulnerabilities

If you discover a security vulnerability in HTTP PostgreSQL Gateway:

  • Do not open a public GitHub issue.
  • Disclose privately following the repository security policy by emailing harsh@1st-services.com.
Copyright © 2026