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 b6c49496ab [#14936] fix: Pass ForbiddenException through catalog
create-time validation (#14937)
b6c49496ab is described below
commit b6c49496ab2f45af023d13f555c715fd2afacca5
Author: geyanggang <[email protected]>
AuthorDate: Fri Nov 13 15:54:39 2026 +0800
[#14936] fix: Pass ForbiddenException through catalog create-time
validation (#14937)
### What changes were proposed in this pull request?
- `CatalogManager.initCatalogWrapper` now passes `ForbiddenException`
through unchanged, in addition to `IllegalArgumentException` and
`ConnectionFailedException`, when a catalog's create-time validation
throws it.
- Document the 403 response of `createCatalog` in the OpenAPI spec.
- Add `testCreateCatalogPropagatesBackendForbidden`, with a
`need-forbid` switch in the test catalog operations. The test checks
that the exception is not wrapped and that the cache and the store are
rolled back.
### Why are the changes needed?
A backend that refuses the credentials configured for a catalog is a
caller-side configuration problem. A catalog implementation can report
it with `ForbiddenException`, and the catalog REST exception handler
maps that to 403. But the exception was wrapped in a plain
`RuntimeException` by the class loader passthrough, so creating the
catalog returned 500. The only alternative for a catalog was
`ConnectionFailedException` (502, "retry later"), which is wrong for a
request that can never succeed. The standalone connection test already
reports the same denial as 403.
Only exceptions that were previously turned into a 500 change. 400 and
502 results and the failure cleanup are unchanged.
Fixes #14936
### Does this PR introduce _any_ user-facing change?
Creating a catalog whose create-time validation throws
`ForbiddenException` now returns 403 instead of 500. No API or property
changes; the OpenAPI spec now lists the 403 response of `createCatalog`.
### How was this patch tested?
- New unit test
`TestCatalogManager#testCreateCatalogPropagatesBackendForbidden`.
Without the fix it fails with `RuntimeException`.
- `./gradlew :core:spotlessJavaCheck :core:javadoc :core:coreUnitTest
--tests '*TestCatalogManager*' -PskipITs` passes (61 tests).
- `./gradlew :docs:build` passes.
---
.../apache/gravitino/catalog/CatalogManager.java | 7 +++--
.../gravitino/catalog/TestCatalogManager.java | 33 ++++++++++++++++++++++
.../gravitino/connector/TestCatalogOperations.java | 6 ++++
docs/open-api/catalogs.yaml | 8 ++++++
4 files changed, 52 insertions(+), 2 deletions(-)
diff --git
a/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
b/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
index 27b8d8fc65..4d4f0cc3f9 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
@@ -94,6 +94,7 @@ import
org.apache.gravitino.exceptions.CatalogAlreadyExistsException;
import org.apache.gravitino.exceptions.CatalogInUseException;
import org.apache.gravitino.exceptions.CatalogNotInUseException;
import org.apache.gravitino.exceptions.ConnectionFailedException;
+import org.apache.gravitino.exceptions.ForbiddenException;
import org.apache.gravitino.exceptions.GravitinoRuntimeException;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
import org.apache.gravitino.exceptions.NoSuchEntityException;
@@ -1923,7 +1924,8 @@ public class CatalogManager implements CatalogDispatcher,
Closeable {
// Validate opted-in catalogs so a misconfiguration fails at
create rather than on
// first use. The default validation eagerly initializes ops();
JDBC overrides it to
// run a real backend probe. The backend translates failures into
the caller-error vs
- // dependency-unavailable taxonomy; both types are forwarded by
the passthrough below.
+ // dependency-unavailable taxonomy; both types are forwarded by
the passthrough below,
+ // as is ForbiddenException when the backend refuses the
configured credentials.
// The backend probe is gated by validateBackend so the standalone
testConnection path
// can keep property validation while running its own explicit
probe instead.
if (validateBackend && propsToValidate != null &&
catalog.shouldValidateOnCreate()) {
@@ -1932,7 +1934,8 @@ public class CatalogManager implements CatalogDispatcher,
Closeable {
return null;
},
IllegalArgumentException.class,
- ConnectionFailedException.class);
+ ConnectionFailedException.class,
+ ForbiddenException.class);
} catch (RuntimeException e) {
// Close the partially-initialized catalog (which releases its
authorizationPlugin and other
// resources) before the caller tears down or releases the ClassLoader.
Otherwise a creation
diff --git
a/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java
b/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java
index 903e7a5395..f6b57eb04c 100644
--- a/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java
+++ b/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java
@@ -82,6 +82,7 @@ import org.apache.gravitino.credential.CredentialConstants;
import org.apache.gravitino.exceptions.CatalogAlreadyExistsException;
import org.apache.gravitino.exceptions.CatalogNotInUseException;
import org.apache.gravitino.exceptions.ConnectionFailedException;
+import org.apache.gravitino.exceptions.ForbiddenException;
import org.apache.gravitino.exceptions.GravitinoRuntimeException;
import org.apache.gravitino.exceptions.NoSuchCatalogException;
import org.apache.gravitino.exceptions.NoSuchEntityException;
@@ -1011,6 +1012,38 @@ public class TestCatalogManager {
"4",
catalogManager.loadCatalog(ident).properties().get("validation-max"));
}
+ @Test
+ public void testCreateCatalogPropagatesBackendForbidden() throws Exception {
+ // The create-time probe reports that the backend refuses the configured
credentials: the
+ // ForbiddenException must reach the caller unwrapped, and creation must
roll back the cache and
+ // the store.
+ NameIdentifier forbidIdent = NameIdentifier.of("metalake",
"verify-testconn-forbid");
+ Map<String, String> forbidProps =
+ Maps.newHashMap(
+ ImmutableMap.of(
+ PROPERTY_KEY1,
+ "value1",
+ PROPERTY_KEY2,
+ "value2",
+ PROPERTY_KEY5_PREFIX + "1",
+ "value3",
+ TestCatalogOperations.VALIDATE_ON_CREATE,
+ "true",
+ TestCatalogOperations.FORBID_TEST,
+ "true"));
+ ForbiddenException exception =
+ Assertions.assertThrows(
+ ForbiddenException.class,
+ () ->
+ catalogManager.createCatalog(
+ forbidIdent, Catalog.Type.RELATIONAL, provider, "comment",
forbidProps));
+ Assertions.assertEquals("Backend denied access", exception.getMessage());
+
Assertions.assertNull(catalogManager.getCatalogCache().getIfPresent(forbidIdent));
+ Assertions.assertThrows(
+ NoSuchEntityException.class,
+ () -> entityStore.get(forbidIdent, EntityType.CATALOG,
CatalogEntity.class));
+ }
+
@Test
public void testCreateCatalogVerifiesBackendViaTestConnection() throws
Exception {
// Opted in via validateOnCreate() force-probe, and the probe reports the
backend unreachable:
diff --git
a/core/src/test/java/org/apache/gravitino/connector/TestCatalogOperations.java
b/core/src/test/java/org/apache/gravitino/connector/TestCatalogOperations.java
index b56272877e..51748deef0 100644
---
a/core/src/test/java/org/apache/gravitino/connector/TestCatalogOperations.java
+++
b/core/src/test/java/org/apache/gravitino/connector/TestCatalogOperations.java
@@ -58,6 +58,7 @@ import org.apache.gravitino.audit.FilesetAuditConstants;
import org.apache.gravitino.audit.FilesetDataOperation;
import org.apache.gravitino.exceptions.ConnectionFailedException;
import org.apache.gravitino.exceptions.FilesetAlreadyExistsException;
+import org.apache.gravitino.exceptions.ForbiddenException;
import org.apache.gravitino.exceptions.GravitinoRuntimeException;
import org.apache.gravitino.exceptions.ModelAlreadyExistsException;
import
org.apache.gravitino.exceptions.ModelVersionAliasesAlreadyExistException;
@@ -137,6 +138,7 @@ public class TestCatalogOperations
public static final String FAIL_CREATE = "fail-create";
public static final String FAIL_TEST = "need-fail";
+ public static final String FORBID_TEST = "need-forbid";
public static final String VALIDATE_ON_CREATE = "validate-on-create";
@@ -907,6 +909,10 @@ public class TestCatalogOperations
if ("true".equals(config.get(FAIL_TEST))) {
throw new ConnectionFailedException("Connection failed");
}
+ // Mirror a backend that refuses the configured credentials.
+ if ("true".equals(config.get(FORBID_TEST))) {
+ throw new ForbiddenException("Backend denied access");
+ }
// A catalog that opts into create-time verification mirrors a reachable
JDBC backend: the probe
// succeeds. Otherwise keep the interface default (unsupported) so the
standalone testConnection
// REST path still reports that this test catalog does not support
connection testing.
diff --git a/docs/open-api/catalogs.yaml b/docs/open-api/catalogs.yaml
index 695ef01737..bb0370fd9f 100644
--- a/docs/open-api/catalogs.yaml
+++ b/docs/open-api/catalogs.yaml
@@ -69,6 +69,14 @@ paths:
responses:
"200":
$ref: "#/components/responses/CatalogResponse"
+ "403":
+ description: >-
+ Forbidden - The caller cannot create catalogs in the metalake, or
the backend refuses
+ the credentials configured for the catalog when it is validated at
creation
+ content:
+ application/vnd.gravitino.v1+json:
+ schema:
+ $ref: "./openapi.yaml#/components/schemas/ErrorModel"
"409":
description: Conflict - The target catalog already exists in the
specified metalake
content: