yuqi1129 opened a new issue, #14902:
URL: https://github.com/apache/gravitino/issues/14902

   ### Version
   main branch, commit e88558e1bf (2.0.0-SNAPSHOT)
   
   ### Describe what's wrong
   A user who has only USE_CATALOG, USE_SCHEMA and CREATE_TABLE can replace a 
Lance table that another user owns. They call the Gravitino REST `createTable` 
(or the Java client `createTable`) on a lakehouse-generic catalog with these 
properties: `format=lance` and `lance.creation-mode=OVERWRITE`.
   
   Expected: the request fails, because replacing an existing table needs more 
than CREATE_TABLE.
   
   Actual (from reading the code): `LanceTableOperations.createTable` purges 
the existing table and creates a new one. For a managed table, the purge 
deletes its Lance dataset. Then `TableHookDispatcher` makes the caller the 
owner of the new table. With `lance.register=true`, OVERWRITE replaces the 
metadata of another user's external table in the same way.
   
   The Lance REST service is not affected. 
`LanceMetadataAuthorizationMethodInterceptor` sends `mode=overwrite` through 
`OverwriteAuthzHandler`, which requires MODIFY_TABLE. The Gravitino REST API 
has no such check:
   - 
`server/src/main/java/org/apache/gravitino/server/web/rest/TableOperations.java:121-126`:
 `createTable` only checks CREATE_TABLE on the schema.
   - 
`catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceTableDelegator.java:61-68`:
 `lance.creation-mode` is a normal table property, not reserved and not hidden, 
so a user can set it.
   - 
`catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceTableOperations.java`:
 for OVERWRITE, `createTable` calls `purgeTable` (or 
`dropExternalTableForRegistration` when registering) before it creates the 
table.
   
   External tables are safer by default: their purge is rejected unless the 
catalog sets `lance.allow-external-table-purge`. Managed tables have no such 
guard.
   
   ### Error message and/or stacktrace
   Found by reading the code. Not yet reproduced on a running server.
   
   ### How to reproduce
   Expected steps, with `gravitino.authorization.enable = true`:
   1. As admin, create a metalake, a lakehouse-generic catalog, schema `s1`, 
and a managed Lance table `s1.t1` (`format=lance`, no `external`).
   2. Create user `u1` with only USE_CATALOG on the catalog and USE_SCHEMA and 
CREATE_TABLE on `s1`.
   3. As `u1`, call `POST 
/api/metalakes/{metalake}/catalogs/{catalog}/schemas/s1/tables` for `t1` with 
properties `{"format": "lance", "lance.creation-mode": "OVERWRITE", "location": 
...}`.
   4. Expected 403. Actual: 200, the old dataset is deleted, and `u1` owns the 
new `t1`.
   
   ### Additional context
   - Related: #14436 (the same path with EXIST_OK takes ownership of an 
existing table), #12956 (keep ownership during Lance overwrite).
   - Target: a 2.0.x patch release after 2.0.0.
   - Possible fixes:
     1. The catalog stops accepting OVERWRITE through the public `createTable`. 
The Lance REST service then does purge (or drop) and create as separate calls, 
after its MODIFY_TABLE check.
     2. The Gravitino REST `createTable` authorizes OVERWRITE the way Lance 
REST does, requiring MODIFY_TABLE or ownership of the existing table.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to