This is an automated email from the ASF dual-hosted git repository.
yuqi1129 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new e23b85f9d8 [#14902] test(lance-rest): Cover overwrite authorization
for create-table and register-table (#14933)
e23b85f9d8 is described below
commit e23b85f9d8ee511eb7b5a7239ab837166a746d25
Author: Srihari Srithar <[email protected]>
AuthorDate: Mon Nov 16 01:06:37 2026 -0600
[#14902] test(lance-rest): Cover overwrite authorization for create-table
and register-table (#14933)
### What changes were proposed in this pull request?
Keeps overwrite authorization at the Lance REST boundary, as agreed in
#14902 (review:
https://github.com/apache/gravitino/pull/14933#discussion_r4581582727).
- Revert the `lance.creation-mode` check in
`TableOperations.createTable` and remove
`TestTableOperationsOverwriteAuthorization`. The generic createTable
endpoint is back to `main`: it passes connector properties through and
applies no Lance-specific authorization.
- Add regression tests for `OverwriteAuthzHandler` in
`lance-rest-server` covering cases that were not tested yet:
- Create-table (`mode` query parameter) and register-table (`mode` in
the body) reject spacing and case variants of the overwrite mode (`
overwrite`, `overwrite `, ` OverWrite `, `\toverwrite\n`) when the
caller only has CREATE_TABLE, and the operation does not run. Until now
only namespaces had these cases.
- A client-supplied `lance.creation-mode=OVERWRITE` table property on
create, declare or register cannot replace the authorized request mode.
The catalog always receives `CREATE`.
No production code changes.
### Why are the changes needed?
Overwrite is a Lance REST concept. The Lance REST service already
requires MODIFY_TABLE or ownership for an overwrite on both create-table
and register-table, through `OverwriteAuthzHandler`. Making the generic
endpoint read one connector's property would leak connector semantics
into the core API. The new tests pin down the two ways the existing
check could be bypassed: an unnormalized mode and a smuggled property.
Fix: #14902
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
- `./gradlew :lance:lance-rest-server:test --tests
'*TestLanceMetadataAuthorizationMethodInterceptor' --tests
'*TestGravitinoLanceModeParsing' -PskipITs` passes: 38 tests, including
the new `testTableOverwriteIsRecognizedWhateverSpacingTheClientSends`
and `testClientPropertyCannotOverrideAuthorizedMode`.
- `./gradlew :lance:lance-rest-server:spotlessCheck
:server:spotlessCheck` passes.
---------
Signed-off-by: Srihari Srithar <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../gravitino/TestGravitinoLanceModeParsing.java | 31 ++++++++++++++++++++++
...anceMetadataAuthorizationMethodInterceptor.java | 23 ++++++++++++++++
2 files changed, 54 insertions(+)
diff --git
a/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceModeParsing.java
b/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceModeParsing.java
index ee144208a2..5688be6085 100644
---
a/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceModeParsing.java
+++
b/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceModeParsing.java
@@ -185,6 +185,37 @@ class TestGravitinoLanceModeParsing {
exception.getMessage().contains("Unknown register table mode:
#register$"));
}
+ @Test
+ void testClientPropertyCannotOverrideAuthorizedMode() {
+ // The REST interceptor authorizes an overwrite from the request mode
alone. A caller-supplied
+ // lance.creation-mode table property must therefore never reach the
catalog in place of that
+ // mode, or CREATE_TABLE plus a property would be enough to replace an
existing table.
+ TableCatalog tableCatalog = Mockito.mock(TableCatalog.class);
+ Table table = Mockito.mock(Table.class);
+ when(table.properties()).thenReturn(Map.of(LANCE_LOCATION, "/tmp/table"));
+ when(tableCatalog.createTable(
+ any(NameIdentifier.class), any(Column[].class), isNull(),
anyMap()))
+ .thenReturn(table);
+ GravitinoLanceTableOperations operations =
newTableOperations(tableCatalog);
+ Map<String, String> smuggled = Map.of(LANCE_CREATION_MODE, "OVERWRITE");
+
+ operations.createTable("catalog.schema.table", "create", ".", null,
smuggled, null);
+ operations.declareTable("catalog.schema.table", ".", null, smuggled);
+ operations.registerTable(
+ "catalog.schema.table",
+ "create",
+ ".",
+ Map.of(LANCE_LOCATION, "/tmp/table", LANCE_CREATION_MODE,
"OVERWRITE"));
+
+ ArgumentCaptor<Map<String, String>> propertiesCaptor = propertiesCaptor();
+ Mockito.verify(tableCatalog, Mockito.times(3))
+ .createTable(
+ any(NameIdentifier.class), any(Column[].class), isNull(),
propertiesCaptor.capture());
+ for (Map<String, String> properties : propertiesCaptor.getAllValues()) {
+ Assertions.assertEquals("CREATE", properties.get(LANCE_CREATION_MODE));
+ }
+ }
+
@Test
void testCreateTableReturnsPropertiesAndStorageOptions() {
TableCatalog tableCatalog = Mockito.mock(TableCatalog.class);
diff --git
a/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/service/authorization/TestLanceMetadataAuthorizationMethodInterceptor.java
b/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/service/authorization/TestLanceMetadataAuthorizationMethodInterceptor.java
index 5c30b511cd..d24a846783 100644
---
a/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/service/authorization/TestLanceMetadataAuthorizationMethodInterceptor.java
+++
b/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/service/authorization/TestLanceMetadataAuthorizationMethodInterceptor.java
@@ -374,6 +374,29 @@ class TestLanceMetadataAuthorizationMethodInterceptor {
Response.Status.FORBIDDEN);
}
+ @Test
+ void testTableOverwriteIsRecognizedWhateverSpacingTheClientSends() throws
Throwable {
+ allow(Privilege.Name.USE_CATALOG, Privilege.Name.USE_SCHEMA,
Privilege.Name.CREATE_TABLE);
+
+ // Create-table and register-table read their mode through
CommonUtil.normalizeToken, so each
+ // of these reaches the catalog as OVERWRITE. Authorization must read it
the same way, or
+ // CREATE_TABLE alone would be enough to replace a table owned by somebody
else.
+ for (String mode : new String[] {" overwrite", "overwrite ", " OverWrite
", "\toverwrite\n"}) {
+ MethodInvocation create = createTableInvocation(tableId(), mode);
+ assertErrorResponse(
+ interceptor.invoke(create),
+ Response.Status.FORBIDDEN,
+ "create-table mode '" + mode + "' must be authorized as an
overwrite");
+ verify(create, never()).proceed();
+ MethodInvocation register = registerTableInvocation(tableId(), mode);
+ assertErrorResponse(
+ interceptor.invoke(register),
+ Response.Status.FORBIDDEN,
+ "register-table mode '" + mode + "' must be authorized as an
overwrite");
+ verify(register, never()).proceed();
+ }
+ }
+
@Test
void testTableOverwriteRejectsIdentifiersOfTheWrongDepth() throws Throwable {
when(authorizer.isOwner(any(), any(), any(), any())).thenReturn(true);