Repository navigation
feat(config): Exposure policy — narrow the auto-generated surface - #2
Merged
Merged
Conversation
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>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
ExposuretoPreset— the fine-grained companion topg_schemas.AllOnly(Vec<String>)schema.relationentries.ExtensionsOnlyWhy
pg_schemaswas 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-servsets are doing authorization. It is wrong for an embedder that pulls inmagna-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.ExtensionsOnlyis that case. Planning, fingerprint deduplication, and batchedPgSelectStepall still work for extension-registered fields; no relation is reachable by default.Design
gather— not a filter at each registration pass. Everything downstream derives fromGatherOutput::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.build_relationsresolves both endpoints againstresourcesand 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.Onlymatches 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.PresetOverridethat says nothing about exposure leaves the narrower setting alone. A silent reset to theAlldefault 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-config38 passed ·magna-build173 passed · full workspace 0 failures.Note on CI
CI on this repo has been red on
mainsince April, independent of this change:cargo fmt --all -- --check—mainis drifted by 376 diffs against its own pinned rustfmtcargo clippy -- -D warnings— pre-existing warnings across several crates, plus anapproximate_constanterror in amagna-buildtestBoth predate this branch and neither is touched here. Worth a separate cleanup pass. Also flagging that
rust-toolchain.tomlpins 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