Skip to content

Add PostgreSQL Policy Guard and multi-database discovery adapters - #30

Draft
Agata-Proxima wants to merge 543 commits into
mainfrom
feature/postgres-rls-posture-audit
Draft

Agata-Proxima wants to merge 543 commits into
mainfrom
feature/postgres-rls-posture-audit

Conversation

@Agata-Proxima

@Agata-Proxima Agata-Proxima commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds the Engine-side PostgreSQL Policy Guard work and establishes the database-independent adapter boundary for Proxima Security Core.

Database-independent core

  • Adds the DatabaseAdapter trait and registry for native inspection, policy compilation, verification and drift detection.
  • Hardens the proxima.security.v1 Rust policy model with unknown-field rejection, schema-aligned length limits, NUL rejection and duplicate-resource/operation checks.
  • Makes database-kind serialization explicit and exposes the Engine CLI adapter catalog with scope: engine_runtime.
  • Keeps adapter maturity explicit. PostgreSQL, MySQL/MariaDB, SQL Server, MongoDB, Redis, CockroachDB, SQLite and Elasticsearch/OpenSearch expose only the concrete capabilities implemented; Oracle, DynamoDB, Cassandra and VAULTDB remain planned.

PostgreSQL Policy Guard CLI

  • Read-only PostgreSQL catalog posture audit over verified TLS, with optional private CA support.
  • Reports RLS enabled/forced state, table-owner bypass paths including inherited role membership, PUBLIC grants, inherited SUPERUSER/BYPASSRLS grants, permissive policy counts and SECURITY DEFINER routines.
  • Generates deterministic role-bound SQL with identifier/value escaping, identifier limits, duplicate mapping checks and transactional preflight.
  • Requires one global PROXIMA_TENANT_ROLE_PREFIX plus normalized verified tenant ID; arbitrary per-tenant role aliases are rejected and the required prefix is printed in generated SQL.
  • Preflight rejects tenant roles with elevated attributes, role memberships, database/schema CREATE privileges, non-login roles or unsafe search_path defaults.
  • Preflight refuses partitioned relations and dependent views that are not security-invoker, and refuses materialized views until separately protected.
  • The CLI generates SQL for review; it does not execute DDL. Its posture report remains inspection-only and never claims verified isolation from a clean catalog scan.

Runtime tenant-session guard

  • Parses PostgreSQL simple-query and extended-protocol Parse frames for tenant-bound sessions.
  • Rejects role/session-authorization changes, attempts to disable row security, sensitive set_config calls, DO/CALL, TRUNCATE, DDL, mutable search_path/SCHEMA settings and startup overrides.
  • Rejects legacy FunctionCall protocol messages on tenant-bound sessions.
  • Fails closed when SQL parsing or tokenization cannot validate the statement.

Safety boundary

  • PostgreSQL privileges and RLS remain authoritative.
  • The SQL guard is conservative session protection, not a complete SQL semantic authorization engine or query-rewriting proxy.
  • The CLI audit/generator is operator-invoked; hosted policy lifecycle and drift monitoring remain in the Cloud control plane.
  • The adapter registry remains a production gate and accepts only adapters marked supported with all eight end-to-end capabilities. The in-development native discovery modules are operator-invoked through Policy Guard; they are not registered for runtime admission. No non-PostgreSQL adapter is claimed as production-supported. VAULTDB remains a research target only.

Validation

Unit tests were added for policy validation, SQL generation, identifier escaping/limits, role mapping, owner bypass, startup restrictions and SQL guard behavior. No build or test command was run in this authoring session. GitHub Actions were not triggered because CI minutes are unavailable. Local acceptance is the next step.

Post-review hardening

  • Verification reports now fail closed when their security-model version is unknown, with a regression test added.
  • The adapter registry remains a production gate; PostgreSQL and the non-PostgreSQL adapters remain in development. Discovery implementations are not represented as complete enforcement adapters.

The PR remains a draft. No build, test suite, live database acceptance, or GitHub Actions workflow was run; owner-run local acceptance remains required.

Multi-database policy-plan and evidence work added after the initial review

  • Added review-only native policy-plan compilers for SQL Server RLS, MySQL/MariaDB database-per-tenant grants, MongoDB database-per-tenant collection roles and Redis tenant-key ACL templates.
  • Added proxima-policy-guard compile-plan for those five database families. The command emits reviewable JSON and does not connect to a database or execute changes.
  • Expanded the catalog to include Redis, SQLite, Oracle, DynamoDB, Cassandra and Elasticsearch/OpenSearch in addition to the earlier database kinds. SQL Server, MySQL/MariaDB, MongoDB and Redis have review-only native policy compilers. CockroachDB and SQLite have separate read-only catalog discovery adapters; Elasticsearch/OpenSearch has HTTPS index/mapping/security-role discovery. All these non-PostgreSQL adapters remain in development and expose no runtime tenant enforcement or production admission.
  • Added HMAC-signed policy evidence and a maximum-60-second admission-envelope primitive bound to exact policy revision, target, tenant and evidence digest.

Remaining implementation and acceptance gates

  • MySQL/MariaDB, SQL Server, MongoDB, Redis, CockroachDB, SQLite and Elasticsearch/OpenSearch now have concrete native catalog discovery and fingerprint-based drift inspection paths, with direct Policy Guard discovery/inspection commands. MySQL/MariaDB, SQL Server, MongoDB and Redis also have review-only policy compilers. These are still not complete enforcement adapters: controlled policy deployment, independently executed semantic probes, tenant-principal binding, runtime fail-closed admission and signed per-operation data-plane evidence remain unimplemented for these database families.
  • The PostgreSQL startup/session path now verifies one-time signed Control Plane decisions; Cloud persists rate-bounded signed posture snapshots and exposes them in the dashboard. The generic PolicyEvidenceAuthority envelope remains separate, and independent positive/negative data-plane probes remain outstanding.
  • No new tests or builds were executed. No CI/GitHub Actions were triggered. Local database and adversarial acceptance remain required; keep this PR draft.

Implementation-state audit: docs/IMPLEMENTATION_AUDIT_2026-11-17.md. It records which adapters have native discovery versus policy compilation, which enforcement capabilities remain absent, that generic evidence primitives are not all wired into runtime/Cloud, and that local acceptance is outstanding.

Production adapter registry gate

The Engine registry now rejects adapters unless maturity is supported and all eight end-to-end capability flags are true. Unit tests cover rejection of review-only/partial descriptors and acceptance of a complete descriptor. The gate prevents accidental registration; it does not implement or promote any database adapter.

PostgreSQL runtime admission and observability integration — 17 November 2026

  • Wired the signed Control Plane posture check into PostgreSQL protocol startup before ReadyForQuery is released, and into five-second active-session rechecks.
  • Every request now carries a fresh random request ID, and every response must match that ID, node, target, database, tenant, role prefix, timestamp and 15-second expiry. Cached allow decisions were removed; redirects are disabled for the signed admission client.
  • The signed response includes the per-registration evidence object and is verified as part of the HMAC-covered payload.
  • Added Prometheus counters for admission checks, allows, denies and active-session revocations.
  • The generic PolicyEvidenceAuthority envelope remains a separate library primitive; the PostgreSQL path currently consumes the Cloud's node-key-signed decision/evidence format. Independent positive and cross-tenant negative data probes remain an acceptance gap.

No Rust build, tests, live PostgreSQL test or GitHub Actions workflow was run. Keep this PR draft until owner-run local and adversarial acceptance is complete.

Additional native discovery adapters — 17 November 2026

  • Added CockroachDB discovery over the PostgreSQL wire protocol with server identity verification, table/view/column/grant inventory, bounded fingerprints and drift detection. It does not assume PostgreSQL RLS semantics.
  • Added SQLite read-only file discovery with attached-database rejection, schema/index/foreign-key/trigger inspection, filesystem mode checks for the database, parent directory and WAL/SHM sidecars, and drift fingerprints. Windows ACL inspection is not implemented.
  • Added Elasticsearch/OpenSearch HTTPS discovery for index mappings, settings, aliases, native security roles/users and DLS role coverage. Missing security API permissions are represented as incomplete inspection; user credential/hash fields are redacted.
  • Added bounded discovery deadlines and tightened native inspection identities: inherited elevated PostgreSQL roles, overprivileged SQL Server roles/object grants, MongoDB connection and whole-operation deadlines and MySQL/MariaDB read-only statement settings.
  • All three new adapters and the other non-PostgreSQL discovery modules remain in_development; their verification paths deny admission. No Rust build, unit tests, live database acceptance or CI workflow was run. Keep this PR draft.

@Agata-Proxima Agata-Proxima changed the title Add PostgreSQL RLS posture audit and managed policy SQL generator Add PostgreSQL RLS Policy Guard and tenant-session SQL protections Nov 16, 2026
@Agata-Proxima Agata-Proxima changed the title Add PostgreSQL RLS Policy Guard and tenant-session SQL protections Add Proxima adapter contract and PostgreSQL Policy Guard protections Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant