Skip to content

Commit f843555

Browse files
committed
fix selection algorithm
1 parent e025110 commit f843555

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -870,24 +870,32 @@ ALLOW_FEDERATED_CATALOGS_CREDENTIAL_VENDING, getResolvedCatalogEntity())) {
870870
private AccessDelegationMode selectAccessDelegationMode(
871871
Set<AccessDelegationMode> delegationModes) {
872872

873-
// Whether vending credentials is globally enabled
874-
boolean skipCredIndirection =
875-
realmConfig.getConfig(FeatureConfiguration.SKIP_CREDENTIAL_SUBSCOPING_INDIRECTION);
876-
877-
// Credential subscoping is only allowed for local catalogs
878-
// and federated catalogs that have credential vending explicitly enabled.
879-
boolean credentialSubscopingAllowed =
880-
baseCatalog instanceof IcebergCatalog
881-
|| realmConfig.getConfig(
882-
ALLOW_FEDERATED_CATALOGS_CREDENTIAL_VENDING, getResolvedCatalogEntity());
883-
884-
// Always prefer VENDED_CREDENTIALS if requested and available,
885-
// even if REMOTE_SIGNING is also requested.
886-
return delegationModes.contains(VENDED_CREDENTIALS)
887-
&& credentialSubscopingAllowed
888-
&& !skipCredIndirection
889-
? VENDED_CREDENTIALS
890-
: delegationModes.contains(REMOTE_SIGNING) ? REMOTE_SIGNING : UNKNOWN;
873+
if (delegationModes.isEmpty()) {
874+
return UNKNOWN;
875+
}
876+
877+
if (delegationModes.size() == 1) {
878+
return delegationModes.iterator().next();
879+
}
880+
881+
if (delegationModes.contains(VENDED_CREDENTIALS) && delegationModes.contains(REMOTE_SIGNING)) {
882+
883+
boolean skipCredIndirection =
884+
realmConfig.getConfig(FeatureConfiguration.SKIP_CREDENTIAL_SUBSCOPING_INDIRECTION);
885+
886+
boolean credentialSubscopingAllowed =
887+
baseCatalog instanceof IcebergCatalog
888+
|| realmConfig.getConfig(
889+
ALLOW_FEDERATED_CATALOGS_CREDENTIAL_VENDING, getResolvedCatalogEntity());
890+
891+
// If both modes are supported, prefer VENDED_CREDENTIALS,
892+
// but only if credential subscoping is allowed for this catalog
893+
return !skipCredIndirection && credentialSubscopingAllowed
894+
? VENDED_CREDENTIALS
895+
: REMOTE_SIGNING;
896+
}
897+
898+
throw new IllegalArgumentException("Unsupported access delegation modes: " + delegationModes);
891899
}
892900

893901
private void validateRemoteTableLocations(
@@ -1291,15 +1299,14 @@ private void checkAllowExternalCatalogCredentialVending() {
12911299
CatalogEntity catalogEntity = getResolvedCatalogEntity();
12921300

12931301
LOGGER.info("Catalog type: {}", catalogEntity.getCatalogType());
1294-
LOGGER.info(
1295-
"allow external catalog credential vending: {}",
1302+
Boolean allowCredentialVending =
12961303
realmConfig.getConfig(
1297-
FeatureConfiguration.ALLOW_EXTERNAL_CATALOG_CREDENTIAL_VENDING, catalogEntity));
1298-
if (catalogEntity
1304+
FeatureConfiguration.ALLOW_EXTERNAL_CATALOG_CREDENTIAL_VENDING, catalogEntity);
1305+
LOGGER.info("allow external catalog credential vending: {}", allowCredentialVending);
1306+
if (!allowCredentialVending
1307+
&& catalogEntity
12991308
.getCatalogType()
1300-
.equals(org.apache.polaris.core.admin.model.Catalog.TypeEnum.EXTERNAL)
1301-
&& !realmConfig.getConfig(
1302-
FeatureConfiguration.ALLOW_EXTERNAL_CATALOG_CREDENTIAL_VENDING, catalogEntity)) {
1309+
.equals(org.apache.polaris.core.admin.model.Catalog.TypeEnum.EXTERNAL)) {
13031310
throw new ForbiddenException(
13041311
"Access Delegation is not enabled for this catalog. Please consult applicable "
13051312
+ "documentation for the catalog config property '%s' to enable this feature",

0 commit comments

Comments
 (0)