Skip to content

pgvector: audit partitioned tables through the parent - #18

Merged
xkimopro merged 1 commit into
Vecshield:mainfrom
nnbakirtzis:fix/pgvector-partitioned-tables
Nov 21, 2026
Merged

xkimopro merged 1 commit into
Vecshield:mainfrom
nnbakirtzis:fix/pgvector-partitioned-tables

Conversation

@nnbakirtzis

Copy link
Copy Markdown
Contributor

What this changes

Partitioned parents (relkind p) were skipped, and each partition was audited as its own table, outside the parent's RLS. As a result:

  • a BYPASSRLS retrieval role (CRITICAL) went unreported;
  • per-tenant partitions looked single-tenant;
  • the data checks never ran on the table the application actually queries.

The changes:

  • The parent is now the collection. Its partitions are listed in metadata["partitions"] via pg_partition_tree (PG 12+), and the listing degrades gracefully without it. store_facts uses the same catalog filter.
  • New HIGH rule partition_bypasses_row_security: a partition with no RLS of its own, under an RLS parent, that the retrieval role or PUBLIC can SELECT.
    • Basis, from the PostgreSQL docs (ddl-inherit): "A child table's policies, if any, are applied only when it is the table explicitly named in the query; and in that case, any policies attached to its parent(s) are ignored."
    • It is not raised for a superuser or BYPASSRLS principal, which is already reported as such. PUBLIC is always reported.
  • The rule is registered in pg_hardening_rules.json.
  • docs/pgvector.md: new section "Partitioned tables".

How you verified it

  • ruff check .: clean
  • pytest -rs with VECSHIELD_PG_DSN pointing at PostgreSQL 17.12 / pgvector 0.8.7, so the live tests ran instead of skipping. Across tests/test_pgvector.py, test_pgvector_unit.py, test_pg_access_hardening.py, test_store_facts_selfhosted.py and test_isolation.py: 279 passed, 0 skipped.
  • Full suite, with this PR merged together with the five sibling pgvector PRs: 17 failed / 3 errors. These are the same Windows-only and flaky failures main shows on this machine (symlinks, /proc, webhook sockets, test_demo). No new failures.
  • npm test: console unchanged
  • benchmark: no detector changed
  • Audited a local lab of realistic pgvector layouts as a least-privileged auditor, before and after. The layouts were LangChain, LlamaIndex, RLS multi-tenant, partitioned halfvec, and a least-privilege control.

Tests added:

  • Unit: catalog filter; partitions listed; missing pg_partition_tree; access-model partition facts; rule firing per partition (role or PUBLIC); skipped for privileged or assumed principals; rule registry.
  • Live: a partitioned table is one collection, 2 rows are read through the parent, and only the open partition is flagged.

This is one of six independent pgvector PRs, all based on main (0041576). They merge cleanly with each other in any order.

Checklist

  • No route changed.
  • No check added or renamed. access_grants gains a rule inside the existing check, so it can now fail where it used to pass.
  • No detector changed.
  • Nothing reports unknown coverage as a pass, and no partial read is reported as clean.
  • No secrets or real data: fixtures are synthetic.
  • No interface, security boundary or user-facing default changed.

A partitioned table was skipped (relkind p) and each partition audited as
a table of its own, without the parent's row security, so a BYPASSRLS
retrieval role on a partitioned RLS table went unreported and per-tenant
partitions looked single-tenant. The parent is now the collection, read as
the application reads it, with its partitions named in metadata.

Partitions are still tables to PostgreSQL: queried by name, only their own
policies apply. New HIGH rule partition_bypasses_row_security reports a
partition without row security, under an RLS parent, that the retrieval
role or PUBLIC can SELECT (ddl-inherit.html).
@xkimopro
xkimopro merged commit 03881c2 into Vecshield:main Nov 21, 2026
7 checks passed
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.

2 participants