Skip to content

melange v0.11.0

Latest

Choose a tag to compare

@github-actions github-actions released this 09 Nov 17:31
· 2 commits to main since this release

SQL API, security and performance release. Choose which relations and function families a database installs, and filter your own queries by access with inlinable accessible_* functions and parent-key forms. Paged lists now do the work of one page and generated functions are planned once per session. Depth limits and cycles follow OpenFGA. Fixes a check that let userset subjects through constrained grants and a migrate that dropped RLS policies with CASCADE.

📖 Full write-up: Melange v0.11.0 release notes

Run melange validate with the v0.11.0 CLI first: some schemas with cycles through and or but not are now rejected. Then run melange migrate; the security fixes take effect only after migrating. Upgrade the Go runtime for the contextual tuples fix. Lists past the depth limit now raise M2002 instead of returning a truncated result. Without an sql: section in melange.yaml, every relation and function family is still installed.

⚠ Breaking Changes

  • schema: reject a relation that resolves back to itself on the same object through an intersection or exclusion operand, such as a: [user] or (b and c) with b: [user] or a. OpenFGA rejects these with 2056 (#137).

  • sqlgen: raise M2002 past the depth limit in recursive list_objects and list_subjects and in nested group walks, instead of silently truncating at 25 levels (#137).

    Matches OpenFGA v1.22.1: 24 levels list and 25 fail, and a userset or cross-type step at the end of a parent chain counts toward the limit.

  • migrator: refuse to drop orphaned functions that views, materialized views, RLS policies, rules or BEGIN ATOMIC functions depend on, unless forced (#138).

    The error lists the dependents. Unforced drops and generate migration UP files no longer use CASCADE. See Dependent objects.

  • sqlgen: declare every check function COST 1000, so queries and RLS policies that call check_<type>_<relation> directly can plan differently (#139).

Security

  • sqlgen: check userset subjects against constrained grants (#137).

    For viewer: [user, group#member] and member from owner, check_permission said group:eng#member was a viewer with no member on the owner, and the same held through implied relations whose grant sat in an intersection or under an exclusion. Wildcard tuples also matched userset subjects in some probes. Plain subjects were not affected.

  • migrator: stop unforced drops from removing dependents with CASCADE (#138).

    Removing a relation dropped its functions with CASCADE, which also dropped RLS policies that called them and widened access to their tables.

  • checker: see contextual tuples on a session reused after plain calls (#137).

    PL/pgSQL kept statements resolved against the base view, so on a pooled session a contextual request after a plain one ignored its tuples. Cleanup now drops the view under its own timeout and closes the connection if the drop fails, so a driver that keeps a cancelled session open can no longer leave the view granting its tuples to later requests. pgx and lib/pq were not affected by the latter.

Features

  • sqlgen: generate only the exposed SQL API and what it depends on (#138).

    The new sql: section of melange.yaml (and --include-relation, --exclude-relation, --no-<family>) names the exposed relations and the list_objects, list_subjects, accessible, parent_key, expand and explain families. Migrate installs those and every relation they resolve through, and records the exposure in melange_migrations. Public functions raise M2003 for unexposed relations, mapped to ValidationError in the Go and TypeScript runtimes. status and doctor report exposure drift. See Exposure.

  • sqlgen: generate inlinable accessible_{type}_{relation} functions and accessible_objects for filtering your own queries (#137).

    PostgreSQL inlines the per-relation function, so your filters, sort and limit are planned with the access set. On the kitchen sink at 1M, a page of 50 documents by name went from 158 ms to 42 ms against IN list_accessible_objects.

  • sqlgen: generate parent-key functions accessible_{type}_{relation}_by_{link} for relations granted only through one parent link (#137).

    They return parent IDs, so you filter the link column. For a viewer of a 1M-subject organization, a count went from about 4 s to 70 ms, and a LATERAL page per parent took 0.9 ms.

  • cli: add melange functions and a Studio SQL API page: every function a model compiles to, with exact names, signatures, example calls and drift against pg_proc (#138, #139).

  • clientgen: emit exact accessible function names (SQLAccessibleDocumentViewer, TypeScript AccessibleFunctions) and follow the exposure; add generate client --check and a Generated Client category in doctor (#138).

  • cli: compile explain and expand on demand in pg_temp when their family is not installed, for melange explain, melange expand and Studio (#138).

  • migrator: predict what an unforced migrate would do (Migrator.Plan), and use it for doctor fix hints that work (#138).

  • schema: accept parent lookups that cycle across types while changing relation, as OpenFGA does (#137).

  • studio: larger type, more spacing and neutral badges for expected states across every page (#139).

Bug Fixes

  • sqlgen: count check resolution steps like OpenFGA: resolve 25 hops and raise M2002 at 26 (#137).
  • sqlgen: stop userset-filter list_subjects recursing until stack depth limit exceeded on parent cycles (#137).
  • sqlgen: match the userset relation exactly in nested group walks, where LIKE let an underscore match any character (#137).
  • sqlgen: resolve the linking types of excluded intersection parts, and reference only the parent types of intersection tuple-to-userset parts (#137, #138).
  • migrator: refuse exposure changes through MigrateWithTypes, which records no migration (#138).
  • doctor: report as orphans only the functions the last migration recorded, and suggest a per-call expand leaf cap instead of a session setting that does not exist (#138, #139).

Performance

  • sqlgen: paginate list_objects as a top-k query, and page tuple-to-userset compositions a parent at a time (#137).

  • sqlgen: plan generated functions once per session with JIT off, fold userset arms at plan time, and call check functions directly instead of through the dispatcher (#137, #139).

  • sqlgen: anchor intersection list_subjects on direct tuples and parent lookups instead of every subject, walk recursive lists breadth first, and look up subject-keyed sets with = ANY(ARRAY(...)) (#137). doctor gains a subject_lookup_indexes check.

    Cloud SQL for PostgreSQL 18.6, same instance and client, medians of six runs:

    Benchmark v0.10.3 v0.11.0
    SaaS ListSubjects 1M, readers of the largest org's contacts 206,743 ms 25.3 ms
    SaaS ListObjects 1M, first page of 50 contacts, partner 3,457 ms 6.1 ms
    ListObjects 1M, pull requests, page of 10 117.5 ms 6.9 ms
    Kitchen sink ListObjects 1M, document can_edit 69.5 ms 5.4 ms
    Kitchen sink ListObjects 1M, document can_view 434.8 ms 156.4 ms

    Outside the OpenFGA suite, 180 of 439 benchmarks are more than 10% faster and 33 more than 10% slower, mostly SaaS checks (worst: org can_read for a partner, 0.91 ms to 1.17 ms).

Documentation

  • docs: update the Performance reference to a Cloud SQL run of 0.11.0 on PostgreSQL 18 (#143).
  • docs: document the exposure, accessible and parent-key functions, on-demand explain and expand, fix hints and dependent objects across the SQL API, configuration, CLI, migrations, Studio and troubleshooting pages (#138, #139).

Testing

  • openfgatests: compare the accessible and parent-key functions with every list and check assertion (1,330 list and 1,834 check comparisons), page every list_objects assertion in pages of 1 and 2, and replay 232 cases under a restricted exposure (#137, #138).
  • openfgatests: fuzz accessible functions and random restricted exposures against OpenFGA (#138).
  • test: add BenchmarkSaaS, a multi-tenant model with tiered roles, partner orgs, staff access and a 27-branch view at 100K, 1M and 5M tuples (#137).
  • bench: run the cloud benchmark on PostgreSQL 18 (#142).

Full Changelog: v0.10.3...v0.11.0