Skip to content

flowctl: fetch storage mappings via GraphQL instead of PostgREST - #3238

Draft
GregorShear wants to merge 4 commits into
masterfrom
greg/flowctl-gql-storage-mappings
Draft

flowctl: fetch storage mappings via GraphQL instead of PostgREST#3238
GregorShear wants to merge 4 commits into
masterfrom
greg/flowctl-gql-storage-mappings

Conversation

@GregorShear

@GregorShear GregorShear commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Resolves storage mappings during flowctl source loading through the control-plane storageMappings GraphQL query instead of PostgREST.

Stacked on #3242 — uses the new filter: { catalogPrefix: { in } } predicate that PR adds. Review/merge #3242 first.

Why

The PostgREST path relied on row-level security, whose grant graph only walks downward: a user scoped to a sub-prefix (e.g. acmeCo/team-a/) could not read the tenant-root mapping at acmeCo/, so flowctl discover failed with an access error. The GraphQL resolver authorizes against the snapshot grant graph, which walks ancestors as well as descendants, so sub-prefix admins resolve tenant-root mappings correctly.

How

  • Requested prefixes are grouped by tenant; each group is fetched with filter: { catalogPrefix: { in: [...] } } (exact-set match) plus cursor pagination.
  • Keeping each tenant in its own request means an unreadable foreign tenant — reachable through a cross-tenant reference — fails only its own request rather than hiding a readable tenant's mappings. Such a group is treated as having no visible mappings and logged at debug level; transport/HTTP errors still propagate.
  • Recovery mappings continue to be synthesized client-side with a zero control id.

Note on the filter

Originally written against by: { exactPrefixes }. Rebased onto #3242 to use the going-forward filter: { catalogPrefix: { in } } predicate instead — the deprecated by argument stays available but this is the pattern the UI and flowctl now share.

Testing

  • local_specs unit tests green (per-tenant grouping, URL-budget chunking).
  • cargo check -p flowctl and cargo fmt clean.

…pings` query

Adds an optional `filter: StorageMappingsFilter` argument to `storageMappings`,
following the composable-filter pattern used by `inviteLinks` (and the in-flight
`dataPlanes` filter). Its one field, `catalogPrefix: PrefixFilter`, narrows to a
catalog-prefix subtree — the same scoping the deprecated `by: { underPrefix }`
provides.

`catalogPrefix.startsWith` folds into the existing `under_prefix` code path, so
it flows through `authorized_prefixes` (bidirectional prefix overlap against the
caller's grants) and the query's subtree predicate unchanged. Predicates only
narrow; the caller's catalog-read scope is enforced regardless, so a filter can
never widen what a caller may see, and omitting it behaves exactly as before.

`by` and `filter` are mutually exclusive: they express the same subtree scoping
two ways, and rejecting both keeps the resolved scope unambiguous. `by` stays
for now — flowctl still uses it, and its `exactPrefixes` lookup has no `filter`
equivalent yet — but is re-deprecated to point callers at `filter`.

This is the schema half of migrating the UI's storage-mappings table off the
`by:` convention onto the filter-param pattern; the query shape is otherwise
unchanged, so existing consumers are unaffected.
…fixFilter`

Extends `PrefixFilter` with `in: [String!]`, an exact-set match alongside the
existing `startsWith` subtree match, and wires it into every consumer so the
new field is never a silent no-op:

- `storageMappings`: `filter.catalogPrefix.in` maps to the `exactPrefixes` path,
  the way `startsWith` maps to `underPrefix`. Within a filter the two are
  alternative query modes and are mutually exclusive (as `by`'s own
  `exactPrefixes`/`underPrefix` already are).
- `inviteLinks` and `alertConfigs`: add an exact-equality WHERE clause, and
  narrow the authorized-prefix set by the `in` entries before the MAX_PREFIXES
  guard — the same narrowing `startsWith` already provides as a hint — so a
  caller with many grants isn't forced to page.

Filtering stays narrow-only: predicates run against the caller's authorized
prefixes, so `in` can never widen what a caller may see, and an entry the
caller can't read (or that matches nothing) simply falls out.

This makes `in` the single exact-match predicate on `PrefixFilter`, so a set of
prefixes can be resolved in one request. It supersedes the separate single-value
`is` field, which is dropped in the stacked effectiveAlertConfig change.
… queries

Extending the shared `PrefixFilter` with `in` regenerates every graphql_client
consumer's copy of the input, so flowctl's `alerts config` list/lookup queries
must now name the field. Set `in_: None` — these paths filter by `startsWith`
only, so behavior is unchanged; this just keeps the workspace compiling against
the new schema.
Resolve storage mappings during `flowctl` source loading through the control-plane `storageMappings` GraphQL query rather than PostgREST.

The prior PostgREST path relied on row-level security, whose grant graph only walks downward: a user scoped to a sub-prefix (e.g. `acmeCo/team-a/`) could not read the tenant-root mapping at `acmeCo/`, so `flowctl discover` failed with an access error. The GraphQL resolver authorizes against the snapshot grant graph, which walks ancestors as well as descendants, so sub-prefix admins resolve tenant-root mappings correctly.

Requested prefixes are grouped by tenant and each group is fetched with the `filter: { catalogPrefix: { in } }` exact-set predicate (with pagination). Keeping each tenant in its own request means an unreadable foreign tenant — reachable through a cross-tenant reference — fails only its own request rather than hiding a readable tenant's mappings; such a group is treated as having no visible mappings and logged at debug level. Recovery mappings continue to be synthesized client-side with a zero control id.
@GregorShear
GregorShear force-pushed the greg/flowctl-gql-storage-mappings branch from c02cdef to 31ad5e7 Compare July 23, 2026 20:25
@GregorShear
GregorShear changed the base branch from master to greg/gql-storage-mappings-filter July 23, 2026 20:26
@GregorShear
GregorShear force-pushed the greg/gql-storage-mappings-filter branch 3 times, most recently from 572cb9c to 95c7343 Compare July 24, 2026 20:38
Base automatically changed from greg/gql-storage-mappings-filter to master July 27, 2026 19:57
@GregorShear
GregorShear marked this pull request as draft July 30, 2026 16:50
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