You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by di...@apache.org on 2026/10/02 23:16:56 UTC
(polaris) branch main updated: fix: delete connection secrets when an external catalog is deleted (#5657)
This is an automated email from the ASF dual-hosted git repository.
dimas-b pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 5b8d154307 fix: delete connection secrets when an external catalog is deleted (#5657)
5b8d154307 is described below
commit 5b8d15430779c1b01c3a277c6f41fac4ba624bf2
Author: youngrae kim <16...@users.noreply.github.com>
AuthorDate: Sat Oct 3 08:16:50 2026 +0900
fix: delete connection secrets when an external catalog is deleted (#5657)
* fix: delete connection secrets when an external catalog is deleted
Creating an EXTERNAL catalog with inline OAuth client secret or bearer
token credentials writes them to the UserSecretsManager and stores only a
SecretReference in the catalog entity. Deleting the catalog dropped the
entity but never deleted those secrets, leaving unreferenced entries in
the secrets store. The only cleanup path was the one that runs after a
failed catalog creation.
After a successful drop, deleteCatalog now collects the secret references
from the catalog's connection configuration and deletes them, best effort
and logged on failure, reusing the existing cleanup helper. Authentication
types without inline secrets (IMPLICIT, SIGV4, GCP) and internal catalogs
are unaffected.
Fixes #5656
* Expose connection secret references on AuthenticationParametersDpo
Review feedback: instead of branching on the concrete OAuth and bearer
DPO types in PolarisAdminService, let each AuthenticationParametersDpo
report the secret references it holds. The base class returns an empty
list; the OAuth and bearer DPOs override it. Also replace a fully
qualified class name in the test with an import.
---
CHANGELOG.md | 3 +
.../connection/AuthenticationParametersDpo.java | 11 +++
.../BearerAuthenticationParametersDpo.java | 8 ++
.../OAuthClientCredentialsParametersDpo.java | 6 ++
.../polaris/service/admin/PolarisAdminService.java | 53 +++++++----
.../service/admin/PolarisAdminServiceTest.java | 102 +++++++++++++++++++++
6 files changed, 164 insertions(+), 19 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0f13e747e2..b2e116b848 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -168,6 +168,9 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti
### Fixes
+- Deleting an external catalog now also deletes the inline connection secrets (OAuth client secret
+ or bearer token) that were written to the `UserSecretsManager` when the catalog was created.
+ Previously they stayed in the secrets store with no entity referencing them.
- Catalog federation: `connectionConfigInfo.properties` is now persisted and returned for `HADOOP`
and `HIVE` connection configurations. It was previously accepted by the management API but
silently dropped, so `GET /catalogs/{name}` never showed it.
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/connection/AuthenticationParametersDpo.java b/polaris-core/src/main/java/org/apache/polaris/core/connection/AuthenticationParametersDpo.java
index 1205fb1d34..f7afb8e1e9 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/connection/AuthenticationParametersDpo.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/connection/AuthenticationParametersDpo.java
@@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import java.util.List;
import java.util.Map;
import org.apache.polaris.core.admin.model.AuthenticationParameters;
import org.apache.polaris.core.admin.model.OAuthClientCredentialsParameters;
@@ -69,6 +70,16 @@ public abstract class AuthenticationParametersDpo implements IcebergCatalogPrope
public abstract @NonNull AuthenticationParameters asAuthenticationParametersModel();
+ /**
+ * Returns the references to the secrets that were offloaded to the {@code UserSecretsManager}
+ * when the owning entity was created, so that they can be deleted together with the entity.
+ * Authentication types without inline secrets return an empty list.
+ */
+ @JsonIgnore
+ public @NonNull List<SecretReference> getSecretReferences() {
+ return List.of();
+ }
+
public static AuthenticationParametersDpo fromAuthenticationParametersModelWithSecrets(
AuthenticationParameters authenticationParameters,
Map<String, SecretReference> secretReferences) {
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/connection/BearerAuthenticationParametersDpo.java b/polaris-core/src/main/java/org/apache/polaris/core/connection/BearerAuthenticationParametersDpo.java
index 75dd898be1..08275fbd13 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/connection/BearerAuthenticationParametersDpo.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/connection/BearerAuthenticationParametersDpo.java
@@ -18,8 +18,10 @@
*/
package org.apache.polaris.core.connection;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
+import java.util.List;
import org.apache.polaris.core.admin.model.AuthenticationParameters;
import org.apache.polaris.core.admin.model.BearerAuthenticationParameters;
import org.apache.polaris.core.secrets.SecretReference;
@@ -45,6 +47,12 @@ public class BearerAuthenticationParametersDpo extends AuthenticationParametersD
return bearerTokenReference;
}
+ @JsonIgnore
+ @Override
+ public @NonNull List<SecretReference> getSecretReferences() {
+ return List.of(bearerTokenReference);
+ }
+
@Override
public @NonNull AuthenticationParameters asAuthenticationParametersModel() {
return BearerAuthenticationParameters.builder()
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/connection/OAuthClientCredentialsParametersDpo.java b/polaris-core/src/main/java/org/apache/polaris/core/connection/OAuthClientCredentialsParametersDpo.java
index bba9c8bded..8eff79ae0c 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/connection/OAuthClientCredentialsParametersDpo.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/connection/OAuthClientCredentialsParametersDpo.java
@@ -82,6 +82,12 @@ public class OAuthClientCredentialsParametersDpo extends AuthenticationParameter
return clientSecretReference;
}
+ @JsonIgnore
+ @Override
+ public @NonNull List<SecretReference> getSecretReferences() {
+ return List.of(clientSecretReference);
+ }
+
public @Nullable List<String> getScopes() {
return scopes;
}
diff --git a/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java b/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java
index 13ad6a1503..b89326774f 100644
--- a/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java
+++ b/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java
@@ -28,6 +28,7 @@ import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -93,6 +94,7 @@ import org.apache.polaris.core.catalog.PolarisCatalogHelpers;
import org.apache.polaris.core.config.FeatureConfiguration;
import org.apache.polaris.core.config.RealmConfig;
import org.apache.polaris.core.connection.AuthenticationParametersDpo;
+import org.apache.polaris.core.connection.ConnectionConfigInfoDpo;
import org.apache.polaris.core.context.CallContext;
import org.apache.polaris.core.entity.CatalogEntity;
import org.apache.polaris.core.entity.CatalogRoleEntity;
@@ -795,24 +797,20 @@ public class PolarisAdminService {
return secretReferences;
}
- private void deleteSecretReferencesAfterFailedCatalogCreate(
- Map<String, SecretReference> secretReferences) {
- secretReferences
- .values()
- .forEach(
- secretReference -> {
- try {
- getUserSecretsManager().deleteSecret(secretReference);
- } catch (RuntimeException e) {
- LOGGER
- .atWarn()
- .setCause(e)
- .addKeyValue(StructuredLogKeys.SECRET_REFERENCE, secretReference.urn())
- .log(
- "Failed to clean up secret {} after catalog creation failure",
- secretReference.urn());
- }
- });
+ private void deleteSecretReferences(
+ Collection<SecretReference> secretReferences, String context) {
+ secretReferences.forEach(
+ secretReference -> {
+ try {
+ getUserSecretsManager().deleteSecret(secretReference);
+ } catch (RuntimeException e) {
+ LOGGER
+ .atWarn()
+ .setCause(e)
+ .addKeyValue(StructuredLogKeys.SECRET_REFERENCE, secretReference.urn())
+ .log("Failed to clean up secret {} while {}", secretReference.urn(), context);
+ }
+ });
}
/**
@@ -920,7 +918,8 @@ public class PolarisAdminService {
return PolarisEntity.of(catalogResult.getCatalog());
} finally {
if (!catalogCreated) {
- deleteSecretReferencesAfterFailedCatalogCreate(processedSecretReferences);
+ deleteSecretReferences(
+ processedSecretReferences.values(), "cleaning up after a failed catalog creation");
}
}
}
@@ -939,6 +938,22 @@ public class PolarisAdminService {
DropEntityFailureMapper.throwIfFailed(
dropEntityResult, () -> String.format("Catalog '%s'", entity.getName()), null);
+
+ // The catalog entity is gone; release the inline connection secrets that were written to the
+ // secrets manager when the catalog was created.
+ deleteSecretReferences(
+ connectionSecretReferences(entity.getConnectionConfigInfoDpo()),
+ String.format("deleting catalog '%s'", entity.getName()));
+ }
+
+ /** Returns the secret references held by a federated catalog's connection configuration. */
+ private static List<SecretReference> connectionSecretReferences(
+ @Nullable ConnectionConfigInfoDpo connectionConfigInfoDpo) {
+ if (connectionConfigInfoDpo == null
+ || connectionConfigInfoDpo.getAuthenticationParameters() == null) {
+ return List.of();
+ }
+ return connectionConfigInfoDpo.getAuthenticationParameters().getSecretReferences();
}
public @NonNull CatalogEntity getCatalog(String name) {
diff --git a/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java b/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java
index d0c0c9a6f4..d0b950a090 100644
--- a/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java
+++ b/runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java
@@ -22,6 +22,7 @@ import static org.apache.polaris.core.entity.PolarisEntitySubType.ICEBERG_TABLE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
@@ -60,6 +61,10 @@ import org.apache.polaris.core.collection.AttributeMap;
import org.apache.polaris.core.config.BehaviorChangeConfiguration;
import org.apache.polaris.core.config.FeatureConfiguration;
import org.apache.polaris.core.config.RealmConfig;
+import org.apache.polaris.core.connection.AuthenticationParametersDpo;
+import org.apache.polaris.core.connection.BearerAuthenticationParametersDpo;
+import org.apache.polaris.core.connection.OAuthClientCredentialsParametersDpo;
+import org.apache.polaris.core.connection.iceberg.IcebergRestConnectionConfigInfoDpo;
import org.apache.polaris.core.context.CallContext;
import org.apache.polaris.core.entity.CatalogEntity;
import org.apache.polaris.core.entity.NamespaceEntity;
@@ -79,6 +84,7 @@ import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
import org.apache.polaris.core.persistence.ResolvedPolarisEntity;
import org.apache.polaris.core.persistence.dao.entity.BaseResult;
import org.apache.polaris.core.persistence.dao.entity.CreateCatalogResult;
+import org.apache.polaris.core.persistence.dao.entity.DropEntityResult;
import org.apache.polaris.core.persistence.dao.entity.EntityResult;
import org.apache.polaris.core.persistence.dao.entity.GenerateEntityIdResult;
import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult;
@@ -234,6 +240,102 @@ public class PolarisAdminServiceTest {
verify(userSecretsManager, never()).deleteSecret(any());
}
+ @Test
+ void testDeleteCatalogDeletesInlineOauthSecret() {
+ SecretReference secretReference =
+ new SecretReference("urn:polaris-secret:test:oauth", Map.of());
+ setupExternalCatalogDelete(
+ new OAuthClientCredentialsParametersDpo(null, "client-id", secretReference, null));
+
+ adminService.deleteCatalog("external-catalog");
+
+ verify(userSecretsManager).deleteSecret(secretReference);
+ }
+
+ @Test
+ void testDeleteCatalogDeletesInlineBearerSecret() {
+ SecretReference secretReference =
+ new SecretReference("urn:polaris-secret:test:bearer", Map.of());
+ setupExternalCatalogDelete(new BearerAuthenticationParametersDpo(secretReference));
+
+ adminService.deleteCatalog("external-catalog");
+
+ verify(userSecretsManager).deleteSecret(secretReference);
+ }
+
+ @Test
+ void testDeleteCatalogSucceedsWhenSecretDeletionFails() {
+ SecretReference secretReference =
+ new SecretReference("urn:polaris-secret:test:oauth", Map.of());
+ setupExternalCatalogDelete(
+ new OAuthClientCredentialsParametersDpo(null, "client-id", secretReference, null));
+ doThrow(new RuntimeException("cleanup failed")).when(userSecretsManager).deleteSecret(any());
+
+ adminService.deleteCatalog("external-catalog");
+
+ verify(userSecretsManager).deleteSecret(secretReference);
+ }
+
+ @Test
+ void testDeleteCatalogKeepsSecretsWhenDropFails() {
+ SecretReference secretReference =
+ new SecretReference("urn:polaris-secret:test:oauth", Map.of());
+ setupExternalCatalogDelete(
+ new OAuthClientCredentialsParametersDpo(null, "client-id", secretReference, null));
+ when(metaStoreManager.dropEntityIfExists(any(), any(), any(), any(), anyBoolean()))
+ .thenReturn(
+ new DropEntityResult(BaseResult.ReturnStatus.ENTITY_UNDROPPABLE, "not droppable"));
+
+ assertThatThrownBy(() -> adminService.deleteCatalog("external-catalog"))
+ .isInstanceOf(RuntimeException.class);
+
+ verify(userSecretsManager, never()).deleteSecret(any());
+ }
+
+ @Test
+ void testDeleteInternalCatalogDoesNotTouchSecrets() {
+ CatalogEntity catalogEntity =
+ new CatalogEntity.Builder().setName("internal-catalog").setId(200L).build();
+ mockCatalogResolution(catalogEntity);
+ when(metaStoreManager.dropEntityIfExists(any(), any(), any(), any(), anyBoolean()))
+ .thenReturn(new DropEntityResult());
+
+ adminService.deleteCatalog("internal-catalog");
+
+ verify(userSecretsManager, never()).deleteSecret(any());
+ }
+
+ private void setupExternalCatalogDelete(AuthenticationParametersDpo authenticationParameters) {
+ CatalogEntity catalogEntity =
+ new CatalogEntity.Builder()
+ .setName("external-catalog")
+ .setId(200L)
+ .setConnectionConfigInfoDpo(
+ new IcebergRestConnectionConfigInfoDpo(
+ "https://example.com/polaris/api/catalog",
+ authenticationParameters,
+ null,
+ "remote-catalog",
+ null))
+ .build();
+ mockCatalogResolution(catalogEntity);
+ }
+
+ private void mockCatalogResolution(CatalogEntity catalogEntity) {
+ PolarisResolvedPathWrapper wrapper = mock(PolarisResolvedPathWrapper.class);
+ when(wrapper.getRawLeafEntity()).thenReturn(catalogEntity);
+ ResolvedPolarisEntity resolvedLeaf = mock(ResolvedPolarisEntity.class);
+ when(resolvedLeaf.getEntity()).thenReturn(catalogEntity);
+ when(wrapper.getResolvedLeafEntity()).thenReturn(resolvedLeaf);
+ when(resolutionManifest.getResolvedTopLevelEntity(
+ eq(catalogEntity.getName()), eq(PolarisEntityType.CATALOG)))
+ .thenReturn(wrapper);
+ when(resolutionManifest.getResolvedCatalogEntity()).thenReturn(catalogEntity);
+ when(realmConfig.getConfig(FeatureConfiguration.CLEANUP_ON_CATALOG_DROP)).thenReturn(false);
+ when(metaStoreManager.dropEntityIfExists(any(), any(), any(), any(), anyBoolean()))
+ .thenReturn(new DropEntityResult());
+ }
+
@Test
void testGrantPrivilegeOnNamespaceToRole() throws Exception {
String catalogName = "test-catalog";