Repository navigation
fix(opa-bridge,catalog): check the objects Trino acts on, and refuse names that clients cannot address - #2215
Conversation
|
No actionable comments were generated in the recent review. WalkthroughThe 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. ChangesTrino authorization policies
Tabular name validation and lookup
Permission-inspection gate
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
Possibly related PRs
Merge Risk:
|
…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.
40092f0 to
1fd715e
Compare
✅ PR Title Formatted CorrectlyThe title of this PR match the correct format. Thank you! |
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
+, 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.<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.$files,$entries,$all_entries,$manifests,$all_manifests,$partitions) needread_data.CREATE OR REPLACEalso needscommitof any kind on an existing table or view;writeis not enough.DROP SCHEMAas a recursive delete with purge./management/v1/permissions/check.Operators
commiton them; with OpenFGA,modify.read_dataon the table.iceberg.rest-catalog.case-insensitive-name-matchingoff in the Trino catalog.Release notes
CREATE OR REPLACEneedscommiton the existing table or view. Roles that replace tables or views through Trino, such as dbt models, needcommit. With OpenFGA, give themmodify.read_data.$files,$partitionsand similar need permission to read the table's data.$snapshots,$historyand similar keep working with metadata access.$materialized_view_storageis denied, because Trino cannot read it from Lakekeeper.$or@, except metadata tables such asorders$snapshots, and names that Trino or Lakekeeper would change are refused and hidden. Rename such objects if Trino users need them.+and control characters are refused in new names. Generic-table names with+now returnInvalidTableName.Downstream follow-up
CatalogStore::get_tabular_infos_by_ident_implreturns one tabular per name: the live one, or the most recently dropped one if dropped tabulars are included./management/v1/permissions/check.HidingAuthorizer(test-utils): with<kind>:ReadGrantsblocked, table, view and generic-table checks for another principal (not delegated) fail withCannotInspectPermissions, as grant checks do. Tests that blocktable:ReadGrants,view:ReadGrantsorgeneric_table:ReadGrantsand then check for another principal get a 403 in place of a result.InvalidTableNamefor+or control characters in new or renamed tabular names (generic tables returnedInvalidName),InvalidNamespacefor control characters in the last part of a new or moved namespace.require_*helpers,namespace_for_schema,child_schema_nameandsplit_metadata_table_nameare undefined for refused names.is_metadata_tablefollows Trino 484, except that$materialized_view_storageis 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, andbatch_check_results*are undefined for incomplete results.Summary by CodeRabbit