Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#14936] fix: Pass ForbiddenException through catalog create-time validation (#14937)

geyanggangb6c49496ab2f
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: