Repository navigation
Conversation
WalkthroughRename now performs a pre-drop authorization check on the source table, resolves the destination namespace ID and uses it for CanCreateTable authorization, obtains the source table ID with CanRename after the drop check, and no longer maps some lookup errors to NotFound. AllowAllAuthorizer gained helpers that convert optional lookups into structured 404/500 errors. Tests updated to reflect new authorization/error semantics and a Python test now expects NoSuchTableError. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Service as Lakekeeper
participant Auth as Authorizer
participant Catalog
Client->>Service: rename_table(request: source -> destination)
Service->>Catalog: lookup destination namespace id
Catalog-->>Service: Some(namespace_id) / None
Service->>Auth: require_namespace_action(metadata, namespace_lookup, CanCreateTable)
alt destination missing
Auth-->>Service: NoSuchNamespace (404)
Service-->>Client: 404
else destination exists
Auth-->>Service: Ok(namespace_id)
Service->>Auth: require_table_action(metadata, source_table_lookup, CanDrop)
alt source missing or cannot drop
Auth-->>Service: NoSuchTable / Forbidden (404/403)
Service-->>Client: 404/403
else source exists & can drop
Service->>Auth: require_table_action(metadata, source_table_lookup, CanRename)
Auth-->>Service: Ok(source_table_id)
Service->>Catalog: perform rename using destination_namespace_id
Catalog-->>Service: Ok
Service-->>Client: 200
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
crates/lakekeeper/src/catalog/tables.rs (1)
918-929: Enforce authZ on destination namespace (privilege escalation risk) and reuse the lookup resultToday, we only check rename permission on the source table and require CanCreateTable on the source namespace (Line 921), but we never require CanCreateTable on the destination namespace. This enables a caller with rename rights on the source to move a table into a destination they cannot create in. That’s a security gap.
Additionally, the new existence check for the destination namespace is good, but we can reuse its result to also enforce the destination authZ to avoid an extra round trip.
Proposed fix preserves your new NoSuchNamespaceException while adding the missing authorization:
@@ - let namespace_id = - C::namespace_to_id(warehouse_id, &source.namespace, t.transaction()).await; // We can't fail before AuthZ - - // We need to be allowed to delete the old table and create the new one - authorizer - .require_namespace_action( - &request_metadata, - namespace_id, - CatalogNamespaceAction::CanCreateTable, - ) - .await?; + // We need to be allowed to delete the old table and create the new one: + // 1) Source table rename permission is enforced above via `CanRename`. + // 2) Destination namespace must exist and caller must be allowed to create there. @@ - if let Ok(None) = - C::namespace_to_id(warehouse_id, &destination.namespace, t.transaction()).await - { - return Err(ErrorModel::not_found( - "Namespace not found", - "NoSuchNamespaceException", - None, - ) - .into()); - } + let dest_namespace_id = + C::namespace_to_id(warehouse_id, &destination.namespace, t.transaction()).await; + if let Ok(None) = dest_namespace_id { + return Err( + ErrorModel::not_found( + format!("Destination namespace '{}' not found", + destination.namespace.to_url_string()), + "NoSuchNamespaceException", + None, + ).into() + ); + } + // The call below will fail with Unauthorized if the caller cannot create in the destination. + authorizer + .require_namespace_action( + &request_metadata, + dest_namespace_id, + CatalogNamespaceAction::CanCreateTable, + ) + .await?;Also applies to: 935-944
🧹 Nitpick comments (3)
crates/lakekeeper/src/catalog/tables.rs (3)
935-944: Good: return NoSuchNamespaceException (404) when destination namespace is missingThis aligns the API with a precise, spec-friendly error. Consider including the destination namespace in the message for debuggability (as shown in the diff in my other comment).
1915-1916: Type-source consistency for importsYou import NamespaceIdent/TableIdent from iceberg and RenameTableRequest from iceberg_ext. If crate::api::iceberg::v1 re-exports these, prefer consistently importing from there to avoid subtle type divergence if upstreams drift.
Also applies to: 1920-1921
3589-3652: Test covers the new behavior; add a couple of quick follow-upsLGTM: the test asserts the new NoSuchNamespaceException and 404. Two useful follow-ups:
- Also assert the error message contains the destination namespace (if you adopt the improved message).
- Add a positive-path test: rename within the same namespace or to an existing destination namespace.
- Add a negative authZ test: destination namespace exists but caller lacks CanCreateTable there.
|
I was diving deeper into this issue, and I believe that since we have AuthZ, we will never be fully compliant with the REST specification, as the specification doesn't account for AuthZ's existence. Since AuthZ is not a hard requirement for using Lakekeeper, we need to be compliant with both scenarios. For the scenario without AuthZ, commit bb6f14f addresses this, but I will add tests and implementation for the other cases. For the AuthZ scenario in the table rename process, we need to verify:
|
|
@ndrluis thanks for the PR! I think what you are mostly looking for is the 404 status code? Or is the error type also important for you? Could definitly use your test though. Happy to change the error type as well. |
|
The original problem I'm trying to solve is the compatibility with the RCK. Currently, we are returning RenameTableIdOrNamespaceNotFound, which is an invalid error type for the clients. The client expects two kinds of errors when this endpoint returns 404: I'm explaining more about the issue in this issue: #306 Currently, I'm adjusting my dev environment because I have to use my personal computer instead of the company machine. However, I have planned to add a test suite for both cases: one without AuthZ to run with RCK and be compliant with the API, and an AuthZ version that tests all the cases we have. I will push the changes to this PR for you to review the test implementations. What do you think? |
|
Another question I have is what kind of tests you think would be better to implement. I'm concerned about having a lot of duplicated tests based on the clients (Trino/PyIceberg/Spark) and integration tests at the Rust level. What are your thoughts about this, @c-thiel? Should we have opinionated documentation that explains how we should implement tests in Lakekeeper? |
|
Ok, then lets also change the error types in the Authorizer. For me the most important tests are rust tests. Clients should expect to recieve other error types as well - there are many things that can go wrong. However I agree that for these standard errors we should definitly return them. We want to tackle better RCK compatability a bit more holisticly in 0.11. It should also run in CI. |
bb6f14f to
40ef9df
Compare
|
@c-thiel I added the tests and the fix, but I found another case: when we are moving a table between namespaces, we are "deleting" the table from the source namespace, so I'm not sure if we should verify whether the user can_delete/can_rename the original table and can_create a table in the target namespace. If we wanted to be more restrictive, I believe we should not allow moving tables between namespaces when a user has different permission sets for each namespace, because if they're different, then we're creating an opening for privilege escalation. However, I believe it would be better for us to improve the implementation of HidingAuthorizer or run these types of tests against OpenFGA, because we're lacking support for specifying resource identifiers. |
|
You are right, there is a gap regarding privilege escalation. The basic permissions are:
Those are enough for non-managed namespaces, as by default owners can GRANT permissions on owned objects. However, there is one edge case: If managed access is enabled, then owners should not be able to introduce new GRANTS into the managed area - which would stay attached to the moved table. So we should also check managed_access. This isn't easy unfortunately, as the concept of Managed access is currently local to the OpenFGA Authorizer. We might want to introduce a new Catalog Permission: "can_create_moved_objects" or so. |
40ef9df to
ab99a60
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
crates/lakekeeper/src/service/authz/implementations/allow_all.rs (2)
242-262: require_namespace_action: correct 404/500 mapping; consider minor DRY and diagnostics improvements
- Behavior looks right: Ok(None) → 404 NoSuchNamespaceException; Err(e) → 500 internal with details. This meets the objective to avoid leaking auth decisions while still reporting missing resources correctly.
- For AllowAllAuthorizer, ignoring the action parameter is fine, but consider including the action in the 404 message for better traceability when debugging, e.g., “Namespace not found for action CreateTable”.
- The internal mapping is duplicated in require_table_action; consider a small helper to reduce duplication.
Optional refactor to reduce duplication:
async fn require_namespace_action( &self, _metadata: &RequestMetadata, namespace_id: Result<Option<NamespaceId>>, _action: impl From<CatalogNamespaceAction> + std::fmt::Display + Send, ) -> Result<NamespaceId> { - match namespace_id { - Ok(None) => { - Err( - ErrorModel::not_found("Namespace not found", "NoSuchNamespaceException", None) - .into(), - ) - } - Ok(Some(namespace_id)) => Ok(namespace_id), - Err(e) => Err( - ErrorModel::internal(e.error.message, e.error.r#type, e.error.source) - .append_details(e.error.stack) - .into(), - ), - } + unwrap_required(namespace_id, ErrorModel::not_found( + "Namespace not found", + "NoSuchNamespaceException", + None + )) }And similarly for require_table_action (see next comment). Add this helper at module scope:
fn unwrap_required<T>(res: Result<Option<T>>, not_found: ErrorModel) -> Result<T> { match res { Ok(Some(v)) => Ok(v), Ok(None) => Err(not_found.into()), Err(e) => Err( ErrorModel::internal(e.error.message, e.error.r#type, e.error.source) .append_details(e.error.stack) .into(), ), } }
264-281: require_table_action: correct 404 for missing table; mirror DRY suggestion and optional diagnostics
- Ok(None) → 404 NoSuchTableException and Err(e) → 500 internal are consistent with the namespace variant and the PR objectives.
- As with namespaces, consider including the action in the error message for easier debugging.
Optional DRY refactor mirroring the helper above:
async fn require_table_action<T: TableUuid + Send>( &self, _metadata: &RequestMetadata, table_id: Result<Option<T>>, _action: impl From<CatalogTableAction> + std::fmt::Display + Send, ) -> Result<T> { - match table_id { - Ok(None) => { - Err(ErrorModel::not_found("Table not found", "NoSuchTableException", None).into()) - } - Ok(Some(table_id)) => Ok(table_id), - Err(e) => Err( - ErrorModel::internal(e.error.message, e.error.r#type, e.error.source) - .append_details(e.error.stack) - .into(), - ), - } + unwrap_required(table_id, ErrorModel::not_found( + "Table not found", + "NoSuchTableException", + None + )) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
crates/lakekeeper/src/catalog/tables.rs(4 hunks)crates/lakekeeper/src/service/authz/implementations/allow_all.rs(3 hunks)tests/python/tests/test_pyiceberg.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- crates/lakekeeper/src/catalog/tables.rs
🧰 Additional context used
🧬 Code Graph Analysis (1)
crates/lakekeeper/src/service/authz/implementations/allow_all.rs (1)
crates/iceberg-ext/src/catalog/rest/error.rs (2)
not_found(162-168)internal(141-152)
🔇 Additional comments (2)
tests/python/tests/test_pyiceberg.py (1)
205-206: Expectation switch to NoSuchTableError is correct and aligns with new error semanticsDropping a non-existent table should surface NoSuchTableError instead of ForbiddenError given the updated 404 mapping for missing tables. This change matches the PR’s goal of returning standard “not found” errors for absent resources.
crates/lakekeeper/src/service/authz/implementations/allow_all.rs (1)
3-3: New imports are appropriate for the added helpersBringing ErrorModel into scope and adding TableUuid to the prelude are required for the new require_* helpers and the generic return on require_table_action. No issues here.
Also applies to: 14-15
ab99a60 to
f42b010
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
crates/lakekeeper/src/catalog/tables.rs (4)
907-917: Avoid duplicate table lookups; reuse the resolved TableId when checking both CanDrop and CanRenameYou resolve/authorize the same source table twice. This adds an extra catalog round-trip and authorization call you can avoid. Resolve once, enforce CanDrop (returning the TableId), then enforce CanRename using the already-known id.
Apply this refactor within the selected lines:
- authorized_table_ident_to_id::<C, _>( - authorizer.clone(), - &request_metadata, - warehouse_id, - source, - list_flags, - CatalogTableAction::CanDrop, - t.transaction(), - ) - .await?; - - let source_table_id = authorized_table_ident_to_id::<C, _>( - authorizer.clone(), - &request_metadata, - warehouse_id, - source, - list_flags, - CatalogTableAction::CanRename, - t.transaction(), - ) - .await?; + // Resolve once, then enforce both permissions using the same id. + let source_table_id = authorizer + .require_table_action( + &request_metadata, + C::table_to_id(warehouse_id, source, list_flags, t.transaction()).await, + CatalogTableAction::CanDrop, + ) + .await?; + // Must also be allowed to rename the source table + authorizer + .require_table_action( + &request_metadata, + Ok(Some(source_table_id)), + CatalogTableAction::CanRename, + ) + .await?;Also applies to: 919-928
930-941: Consider updating authorizer relationships on cross-namespace renameIf your Authorizer (e.g., OpenFGA) maintains namespace↔table relations (parent/child), a cross-namespace rename should update those tuples to reflect the new parent namespace. The current flow commits the DB rename but does not invoke an authz update.
- Suggestion: introduce an explicit authorizer call (e.g., move_table or update_parent_namespace) that:
- Removes Parent/Child tuples for the old namespace
- Adds Parent/Child tuples for the new namespace
- Preserves ownership tuples
Alternatively, expose a lightweight method on Authorizer to rebind the table’s parent namespace by ids. If such a call already exists elsewhere, wire it in here after C::rename_table and before commit.
Would you like me to draft the Authorizer trait addition and OpenFGA implementation for a move_table(parent_ns_old -> parent_ns_new) operation, plus tests?
3734-3805: Make the test deterministic by creating the destination namespaceIn this scenario you block the namespace CanCreateTable action but don’t create the destination namespace (“to_ns”). Depending on Authorizer semantics, the check may yield 404 NoSuchNamespace instead of 403 NamespaceActionForbidden, making the test brittle.
Create the destination namespace first so the failure is unambiguously due to missing permission, not missing resource.
Apply this change inside the selected block, right after creating from_ns:
let from_ns = crate::catalog::test::create_ns( ctx.clone(), warehouse.warehouse_id.to_string(), "from_ns".to_string(), ) .await; + // Ensure target namespace exists so we test the permission failure (403), not a 404. + let _to_ns = crate::catalog::test::create_ns( + ctx.clone(), + warehouse.warehouse_id.to_string(), + "to_ns".to_string(), + ) + .await;If you prefer to keep the missing-namespace case, assert 404 with AllowAllAuthorizer (as you do in a separate test) and keep this test for the pure authorization failure.
3592-3919: Add a positive-path rename test (success) to complement the negative casesRecommend adding at least one success test to ensure the happy-path works in both modes:
- AuthZ present (HidingAuthorizer with no blocks):
- Create from_ns and to_ns, create source table, rename across namespaces, then load by destination ident and ensure old ident is not found.
- Non-AuthZ (AllowAllAuthorizer):
- Same as above; verifies parity.
I can draft these tests if you’d like.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
crates/lakekeeper/src/catalog/tables.rs(5 hunks)crates/lakekeeper/src/service/authz/implementations/allow_all.rs(3 hunks)tests/python/tests/test_pyiceberg.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- tests/python/tests/test_pyiceberg.py
- crates/lakekeeper/src/service/authz/implementations/allow_all.rs
🧰 Additional context used
🧬 Code Graph Analysis (1)
crates/lakekeeper/src/catalog/tables.rs (4)
crates/lakekeeper/src/service/authz/mod.rs (3)
new(773-778)create_table(422-427)create_table(1018-1025)crates/lakekeeper/src/service/authz/implementations/allow_all.rs (1)
create_table(216-223)crates/lakekeeper/src/service/authz/implementations/openfga/mod.rs (1)
create_table(623-662)crates/lakekeeper/src/request_metadata.rs (1)
new_unauthenticated(74-84)
🔇 Additional comments (8)
crates/lakekeeper/src/catalog/tables.rs (8)
930-941: Correct: authorize against the destination namespace (CanCreateTable) using the resolved destination namespace idThis fixes the previously reported bug where authorization mistakenly used the source namespace. The flow now properly resolves the destination namespace id and gates the operation with CanCreateTable, which prevents a privilege escalation when moving tables across namespaces.
1915-1915: Imports expanded for testsAdding NamespaceIdent alongside TableIdent is fine and consistent with new tests.
1920-1921: Importing RenameTableRequest for test coverageLooks good; required for the new rename authorization tests.
1947-1950: Test authorizer imports are appropriateBringing in HidingAuthorizer/AllowAllAuthorizer and CatalogNamespaceAction/CatalogTableAction is appropriate for the scenarios below.
3592-3663: Good negative test: without CanRename on sourceThis verifies the source CanRename check triggers a 403. Clear and targeted.
3665-3732: Good negative test: without CanDrop on sourceThis verifies the preliminary CanDrop requirement. Solid coverage.
3807-3874: Good negative test: non-AuthZ mode returns 404 for missing target namespaceThis aligns with the intended “AllowAll with missing resource → 404 NoSuchNamespaceException” behavior.
3876-3919: Good negative test: non-AuthZ mode returns 404 for missing source tableValidates NoSuchTableException is surfaced when the source doesn’t exist.
- Fix namespace authorization bug in rename_table to check destination namespace instead of source - Remove error mapping that converted 403 to 404 to prevent information disclosure - Implement missing require_namespace_action and require_table_action in AllowAllAuthorizer - Add comprehensive tests for rename table authorization scenarios
f42b010 to
8a0adfd
Compare
|
@c-thiel ready for review |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/lakekeeper/src/catalog/tables.rs (1)
987-995: Avoid converting authorization failures into 404 inload_table
The call atcrates/lakekeeper/src/catalog/tables.rs:994still does:… .await .map_err(set_not_found_status_code)?;This will turn all errors (including 403 “Forbidden”) into 404. Since the PR’s intent is to preserve 403 for authorization failures, update this mapping to only translate genuine “not found” errors. For example:
- .await - .map_err(set_not_found_status_code)?; + .await + .map_err(|e| match e { + AuthError::NotFound => set_not_found_status_code(e), + other => other.into(), + })?;Please apply the same narrowing to these analogous sites:
crates/lakekeeper/src/catalog/namespace.rs:547crates/lakekeeper/src/catalog/views/load.rs:64crates/lakekeeper/src/catalog/views/exists.rs:57crates/lakekeeper/src/catalog/views/drop.rs:51Ensure only true “not found” cases map to 404; all other errors (e.g., permission denied) should propagate as 403.
🧹 Nitpick comments (1)
crates/lakekeeper/src/catalog/tables.rs (1)
882-904: Avoid duplicate table lookups and auth checks for rename; perform CanDrop once, then reuse id for CanRename.Current flow resolves the same source table twice (once for CanDrop, again for CanRename), incurring duplicate DB work and potential divergence in error paths. You can resolve the table once with CanDrop and then require CanRename on the already-known id. This keeps semantics intact, shortens the critical section, and simplifies reasoning.
Proposed change:
- authorized_table_ident_to_id::<C, _>( - authorizer.clone(), - &request_metadata, - warehouse_id, - source, - list_flags, - CatalogTableAction::CanDrop, - t.transaction(), - ) - .await?; - - let source_table_id = authorized_table_ident_to_id::<C, _>( - authorizer.clone(), - &request_metadata, - warehouse_id, - source, - list_flags, - CatalogTableAction::CanRename, - t.transaction(), - ) - .await?; + // Resolve once while enforcing CanDrop + let source_table_id = authorized_table_ident_to_id::<C, _>( + authorizer.clone(), + &request_metadata, + warehouse_id, + source, + list_flags, + CatalogTableAction::CanDrop, + t.transaction(), + ) + .await?; + // Then enforce CanRename on the resolved id without another DB lookup + authorizer + .require_table_action( + &request_metadata, + Ok(Some(source_table_id)), + CatalogTableAction::CanRename, + ) + .await?;Net effect: same checks (CanDrop + CanRename), one lookup.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
crates/lakekeeper/src/catalog/tables.rs(5 hunks)crates/lakekeeper/src/service/authz/implementations/allow_all.rs(3 hunks)tests/python/tests/test_pyiceberg.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- crates/lakekeeper/src/service/authz/implementations/allow_all.rs
🧰 Additional context used
🧬 Code Graph Analysis (1)
crates/lakekeeper/src/catalog/tables.rs (5)
crates/lakekeeper/src/implementations/postgres/catalog.rs (3)
namespace_to_id(134-140)create_table(160-165)rename_table(232-240)crates/lakekeeper/src/service/catalog.rs (3)
namespace_to_id(363-367)create_table(387-390)rename_table(452-458)crates/lakekeeper/src/tests/mod.rs (3)
setup(189-266)create_ns(86-102)create_table(104-122)crates/lakekeeper/src/implementations/postgres/tabular/table/mod.rs (2)
create_request(894-944)rename_table(800-817)crates/lakekeeper/src/request_metadata.rs (1)
new_unauthenticated(78-88)
🔇 Additional comments (7)
tests/python/tests/test_pyiceberg.py (1)
203-207: Aligns Python expectation with new 404 semantics for unknown table.Switching to NoSuchTableError here matches the updated server behavior and avoids leaking authorization details. Looks good.
crates/lakekeeper/src/catalog/tables.rs (6)
905-915: Destination namespace authorization is now correctly scoped; keep tests focused on existence vs. permission.Using destination_namespace_id with require_namespace_action is the correct fix. To make tests robust across different Authorizer implementations, ensure tests that assert a forbidden CanCreateTable actually create the destination namespace first, so the failure is unequivocally due to authorization rather than non-existence (see below suggestion in tests).
3567-3638: Test: Blocks CanRename correctly; good guard order validation.This verifies that a missing destination namespace does not mask a CanRename violation (forbidden takes precedence). Solid.
3640-3707: Test: Blocks CanDrop correctly; good coverage.Same precedence check for CanDrop. Looks good.
3823-3849: AllowAll + missing destination namespace → 404 NoSuchNamespaceException.Matches the new AllowAllAuthorizer semantics and client expectations. Good.
3851-3894: AllowAll + missing source table → 404 NoSuchTableException.This ensures NoSuchTable is surfaced instead of Forbidden; aligns with the Python test change and PR goals. Good.
3710-3780: No changes required for the destination namespace
The call torequire_namespace_actionmaps a missing namespace (Ok(None)) to a 403 Forbidden with type “NamespaceActionForbidden”, so the test already exercises the permission-denied path regardless of whetherto_nsexists. You can ignore the suggestion to create the destination namespace.Likely an incorrect or invalid review comment.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
crates/lakekeeper/src/catalog/tables.rs (2)
887-908: Cut duplicated lookups and redundant warehouse checks in rename_table authz pathYou call authorized_table_ident_to_id twice (CanDrop, then CanRename). That does two DB lookups (table_to_id) and two require_warehouse_action checks back-to-back. You can resolve the table ID once and check both actions, which:
- reduces DB round-trips,
- narrows the TOCTOU window between checks,
- keeps the “don’t fail before AuthZ” property by explicitly requiring warehouse use once.
Apply this diff to streamline the checks:
@@ - authorized_table_ident_to_id::<C, _>( - authorizer.clone(), - &request_metadata, - warehouse_id, - source, - list_flags, - CatalogTableAction::CanDrop, - t.transaction(), - ) - .await?; - - let source_table_id = authorized_table_ident_to_id::<C, _>( - authorizer.clone(), - &request_metadata, - warehouse_id, - source, - list_flags, - CatalogTableAction::CanRename, - t.transaction(), - ) - .await?; + // Require warehouse once; then fetch table id once and verify both actions. + authorizer + .require_warehouse_action( + &request_metadata, + warehouse_id, + CatalogWarehouseAction::CanUse, + ) + .await?; + // We can't fail before AuthZ + let table_id_result = + C::table_to_id(warehouse_id, source, list_flags, t.transaction()).await; + // Must be allowed to rename the source table... + let source_table_id = authorizer + .require_table_action( + &request_metadata, + table_id_result, + CatalogTableAction::CanRename, + ) + .await?; + // ...and must be allowed to drop it (prevents privilege escalation via move semantics) + authorizer + .require_table_action( + &request_metadata, + Ok(Some(source_table_id)), + CatalogTableAction::CanDrop, + ) + .await?;
887-921: One more consideration: no-op rename still requires destination createBecause the source == destination short-circuit happens after the destination CanCreateTable check, a no-op rename will still require the create permission. That’s defensible (consistent “move = create+drop” model), but different systems sometimes treat no-op as a free success.
Would you like to lock in this behavior with an explicit test (no-op rename + lacks CanCreateTable → Forbidden) and add a brief comment in code stating the rationale to avoid future changes?
I can add a minimal test alongside the existing ones if you want.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
crates/lakekeeper/src/catalog/tables.rs(5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
crates/lakekeeper/src/catalog/tables.rs (7)
crates/lakekeeper/src/implementations/postgres/catalog.rs (3)
namespace_to_id(134-140)create_table(160-165)rename_table(232-240)crates/lakekeeper/src/service/catalog.rs (3)
namespace_to_id(360-364)create_table(384-387)rename_table(449-455)crates/lakekeeper/src/tests/mod.rs (2)
create_ns(86-102)create_table(104-122)crates/lakekeeper/src/service/endpoint_hooks.rs (5)
new(43-45)create_table(165-193)create_table(404-415)rename_table(195-217)rename_table(417-425)crates/lakekeeper/src/service/event_publisher/mod.rs (3)
new(437-439)create_table(190-220)rename_table(222-249)crates/lakekeeper/src/implementations/postgres/tabular/table/mod.rs (2)
create_request(894-944)rename_table(800-817)crates/lakekeeper/src/request_metadata.rs (1)
new_unauthenticated(78-88)
🔇 Additional comments (8)
crates/lakekeeper/src/catalog/tables.rs (8)
2013-2018: Imports for tests look correctAdding NamespaceIdent, TableIdent, and RenameTableRequest in the test module is needed for the new scenarios. No issues.
2043-2046: Test harness imports align with new authz checksUsing HidingAuthorizer, AllowAllAuthorizer, and the Catalog*Action enums directly in tests makes the scenarios explicit and readable.
3690-3761: AuthZ: rename blocked when CanRename is denied — correct behaviorThe test covers the forbidden-on-rename case and ensures we don’t fall back to a 404. This prevents resource enumeration. Looks good.
3763-3830: AuthZ: pre-drop check enforced — correct 403 when CanDrop is deniedVerifies the new pre-drop authorization gate. This ensures move semantics can’t bypass delete privileges. Good coverage.
3832-3903: AuthZ: destination create denied returns 403 — ensure precedence is consistent across authorizersThe test asserts Forbidden for a denied CanCreateTable on the destination (even if the namespace doesn’t exist). That’s the right precedence to avoid enumeration.
Please confirm OpenFGA’s require_namespace_action matches this precedence (Forbidden on explicit deny wins over NotFound on missing destination). If not, mirror the behavior for consistency with these tests.
3905-3972: Non-AuthZ: missing destination namespace → NoSuchNamespaceException (404)This validates the AllowAllAuthorizer path and expected error typing for RCK compatibility. Looks correct.
3974-4016: Non-AuthZ: missing source table → NoSuchTableException (404)Good coverage for the non-AuthZ scenario when the source table does not exist. Matches the client expectation.
910-921: The scripts are running to locate and inspect both theAllowAllAuthorizerand any OpenFGA‐based authorizer implementations. I’ll review the outputs to confirm:
- That
AllowAllAuthorizer::require_namespace_actionmapsOk(None)to aNoSuchNamespaceException.- That in the OpenFGA authorizer, an explicit deny yields
Forbiddenbefore aNotFound, and that itsOk(None)likewise surfaces asNoSuchNamespaceException.Once we have that confirmation, I’ll update the review comment accordingly.
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
crates/lakekeeper/src/service/authz/implementations/allow_all.rs (1)
245-284: Re-run the check: all Authorizer impls should now include the new require_ methods*This was raised earlier; leaving a quick verification script to ensure no regressions in other impls.
#!/bin/bash set -euo pipefail echo "Authorizer implementations and presence of require_*:" rg --type=rust -l '^\s*impl\s+Authorizer\s+for\s+\w+' | sort | while read -r f; do ns=$(rg -n 'async\s+fn\s+require_namespace_action\b' "$f" >/dev/null && echo yes || echo no) tb=$(rg -n 'async\s+fn\s+require_table_action\b' "$f" >/dev/null && echo yes || echo no) printf "%-100s require_namespace_action=%s require_table_action=%s\n" "$f" "$ns" "$tb" done
🧹 Nitpick comments (6)
crates/lakekeeper/src/service/authz/implementations/allow_all.rs (2)
245-265: Harden internal error shape and keep types stable across AuthorizersCurrently, the
Err(e)branch usese.error.r#typeas the type of the new internal error ande.error.messageas the message. That can leak backend/internal detail differences across Authorizer implementations. Consider a stable type/message and move the original details into.append_detail(...)to keep parity with other impls and reduce information leakage.Suggested change:
@@ - Err(e) => Err( - ErrorModel::internal(e.error.message, e.error.r#type, e.error.source) - .append_details(e.error.stack) - .into(), - ), + Err(e) => Err( + ErrorModel::internal( + "Failed to resolve namespace before authorization", + "NamespaceResolutionFailed", + e.error.source, + ) + .append_detail(format!("Original Type: {}", e.error.r#type)) + .append_detail(e.error.message) + .append_details(e.error.stack) + .into(), + ),
267-284: Mirror the stable internal error shape for tablesApply the same stabilization for table errors:
@@ - Err(e) => Err( - ErrorModel::internal(e.error.message, e.error.r#type, e.error.source) - .append_details(e.error.stack) - .into(), - ), + Err(e) => Err( + ErrorModel::internal( + "Failed to resolve table before authorization", + "TableResolutionFailed", + e.error.source, + ) + .append_detail(format!("Original Type: {}", e.error.r#type)) + .append_detail(e.error.message) + .append_details(e.error.stack) + .into(), + ),crates/lakekeeper/src/catalog/tables.rs (4)
889-911: Avoid double DB lookup for the source table id in renameYou resolve the source ID twice: once for
CanDropand again forCanRename. You can capture the ID from the first call and re-use it for the rename check to save an extra lookup (still preserving the ordering: drop first, then rename).Proposed change:
@@ - authorized_table_ident_to_id::<C, _>( - authorizer.clone(), - &request_metadata, - warehouse_id, - source, - list_flags, - CatalogTableAction::CanDrop, - t.transaction(), - ) - .await?; - - let source_table_id = authorized_table_ident_to_id::<C, _>( - authorizer.clone(), - &request_metadata, - warehouse_id, - source, - list_flags, - CatalogTableAction::CanRename, - t.transaction(), - ) - .await?; + let source_table_id = authorized_table_ident_to_id::<C, _>( + authorizer.clone(), + &request_metadata, + warehouse_id, + source, + list_flags, + CatalogTableAction::CanDrop, + t.transaction(), + ) + .await?; + + // Reuse the resolved id to check rename permission without a second lookup. + authorizer + .require_table_action( + &request_metadata, + Ok(Some(source_table_id)), + CatalogTableAction::CanRename, + ) + .await?;
3692-3763: Test: forbids rename when CanRename is blocked (AuthZ)This test ensures the rename-specific permission is required in addition to drop. Consider adding a companion where the destination namespace exists to make the order-of-checks explicit even when dest exists (currently the failure happens before dest check, which is fine).
3765-3832: Test: forbids rename when CanDrop is blocked (AuthZ)Covers the pre-drop gate. Same suggestion as above: optionally ensure the destination exists to isolate the source-side failure independent of dest existence.
3834-3905: Test: forbids rename when CanCreateTable is blocked in destination (AuthZ)Good. For completeness, consider an additional case where the destination namespace exists but is forbidden, to distinguish “Forbidden due to AuthZ” from “Forbidden due to hidden/non-existent namespace”.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
crates/lakekeeper/src/catalog/tables.rs(5 hunks)crates/lakekeeper/src/service/authz/implementations/allow_all.rs(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
crates/lakekeeper/src/service/authz/implementations/allow_all.rs (1)
crates/lakekeeper/src/service/authz/mod.rs (2)
require_namespace_action(750-787)require_table_action(789-821)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
- GitHub Check: docker / docker
- GitHub Check: docker / docker
- GitHub Check: docker / docker
- GitHub Check: docker / docker
- GitHub Check: check-generated-openapi-matches
- GitHub Check: sqlx-check
- GitHub Check: clippy
- GitHub Check: test
🔇 Additional comments (13)
crates/lakekeeper/src/service/authz/implementations/allow_all.rs (4)
3-3: Importing ErrorModel is correct and necessaryBrings in the structured REST error builder you use below. Looks good.
14-14: Exposing TableUuid in the import set is appropriateNeeded for the generic bound in
require_table_action<T: TableUuid + Send>. No issues.
245-265: AllowAll semantics: returning 404 for missing namespaces is aligned with non-AuthZ expectationsMapping
Ok(None)toNoSuchNamespaceException(404) here matches the stated goal for AllowAll and the updated tests. Good separation from the “hiding” behavior used by AuthZ impls.
267-284: AllowAll semantics: returning 404 for missing tables is aligned with non-AuthZ expectationsMapping
Ok(None)toNoSuchTableException(404) here is consistent with the PR objectives and tests.crates/lakekeeper/src/catalog/tables.rs (9)
889-900: Good pre-drop authorization gate on the source tableChecking
CanDropbefore proceeding closes the privilege-escalation gap discussed in the PR. Nice.
912-914: Destination namespace is resolved from the destination ident (not the source) — correctThis fixes the original bug where the source namespace was used. Solid.
917-922: Authorization now checks create permission in the destination namespace — correctThis matches the “delete from source, create in destination” rule of thumb and the test matrix. Good.
2015-2016: Added imports for NamespaceIdent and TableIdent in testsRequired by the new rename tests; all good.
2019-2020: Import RenameTableRequest in testsNecessary for constructing the rename payloads; looks fine.
2045-2048: Test imports for Hiding/AllowAll and Catalog*Action enumsMatches how you parameterize AuthZ behavior in the tests. Good coverage setup.
3907-3974: Test: AllowAll returns 404 for missing destination namespaceValidates the new AllowAll behavior (
NoSuchNamespaceException). Nice alignment with RCK clients.
3976-4018: Test: AllowAll returns 404 for missing source tableValidates
NoSuchTableExceptionunder AllowAll. Looks good.
889-922: 403→404 Mapping Consistency VerifiedI performed a repo-wide audit of all
authorized_table_ident_to_idcall sites and cross-checked usages ofset_not_found_status_code. None of the fourauthorized_table_ident_to_id::<…>invocations are wrapped withmap_err(set_not_found_status_code), so there are no other unintended 403→404 mappings. No further changes needed.
| authorized_table_ident_to_id::<C, _>( | ||
| authorizer.clone(), | ||
| &request_metadata, | ||
| warehouse_id, | ||
| source, | ||
| list_flags, | ||
| CatalogTableAction::CanDrop, | ||
| t.transaction(), | ||
| ) | ||
| .await?; |
There was a problem hiding this comment.
We don't need this here.
CanDrop is less specific than CanRename, which is checked below. CanRename might be implemented as CanDrop AND Something else, depending on the Authz system. In our case, for the OpenFGA Authorizer, they are even identical. In any case, the AuthZ system must make sure that Rename is as least as restrictive as drop.
| authorizer | ||
| .require_table_action(metadata, table_id, action) | ||
| .await | ||
| .map_err(set_not_found_status_code) |
There was a problem hiding this comment.
We probably shouldn't remove this for two reasons:
- Many query engines cannot process a 403 correctly. Not for rename table - it might be OK there, but for example table_exists with a 403 / 401 code is not widely supported. Some versions of trino will even abort "SHOW TABLES FROM ..." if they encounter a 403 / 401. So we must retain the 404 error code. This method is used not only for rename, but other methods as well.
- It leaks information about tables that the client is not authorized to know. Lets assume a client queries a table "hr.employees_to_fire", but has no access to it. Then, if we would return a different error code based on the fact if the table exists or not, we would leak the information if the table exists or not. Thus we should always return 404 with TableNotFound. This is conclusive with the UI, where we won't show these tables. So there is no reason to return a 401/403 - instead, the table should appear non-existant.
There was a problem hiding this comment.
Agreed. Just to confirm we're aligned on the error handling
If a user doesn't have permission to rename a table, raise a 404 with NoSuchTableException
If a user doesn't have permission to create a table in the destination namespace, raise a 404 with NoSuchNamespaceException
If a user tries to rename a table that doesn't exist, raise a 404 with NoSuchTableException
If a user tries to rename a table to a namespace that doesn't exist, raise a 404 with NoSuchNamespaceException
WDYT?
| Ok(()) | ||
| } | ||
|
|
||
| async fn require_namespace_action( |
There was a problem hiding this comment.
We should not implement these two methods (require_namespace_action & require_table_action) here - it only leeds to errors.
These methods are already implemented for AllowAllAuthorizer via the implementations in the Authorizer trait. The behaviour implemented here has no effect for the OpenFGAAuthorizer - only for AllowAllAuthorizer. Diverting behaviour is an anti-pattern and should only be applied if we have very good reasons for it - which I believe we don't.
✅ PR Title Formatted CorrectlyThe title of this PR match the correct format. Thank you! |
|
Closed in favor of: #1346 |
Summary by CodeRabbit
Bug Fixes
Tests