Skip to content

Commit cc444a1

Browse files
committed
fix selection algorithm
1 parent cb7bd80 commit cc444a1

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
@@ -872,24 +872,32 @@ ALLOW_FEDERATED_CATALOGS_CREDENTIAL_VENDING, getResolvedCatalogEntity())) {
872872
private AccessDelegationMode selectAccessDelegationMode(
873873
Set<AccessDelegationMode> delegationModes) {
874874

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

895903
private void validateRemoteTableLocations(
@@ -1293,15 +1301,14 @@ private void checkAllowExternalCatalogCredentialVending() {
12931301
CatalogEntity catalogEntity = getResolvedCatalogEntity();
12941302

12951303
LOGGER.info("Catalog type: {}", catalogEntity.getCatalogType());
1296-
LOGGER.info(
1297-
"allow external catalog credential vending: {}",
1304+
Boolean allowCredentialVending =
12981305
realmConfig.getConfig(
1299-
FeatureConfiguration.ALLOW_EXTERNAL_CATALOG_CREDENTIAL_VENDING, catalogEntity));
1300-
if (catalogEntity
1306+
FeatureConfiguration.ALLOW_EXTERNAL_CATALOG_CREDENTIAL_VENDING, catalogEntity);
1307+
LOGGER.info("allow external catalog credential vending: {}", allowCredentialVending);
1308+
if (!allowCredentialVending
1309+
&& catalogEntity
13011310
.getCatalogType()
1302-
.equals(org.apache.polaris.core.admin.model.Catalog.TypeEnum.EXTERNAL)
1303-
&& !realmConfig.getConfig(
1304-
FeatureConfiguration.ALLOW_EXTERNAL_CATALOG_CREDENTIAL_VENDING, catalogEntity)) {
1311+
.equals(org.apache.polaris.core.admin.model.Catalog.TypeEnum.EXTERNAL)) {
13051312
throw new ForbiddenException(
13061313
"Access Delegation is not enabled for this catalog. Please consult applicable "
13071314
+ "documentation for the catalog config property '%s' to enable this feature",

0 commit comments

Comments
 (0)