Skip to content

fix(opa-bridge,catalog): check the objects Trino acts on, and refuse names that clients cannot address - #2215

Merged
c-thiel merged 13 commits into
mainfrom
christian/trino-bridge-security
Nov 3, 2026
Merged

c-thiel merged 13 commits into
mainfrom
christian/trino-bridge-security

Conversation

@c-thiel

@c-thiel c-thiel commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Stacked on #2115. The Trino OPA bridge now checks exactly the objects Trino acts on, with secure defaults for replace, metadata tables and drops.

BEGIN_COMMIT_OVERRIDE
fix(management): resolve by-name permission checks to the live table or view
fix(opa-bridge): refuse schema, table and view names that Trino or Lakekeeper rewrite
fix(opa-bridge)!: require commit on the existing table or view for CREATE OR REPLACE
fix(opa-bridge): match Trino's metadata-table names and check a view of the same name
fix(opa-bridge): deny a batch check whose results are incomplete
docs(opa-bridge): explain which files add_files can read
fix(opa-bridge)!: require read_data for metadata tables that show data values
fix(opa-bridge): describe Trino's purge and cascade in drop checks
fix(catalog): refuse '+' and control characters in new names
END_COMMIT_OVERRIDE

Changes

  • Names: the bridge refuses and hides schema, table and view names that Trino or Lakekeeper would rewrite: +, U+001F, empty schema parts, and white space or control characters at the start or end of a schema part. Lakekeeper refuses + and control characters in new table, view and generic-table names and rename targets.
  • Metadata tables: only <table>$<type> with a type Trino 484 knows is a metadata table, checked on the base table. Other names with $ or @ are refused, and so is $materialized_view_storage, which Trino cannot read from Lakekeeper. On Trino before 484, the bridge also checks a view with the same name.
  • Metadata tables with data values ($files, $entries, $all_entries, $manifests, $all_manifests, $partitions) need read_data.
  • CREATE OR REPLACE also needs commit of any kind on an existing table or view; write is not enough.
  • Drops are checked with purge; DROP SCHEMA as a recursive delete with purge.
  • Batch checks with incomplete results deny.
  • Management API: permission checks by name resolve to the live table or view, in batch-check and in OpenFGA's /management/v1/permissions/check.

Operators

  • Deploy the bridge policies together with the Lakekeeper server of this release.
  • Give roles that replace tables or views through Trino (for example dbt models) commit on them; with OpenFGA, modify.
  • Give users who read the metadata tables with data values read_data on the table.
  • Rename tables, views and schemas with refused names if Trino users need them.
  • Leave iceberg.rest-catalog.case-insensitive-name-matching off in the Trino catalog.

Release notes

  • Trino bridge: CREATE OR REPLACE needs commit on the existing table or view. Roles that replace tables or views through Trino, such as dbt models, need commit. With OpenFGA, give them modify.
  • Trino bridge: metadata tables that show data need read_data. $files, $partitions and similar need permission to read the table's data. $snapshots, $history and similar keep working with metadata access. $materialized_view_storage is denied, because Trino cannot read it from Lakekeeper.
  • Trino bridge: names that Trino could read differently are refused. Table and view names with $ or @, except metadata tables such as orders$snapshots, and names that Trino or Lakekeeper would change are refused and hidden. Rename such objects if Trino users need them.
  • Trino bridge: drops are checked with purge. Dropping a schema is checked as a recursive delete.
  • Catalog: + and control characters are refused in new names. Generic-table names with + now return InvalidTableName.
  • Management API: permission checks by name use the live table or view. Use the id to check a dropped object.

Downstream follow-up

  • CatalogStore::get_tabular_infos_by_ident_impl returns one tabular per name: the live one, or the most recently dropped one if dropped tabulars are included.
  • By-name batch checks no longer see dropped or staged tabulars; use ids. The same holds for by-name checks of OpenFGA's /management/v1/permissions/check.
  • HidingAuthorizer (test-utils): with <kind>:ReadGrants blocked, table, view and generic-table checks for another principal (not delegated) fail with CannotInspectPermissions, as grant checks do. Tests that block table:ReadGrants, view:ReadGrants or generic_table:ReadGrants and then check for another principal get a 403 in place of a result.
  • New 400s: InvalidTableName for + or control characters in new or renamed tabular names (generic tables returned InvalidName), InvalidNamespace for control characters in the last part of a new or moved namespace.
  • Bridge Rego: require_* helpers, namespace_for_schema, child_schema_name and split_metadata_table_name are undefined for refused names. is_metadata_table follows Trino 484, except that $materialized_view_storage is not a metadata table. New: metadata_table_read_action, require_metadata_table_view_access, require_{table,view,schema}_access_drop. The drop and replace check bodies changed. lakekeeper.* single checks need status 200, and batch_check_results* are undefined for incomplete results.

