Skip to content

Security

Tenant mTLS, certificate identities, database roles and grants.

A pgetcd gateway process authenticates one tenant principal over mTLS and connects to that tenant’s fixed PostgreSQL database using a restricted SQL role. It does not implement the etcd Auth service, RBAC roles, or per-key authorization.

Client to gateway

The gRPC listener requires TLS 1.2 or later and a verified client certificate (RequireAndVerifyClientCert). After X.509 chain verification against tls.client_ca_file, the gateway requires an exact URI Subject Alternative Name (SAN) match with the tenant’s configured tls.client_uri.

The standard URI format is spiffe://pgetcd/tenant/<tenant_id>. Trust in the same CA is not sufficient on its own: a valid certificate carrying another tenant’s URI SAN is rejected during the TLS handshake. If tls.server_name is configured, clients must also present that exact SNI hostname; connecting to an IP literal requires a matching IP SAN on the server certificate.

The operational HTTP listener (listen_http) enforces the exact same tenant mTLS policy. Its /livez, /readyz, /health, /metrics, and /version routes are not anonymous probes. Diagnostics use a separate HTTP/1.1 listener, while etcd application RPCs use gRPC over HTTP/2 on listen_grpc.

The internal -p0-fixture flag binds only to an explicit loopback IP (127.0.0.1 or ::1) using plaintext. It exists solely for local feasibility harnesses and does not provide tenant mTLS or the production Watch service.

Gateway to PostgreSQL

The tenant configuration file fixes db_name and role, and PGETCD_DSN must resolve to that exact pair. Client requests, gRPC metadata, and key prefixes cannot select a different database or role.

In production tenant mode, every PostgreSQL connection alternative in PGETCD_DSN must use sslmode=verify-full with certificate and hostname verification. Plaintext or unverified TLS fallbacks (disable, allow, prefer, require, verify-ca) are rejected unless -allow-insecure-pg-tls is explicitly passed for local development. The DSN is read from the environment and is never echoed in public diagnostics or error messages.

Gateway configuration checks do not grant or prove PostgreSQL privileges. Operators must provision two separate non-superuser roles in PostgreSQL:

  • pgetcd_owner (NOLOGIN): Owns the etcd schema, its seven tables, and its SECURITY DEFINER functions, without superuser, replication, or login privileges.
  • Gateway runtime role (LOGIN): Granted CONNECT on the tenant database, USAGE on schema etcd, and EXECUTE on etcd._abi(), etcd._execute(jsonb), etcd._tail_v2(bigint, integer), and etcd._publication_barrier(). It must not own the extension, inherit pgetcd_owner, or hold direct table privileges.

The extension installation script revokes PUBLIC access. Granting ALL on schema etcd or adding the gateway role to pgetcd_owner defeats this privilege boundary.

Resource admission

The gateway bounds concurrent TCP connections, gRPC message sizes (2 MiB input, 8 MiB output), publication flight slots (max_inflight = 64), Watch queues (queue_capacity = 128), and per-stream watcher counts (max_streams_per_conn = 256). Inside PostgreSQL, pg_etcd checks response and complete-revision byte budgets before committing mutations.

These limits operate at the request and stream layers; a response-size cap does not bound total PostgreSQL query memory, temporary disk spill, WAL growth, or overall OS memory. Attempts to bound cold-start Go runtime and Linux kernel memory accounting in the experimental native P3 line are documented in Frozen native line.

Graceful shutdown preserves resource ownership for in-flight work. A client cancellation or timeout never releases a PostgreSQL connection whose COMMIT is still in flight, and a Watch sender’s memory credit remains occupied until that sender goroutine exits.

Authority and isolation

Mutual TLS authenticates the peer identity, but it does not prove that the target PostgreSQL instance is the sole active primary. A SQL pg_is_in_recovery() check, a reachable TCP address, or a cached authority record cannot replace primary fencing during a network partition.

For multi-node deployments, primary authority verification, stale-route retirement, and split-brain fencing are tracked in the post-MVP HA roadmap.

Validation boundary

On v0.1.0-rc2 (commit 81691bc, Linux amd64, PostgreSQL 18.6, 2026-11-08), the internal/transport mTLS tests, including rejection of another tenant’s trust and SNI, passed, and the etcdctl probes confirmed that a valid certificate for another tenant is refused. The frozen P1 single-primary candidate (e37e197, 2026-10-08) verified tenant mTLS enforcement, cross-tenant URI SAN rejection, SNI checks and restricted database role boundaries in its integration suites.

Source: internal/transport/mtls.go, internal/tenant/config.go, internal/pgstore/tenant.go, cmd/pgetcd/main.go, and extension/pg_etcd--0.1.0.sql.

Scan to open this page
https://mimus.pgsty.com/docs/etcd/architecture/security/