Skip to content

feat(config): Exposure policy — narrow the auto-generated surface - #2

Merged
srmcguirt merged 1 commit into
mainfrom
feat/exposure-policy
Aug 1, 2026
Merged

srmcguirt merged 1 commit into
mainfrom
feat/exposure-policy

Conversation

@srmcguirt

Copy link
Copy Markdown
Member

Adds Exposure to Preset — the fine-grained companion to pg_schemas.

Variant Meaning
All Every relation in the configured schemas. Default; behavior unchanged.
Only(Vec<String>) Exactly the named schema.relation entries.
ExtensionsOnly No auto-generated fields at all.

Why

pg_schemas was the only exposure control and it is schema-grained. Point magna at a schema and you get every relation in it.

That is right for the gateway model — Postgres RLS plus the per-request role magna-serv sets are doing authorization. It is wrong for an embedder that pulls in magna-build/magna-dataplan/magna-core, connects with a privileged service role, and authorizes in application code. There was no way to express that case, and the failure mode is publishing every table in the schema with nothing behind it.

ExtensionsOnly is that case. Planning, fingerprint deduplication, and batched PgSelectStep all still work for extension-registered fields; no relation is reachable by default.

Design

  • One gate, in gather — not a filter at each registration pass. Everything downstream derives from GatherOutput::resources, so a filtered relation gets no object type, no query field, and no relation field pointing at it. Unreachable, not merely unqueryable at the root.
  • Dangling FKs already handled — build_relations resolves both endpoints against resources and skips when either is absent, so filtering one side of a foreign key drops the relation rather than leaving a reference to a type that was never registered. Verified with a test, not assumed.
  • Only matches the qualified name exactly — no globbing, no case folding, and an unqualified entry never matches. Every way of getting a rule wrong hides a relation instead of exposing one.
  • Silent overrides do not widen — a later PresetOverride that says nothing about exposure leaves the narrower setting alone. A silent reset to the All default would mean layering an unrelated preset re-publishes everything.

Tests

13 new, written as the security property rather than for coverage — each negative case is one where a wrong answer publishes something nobody named.

magna-config 38 passed · magna-build 173 passed · full workspace 0 failures.

Note on CI

CI on this repo has been red on main since April, independent of this change:

  • cargo fmt --all -- --check — main is drifted by 376 diffs against its own pinned rustfmt
  • cargo clippy -- -D warnings — pre-existing warnings across several crates, plus an approximate_constant error in a magna-build test

Both predate this branch and neither is touched here. Worth a separate cleanup pass. Also flagging that rust-toolchain.toml pins 1.89.0 while current stable is 1.96.0 — the workspace does build and fully pass tests on 1.96.0.

🤖 Generated with Claude Code

Adds `Exposure` to `Preset`, the fine-grained companion to `pg_schemas`:

  All              every relation in the configured schemas (default; unchanged
                   behavior, and what makes magna a Postgres gateway)
  Only(Vec<..>)    exactly the named `schema.relation` entries
  ExtensionsOnly   no auto-generated fields at all

Motivation: `pg_schemas` was the ONLY exposure control, and it is schema-
grained. An embedder pointing magna at a schema got every relation in it,
which is correct for the gateway model (Postgres RLS plus the per-request role
magna-serv sets are doing authorization) and wrong for an embedder that
connects with a privileged role and authorizes in application code. There was
no way to express the second case.

`ExtensionsOnly` is that case: planning, fingerprint deduplication, and
batched PgSelectStep still work for extension-registered fields, but no
relation is reachable by default.

Design notes:

* The gate is ONE check in `gather`, not a filter at each registration pass.
  Everything downstream derives from `GatherOutput::resources`, so a filtered
  relation gets no object type, no query field, and no relation field pointing
  at it — unreachable rather than merely unqueryable at the root.

* `build_relations` already resolves both FK endpoints against `resources` and
  skips when either is absent, so filtering one side of a foreign key drops
  the relation instead of leaving a reference to an unregistered type. Covered
  by a test rather than assumed.

* `Only` matches the QUALIFIED name exactly — no globbing, no case folding,
  and an unqualified entry never matches. Every way of getting a rule wrong
  therefore hides a relation instead of exposing one.

* A later `PresetOverride` that is silent about exposure leaves the narrower
  setting alone. A silent reset to the `All` default would mean layering an
  unrelated preset re-publishes every relation.

The default is unchanged: `Preset::default()` is still `Exposure::All`.

13 tests, written as the security property — each negative case is one where
a wrong answer publishes something nobody named.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Aug 1, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2d40a20

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@srmcguirt
srmcguirt merged commit 7005a2b into main Aug 1, 2026
2 of 4 checks passed
@srmcguirt
srmcguirt deleted the feat/exposure-policy branch August 1, 2026 14:35
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