Summary by CodeRabbit

  • Authorization
    • Trino checks now apply specific permissions to table and view creation, replacement, deletion, and metadata reads. Metadata-table permissions vary by table type, with additional view checks on older Trino versions.
    • Failed or incomplete batch authorization responses deny access to affected resources, which are hidden from filtered results.
    • Permission checks on behalf of another principal require permission to inspect grants.
  • Validation
    • New tables, views, and generic tables—and rename destinations—reject unsupported names. New namespaces reject control characters.
  • Behavior
    • Name-based checks resolve live objects; dropped or staged objects require UUIDs.
  • Documentation
    • Updated guidance covers naming rules, authorization, and batch-check behavior.

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The pull request updates Trino-to-Lakekeeper authorization checks for canonical names, metadata-table reads, replacement and drop operations, and batch responses. It also changes Lakekeeper name validation and tabular lookup behavior, and adds permission-inspection checks for batch authorization.

Changes

Trino authorization policies

Layer / File(s) Summary
Lakekeeper check and batch contracts
authz/opa-bridge/policies/lakekeeper/check.rego, authz/opa-bridge/tests/trino/incomplete_batch_test.rego, docs/docs/opa.md
Single checks require HTTP 200 and exactly one allowed result. Batch checks use configured chunking and require complete result arrays in input order. Tests cover failed, incomplete, and unexpected responses.
Canonical identifiers and batch routing
authz/opa-bridge/policies/trino/check.rego, authz/opa-bridge/policies/trino/check_batch.rego, authz/opa-bridge/policies/trino/allow_schema.rego, authz/opa-bridge/policies/trino/allow_table.rego, authz/opa-bridge/policies/trino/allow_view.rego, authz/opa-bridge/tests/trino/identifiers_test.rego, authz/opa-bridge/tests/trino/batch_routing_test.rego, docs/docs/opa.md
Schema and tabular checks require canonical names. Batch routing excludes noncanonical resources. Tests cover identifier rewriting and batch result alignment.
Create, replace, rename, and drop checks
authz/opa-bridge/policies/trino/*, authz/opa-bridge/tests/trino/drop_test.rego, authz/opa-bridge/tests/trino/replace_test.rego, authz/opa-bridge/tests/trino/write_test.rego, docs/docs/opa.md, docs/docs/logging.md, docs/docs/authorization-openfga.md
Create checks include replacement authorization when a target exists. Drop checks include purge flags, and schema deletion includes recursive purge. Tests verify check payloads and authorization outcomes.
Metadata-table read authorization
authz/opa-bridge/policies/trino/allow_table.rego, authz/opa-bridge/policies/trino/check.rego, authz/opa-bridge/policies/trino/main.rego, authz/opa-bridge/tests/trino/metadata_*_test.rego
Recognized metadata-table types map to read_data or get_metadata on the base table. Older Trino versions also check a same-named view.

Tabular name validation and lookup

Layer / File(s) Summary
Creation and rename name validation
crates/lakekeeper/src/server/*, crates/lakekeeper-integration-tests/src/internal_helper.rs, crates/lakekeeper-integration-tests/tests/server_*
Shared validators reject specified tabular names and control characters in a newly created namespace’s final segment. Integration tests cover create and rename operations.
Live name lookup and identifier resolution
crates/lakekeeper/src/api/management/v1/check.rs, crates/lakekeeper-storage-postgres/src/tabular/*, crates/authz-openfga/src/check.rs, crates/lakekeeper-integration-tests/tests/management_check.rs, docs/docs/api/management-open-api.yaml
Name-based checks fetch active tabulars. Identifier lookups that include deleted tabulars select a live match or, if none exists, the most recently dropped match. Tests cover name and ID lookups.

Permission-inspection gate

Layer / File(s) Summary
Shared ReadGrants checks
crates/lakekeeper/src/service/authz/mod.rs, crates/lakekeeper-integration-tests/tests/management_check.rs
A shared helper checks permission-inspection access for another principal. Table, view, and generic-table batch checks apply the gate outside delegated execution.

Estimated code review effort: 5 (Critical) | ~100 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Trino
  participant TrinoOPA as Trino OPA policy
  participant Lakekeeper
  Trino->>TrinoOPA: Authorize CreateTable
  TrinoOPA->>Lakekeeper: Check namespace create access
  TrinoOPA->>Lakekeeper: Check commit access if the name is occupied
  Lakekeeper-->>TrinoOPA: Return authorization check results
  TrinoOPA-->>Trino: Return authorization decision
Loading

Possibly related PRs

  • lakekeeper/lakekeeper#2153: Both changes update batch routing in check_batch.rego and affect which resources use fast-path results.
  • lakekeeper/lakekeeper#2115: This PR uses commit-access checks for table and view replacement, building on the commit-access contract.
Merge Risk: Low · up to 81555

The batch-check guidance now matches the policy. A previously reported $snapshots permission concern remains, but this change does not expand it; merging is reasonable with owner follow-up.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 31.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names two themes, checking the objects Trino acts on and refusing names clients cannot address. The changeset matches both: the OPA bridge policies now check table, view, and metadata-table …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names two themes, checking the objects Trino acts on and refusing names clients cannot address. The changeset matches both: the OPA bridge policies now check table, view, and metadata-table objects per action, and Lakekeeper refuses names containing +, control characters, and similar characters. The title is specific and describes the primary change. It is a long, compound title, and it names the scope (opa-bridge, catalog) in the prefix, but it is not misleading or vague.

Full details: Docstring Coverage

Explanation

Docstring coverage is 31.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 35 functions across 19 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks names by the moonlit stream,
Then sorts each answer in its proper beam.
Tables and views get checks in a row,
A dropped name yields to the live one below.
Batches return only when whole and in time,
The rabbit hops off with a policy rhyme.

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 64afa64c-7786-49fa-9d17-5c891a8c4adf
Commits

Reviewing files that changed from the base of the PR and between 1fd715e and 815551b.

Files selected for processing: 2
  • docs/docs/logging.md
  • docs/docs/opa.md
Files skipped from review as they are similar to previous changes: 2
  • docs/docs/logging.md
  • docs/docs/opa.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Base automatically changed from christian/vak-618-split-delete-permission to main November 3, 2026 00:44
…or view

A batch-check that names a table, view or generic table now resolves the name to the live tabular only. Dropped tabulars that can still be restored keep their names, so one name can match a live tabular and dropped ones. Such a check is always decided on the live tabular. With `error-on-not-found`, a name that only dropped tabulars hold, or that belongs to a staged table that was not committed yet, is reported as not found. Dropped tabulars and staged tables are addressed by their id. Checks by id are unchanged.

The by-name lookup of the Postgres store returns one tabular per requested name: the live tabular, or the most recently dropped one if no live tabular has the name and the caller includes dropped tabulars.
…kekeeper rewrite

The bridge now checks only names that Trino and Lakekeeper use unchanged. Trino trims each namespace part and drops empty parts, the Iceberg REST client separates namespace parts with U+001F in the request path, and Lakekeeper reads '+' in a request path as a space. The bridge refuses every operation on schema names with an empty part, with white space or a control character at the start or end of a part, or with U+001F, and on schema, table and view names with '+'. Filter operations hide these names, and batch results stay aligned around them.

Namespaces, tables and views with such names can exist in Lakekeeper, for example if another client created them. To use one of them in Trino, rename it with the Lakekeeper API or UI.
…EATE OR REPLACE

Trino asks `CreateTable` and `CreateView` for `CREATE` as well as for `CREATE OR REPLACE`. After the create check passes, the bridge now sends one more batch-check with `error-on-not-found`: `commit` on a table of that name for `CreateTable`, with target ref `main`, the update kinds that every Iceberg replace contains (`set-current-schema`, `set-default-spec`, `set-default-sort-order`) and the statement's properties, and `commit` on a view of that name for `CreateView`. It allows the statement if the check allows it or if Lakekeeper answers that no such table or view exists. Every other answer denies.

The docs advise leaving `iceberg.rest-catalog.case-insensitive-name-matching` off in the Trino catalog: Lakekeeper already matches names regardless of upper and lower case, and the option makes Trino compare names with Java's rules, which treat a few letters differently.

This relies on the previous two commits: by-name checks resolve to the live table or view, and the bridge checks only names that Trino uses unchanged. Deploy the bridge policies together with a Lakekeeper server that includes these commits.

Behavior changes: replacing a table or view through Trino needs `commit` on it (with OpenFGA, `modify` or ownership on it or on anything that contains it; `write` is not enough, because the replace check names structural update kinds). `CREATE VIEW` with the name of an existing view returns an access error instead of "already exists" if the user lacks `commit`, and `CREATE VIEW IF NOT EXISTS` on an existing view needs `commit`. Each create of a new name writes one failed `introspect_permissions` audit record with `resource_not_found` (two for views).
…of the same name

Trino 484 reads `<table>$<type>` as a metadata table of `<table>` if the base name has neither `$` nor `@` and the type is a known metadata table type, ignoring ASCII case. The bridge now uses the same rule and knows `$materialized_view_storage`. Reading a metadata table is checked on its base table. Table and view rules refuse metadata-table names, and every other table or view name with `$` or `@`, also as a rename target, so a type that a later Trino version adds is denied. Filter operations hide these names. Schema names with `$` or `@` stay allowed.

On Trino 484 and later, such a name always means the metadata table. Older Trino versions can read a view with this name instead. When Trino reports a version before 484, or a version the bridge cannot read, reading a metadata table also needs `select` on a live view with this name, if one exists. The bridge takes the version from the leading number of `context.softwareStack.trinoVersion` (for example 484 for "484-SNAPSHOT"). It asks Lakekeeper with `error-on-not-found`, using the same request as the replace check from the previous commit: it continues if the check allows it or if Lakekeeper answers that no such view exists, and denies on every other answer. On older Trino, each read of a metadata table costs one more request, and if no view has its name, Lakekeeper writes one failed `introspect_permissions` audit record with `resource_not_found`.
The bridge splits large batch checks into several requests and matches the results to resources by position. It now uses the results only if every request succeeds with status 200 and returns a list with one result per check. Otherwise the whole batch check has no result, and the bridge allows none of the resources that it checks, so filter operations do not show them. If a `list_everything` check of the shortcut for broad access fails, the bridge checks each schema, table and view instead.

Checks that the bridge sends one at a time also need status 200. They share one helper.
Trino's `add_files` procedure, which the bridge allows to users who may commit any change to the table, reads the given location with the storage access Trino has for the table. With vended credentials this is the table's own location. With Trino's own static credentials it is everything those credentials can read, so the docs say when to keep `add_files` allowed and how to remove it.
…a values

Trino's metadata tables `$files`, `$entries`, `$all_entries`, `$manifests`, `$all_manifests` and `$partitions` show values of the data, such as column bounds and partition values. Reading them, and `$materialized_view_storage`, now needs `read_data` on the base table. `$snapshots`, `$history`, `$refs`, `$properties` and `$metadata_log_entries` keep needing `get_metadata`. A metadata table type without an entry in the bridge cannot be read. The check of a view with the same name stays. The batch path follows the same rule.

Users who can only see a table can list tables and columns and run `SHOW COLUMNS`, `DESCRIBE` and `SHOW CREATE TABLE`. Tools such as Superset may log denied `$partitions` queries for such users; what they show does not change.
Trino drops tables through the Iceberg REST catalog with purge, and drops views without a purge flag, which Lakekeeper drops with purge. The `DropTable` and `DropView` checks now send `{"action": "drop", "purge": true}`, as Lakekeeper authorizes these requests. Trino's `DropSchema` request does not say whether the statement has `CASCADE`, and with `CASCADE` Trino drops and purges every table and view in the schema without checking each of them. The `DropSchema` check now sends `{"action": "delete", "recursive": true, "purge": true}`, also for an empty schema. Cedar policies can use these fields; OpenFGA does not use them. The docs also note that `expire_snapshots` and `remove_orphan_files` delete files and are checked as a commit of any kind.
Lakekeeper reads a '+' in a request path as a space, so a view whose name contains '+' cannot be addressed by any client. Lakekeeper already refused '+' in new table and generic-table names; it now also refuses it in new view names and in the new name of a table, view or generic-table rename. Lakekeeper's own paths and the `referenced-by` parameter separate namespace parts with U+001F, so new table, view, generic-table and namespace names with a control character are refused too.

API changes:

- A new or registered table name, a new view or generic-table name, or the new name in a table, view or generic-table rename that contains '+' or a control character returns 400 `InvalidTableName`. For a generic-table name with '+' the error type was `InvalidName`.
- A new namespace name, also as a move destination, whose last part contains a control character returns 400 `InvalidNamespace`.

Existing objects keep their names and can be loaded, dropped and renamed to a valid name. Moving such a namespace, or renaming such a table or view into another namespace under its old name, now fails.
The replace check of CREATE OR REPLACE TABLE asks about a commit of any kind to `main`. A Trino replace commit holds more updates than the three kinds the check named, and which ones depends on the table and the Trino version.

The bridge denies `$materialized_view_storage`, which Trino cannot read from Lakekeeper because Trino's REST catalog has no materialized views. Comments and docs describe when Trino before 484 reads a view with a metadata table name.

OpenFGA's /management/v1/permissions/check resolves a name to the live table, view or generic table, as batch-check does. An id also addresses dropped and staged tabulars.

HidingAuthorizer refuses table, view and generic-table checks for another principal when `<kind>:ReadGrants` is blocked, as the authorizer trait requires. New integration tests pin that a by-name batch-check with error-on-not-found reports a free name with 404 before any authorization.
…ing requirement and the expected audit records
…dge policies

Older bridge policies check SetTableProperties as a commit that changes properties, and such a commit needs `modify`. A user with only `write` therefore cannot change table properties through them.
@c-thiel
c-thiel force-pushed the christian/trino-bridge-security branch from 40092f0 to 1fd715e Compare November 3, 2026 00:50

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread docs/docs/logging.md Resolved

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread docs/docs/opa.md Resolved
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

✅ PR Title Formatted Correctly

The title of this PR match the correct format. Thank you!

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