dimas-b commented on code in PR #2759:
URL: https://github.com/apache/polaris/pull/2759#discussion_r2411585047


##########
polaris-core/src/main/java/org/apache/polaris/core/credentials/connection/CatalogAccessProperty.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.core.credentials.connection;
+
+import org.apache.iceberg.aws.AwsProperties;
+
+/**
+ * A subset of Iceberg catalog properties recognized by Polaris.
+ *
+ * <p>Most of these properties are meant to initialize Catalog objects for 
accessing the remote
+ * Catalog service.
+ */
+public enum CatalogAccessProperty {
+  AWS_ACCESS_KEY_ID(String.class, AwsProperties.REST_ACCESS_KEY_ID, "the aws 
access key id", true),
+  AWS_SECRET_ACCESS_KEY(
+      String.class, AwsProperties.REST_SECRET_ACCESS_KEY, "the aws access key 
secret", true),
+  AWS_SESSION_TOKEN(
+      String.class, AwsProperties.REST_SESSION_TOKEN, "the aws scoped access 
token", true),
+  EXPIRATION_TIME(

Review Comment:
   Do we actually need this to be an enum value? I do not see any real usage of 
it 🤔 



##########
runtime/service/src/main/java/org/apache/polaris/service/credentials/PolarisCredentialManagerConfiguration.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.service.credentials;
+
+import io.quarkus.runtime.annotations.StaticInitSafe;
+import io.smallrye.config.ConfigMapping;
+import org.apache.polaris.core.credentials.PolarisCredentialManager;
+
+/**
+ * Quarkus configuration mapping for Polaris Credential Manager.
+ *
+ * <p>Defines which {@link PolarisCredentialManager} implementation should be 
used at runtime. This
+ * allows switching between different credential management strategies via 
configuration.
+ */
+@StaticInitSafe
+@ConfigMapping(prefix = "polaris.credential-manager")
+public interface PolarisCredentialManagerConfiguration {
+
+  /**
+   * The type identifier of the PolarisCredentialManager implementation to 
use. This corresponds to
+   * the {@code @Identifier} annotation value on the implementation (e.g., 
"default").
+   */
+  String type();

Review Comment:
   nit: Do we expect more config properties here? If not, it could be folded 
into the producer, as in: 
https://github.com/apache/polaris/blob/20febdaede19fb7c46e120652fdd1a262c2138e4/runtime/admin/src/main/java/org/apache/polaris/admintool/config/AdminToolProducers.java#L41



##########
runtime/service/src/main/java/org/apache/polaris/service/credentials/DefaultPolarisCredentialManager.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.service.credentials;
+
+import jakarta.annotation.Nonnull;
+import jakarta.enterprise.inject.Any;
+import jakarta.enterprise.inject.Instance;
+import org.apache.polaris.core.connection.AuthenticationType;
+import org.apache.polaris.core.connection.ConnectionConfigInfoDpo;
+import org.apache.polaris.core.credentials.PolarisCredentialManager;
+import 
org.apache.polaris.core.credentials.connection.ConnectionCredentialVendor;
+import org.apache.polaris.core.credentials.connection.ConnectionCredentials;
+import org.apache.polaris.service.credentials.connection.SupportsAuthType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default implementation of {@link PolarisCredentialManager} responsible for 
retrieving credentials
+ * used by Polaris to access external systems such as remote catalogs or cloud 
storage.
+ *
+ * <p>This implementation delegates to {@link ConnectionCredentialVendor} 
implementations selected
+ * via CDI based on the authentication type. Each vendor handles the 
credential transformation logic
+ * for a specific authentication mechanism (e.g., SigV4, OAuth).
+ *
+ * <p>Flow:
+ *
+ * <ol>
+ *   <li>Selects the appropriate {@link ConnectionCredentialVendor} based on 
the authentication type
+ *   <li>Delegates to the vendor to generate the final connection credentials 
(the vendor will
+ *       resolve the service identity internally)
+ * </ol>
+ */
+public class DefaultPolarisCredentialManager implements 
PolarisCredentialManager {
+  private static final Logger LOGGER =
+      LoggerFactory.getLogger(DefaultPolarisCredentialManager.class);
+
+  private final Instance<ConnectionCredentialVendor> credentialVendors;
+
+  public DefaultPolarisCredentialManager(
+      @Any Instance<ConnectionCredentialVendor> credentialVendors) {
+    this.credentialVendors = credentialVendors;
+  }
+
+  @Override
+  public @Nonnull ConnectionCredentials getConnectionCredentials(
+      @Nonnull ConnectionConfigInfoDpo connectionConfig) {
+
+    // Select the appropriate vendor based on authentication type
+    AuthenticationType authType =
+        connectionConfig.getAuthenticationParameters().getAuthenticationType();
+    Instance<ConnectionCredentialVendor> selectedVendor =
+        credentialVendors.select(SupportsAuthType.Literal.of(authType));

Review Comment:
   I'll open a new thread with more concrete suggestions just for the current 
PR.



##########
runtime/service/src/main/java/org/apache/polaris/service/credentials/DefaultPolarisCredentialManager.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.service.credentials;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.annotation.Nonnull;
+import jakarta.enterprise.context.RequestScoped;
+import jakarta.enterprise.inject.Any;
+import jakarta.enterprise.inject.Instance;
+import jakarta.inject.Inject;
+import org.apache.polaris.core.connection.AuthenticationType;
+import org.apache.polaris.core.connection.ConnectionConfigInfoDpo;
+import org.apache.polaris.core.context.RealmContext;
+import org.apache.polaris.core.credentials.PolarisCredentialManager;
+import 
org.apache.polaris.core.credentials.connection.ConnectionCredentialVendor;
+import org.apache.polaris.core.credentials.connection.ConnectionCredentials;
+import org.apache.polaris.service.credentials.connection.AuthType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default implementation of {@link PolarisCredentialManager} responsible for 
retrieving credentials
+ * used by Polaris to access external systems such as remote catalogs or cloud 
storage.
+ *
+ * <p>This implementation delegates to {@link ConnectionCredentialVendor} 
implementations selected
+ * via CDI based on the authentication type. Each vendor handles the 
credential transformation logic
+ * for a specific authentication mechanism (e.g., SigV4, OAuth).
+ *
+ * <p>This bean is request-scoped and realm-aware, delegating all credential 
generation to
+ * CDI-managed vendors.
+ *
+ * <p>Flow:
+ *
+ * <ol>
+ *   <li>Selects the appropriate {@link ConnectionCredentialVendor} based on 
the authentication type
+ *   <li>Delegates to the vendor to generate the final connection credentials 
(the vendor will
+ *       resolve the service identity internally)
+ * </ol>
+ */
+@RequestScoped
+@Identifier("default")
+public class DefaultPolarisCredentialManager implements 
PolarisCredentialManager {
+  private static final Logger LOGGER =
+      LoggerFactory.getLogger(DefaultPolarisCredentialManager.class);
+
+  private final RealmContext realmContext;
+  private final Instance<ConnectionCredentialVendor> credentialVendors;
+
+  @Inject
+  public DefaultPolarisCredentialManager(
+      RealmContext realmContext, @Any Instance<ConnectionCredentialVendor> 
credentialVendors) {
+    this.realmContext = realmContext;
+    this.credentialVendors = credentialVendors;
+  }
+
+  public RealmContext getRealmContext() {
+    return realmContext;
+  }
+
+  @Override
+  public @Nonnull ConnectionCredentials getConnectionCredentials(
+      @Nonnull ConnectionConfigInfoDpo connectionConfig) {
+
+    // Select the appropriate vendor based on authentication type
+    AuthenticationType authType =
+        connectionConfig.getAuthenticationParameters().getAuthenticationType();
+    Instance<ConnectionCredentialVendor> selectedVendor =
+        credentialVendors.select(AuthType.Literal.of(authType));
+
+    if (selectedVendor.isUnsatisfied()) {

Review Comment:
   Calling `credentialVendors.select()` looks reasonable to me, but getting too 
much into CDI internals looks like an overkill. Is there material benefit in 
having this custom logic as opposed to letting the CDI framework throw an 
exception from `selectedVendor.get()`?



##########
runtime/service/src/main/java/org/apache/polaris/service/credentials/DefaultPolarisCredentialManager.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.polaris.service.credentials;
+
+import io.smallrye.common.annotation.Identifier;
+import jakarta.annotation.Nonnull;
+import jakarta.enterprise.context.RequestScoped;
+import jakarta.enterprise.inject.Any;
+import jakarta.enterprise.inject.Instance;
+import jakarta.inject.Inject;
+import org.apache.polaris.core.connection.AuthenticationType;
+import org.apache.polaris.core.connection.ConnectionConfigInfoDpo;
+import org.apache.polaris.core.context.RealmContext;
+import org.apache.polaris.core.credentials.PolarisCredentialManager;
+import 
org.apache.polaris.core.credentials.connection.ConnectionCredentialVendor;
+import org.apache.polaris.core.credentials.connection.ConnectionCredentials;
+import org.apache.polaris.service.credentials.connection.AuthType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default implementation of {@link PolarisCredentialManager} responsible for 
retrieving credentials
+ * used by Polaris to access external systems such as remote catalogs or cloud 
storage.
+ *
+ * <p>This implementation delegates to {@link ConnectionCredentialVendor} 
implementations selected
+ * via CDI based on the authentication type. Each vendor handles the 
credential transformation logic
+ * for a specific authentication mechanism (e.g., SigV4, OAuth).
+ *
+ * <p>This bean is request-scoped and realm-aware, delegating all credential 
generation to
+ * CDI-managed vendors.
+ *
+ * <p>Flow:
+ *
+ * <ol>
+ *   <li>Selects the appropriate {@link ConnectionCredentialVendor} based on 
the authentication type
+ *   <li>Delegates to the vendor to generate the final connection credentials 
(the vendor will
+ *       resolve the service identity internally)
+ * </ol>
+ */
+@RequestScoped
+@Identifier("default")
+public class DefaultPolarisCredentialManager implements 
PolarisCredentialManager {
+  private static final Logger LOGGER =
+      LoggerFactory.getLogger(DefaultPolarisCredentialManager.class);
+
+  private final RealmContext realmContext;
+  private final Instance<ConnectionCredentialVendor> credentialVendors;
+
+  @Inject
+  public DefaultPolarisCredentialManager(
+      RealmContext realmContext, @Any Instance<ConnectionCredentialVendor> 
credentialVendors) {
+    this.realmContext = realmContext;
+    this.credentialVendors = credentialVendors;
+  }
+
+  public RealmContext getRealmContext() {
+    return realmContext;
+  }
+
+  @Override
+  public @Nonnull ConnectionCredentials getConnectionCredentials(
+      @Nonnull ConnectionConfigInfoDpo connectionConfig) {
+
+    // Select the appropriate vendor based on authentication type
+    AuthenticationType authType =
+        connectionConfig.getAuthenticationParameters().getAuthenticationType();
+    Instance<ConnectionCredentialVendor> selectedVendor =
+        credentialVendors.select(AuthType.Literal.of(authType));
+
+    if (selectedVendor.isUnsatisfied()) {
+      // TODO: Add credential vendors for other authentication types
+      LOGGER.warn("No connection credential vendor found for authentication 
type: {}", authType);
+      return ConnectionCredentials.builder().build();
+    }
+
+    if (selectedVendor.isAmbiguous()) {
+      LOGGER.error(
+          "Multiple connection credential vendors found for authentication 
type: {}. "
+              + "Use @Priority to specify which vendor should be used. "
+              + "Higher priority values take precedence.",
+          authType);
+      throw new IllegalStateException(
+          String.format(
+              "Ambiguous connection credential vendor for authentication type: 
%s. "
+                  + "Multiple implementations found without @Priority 
annotation.",
+              authType));
+    }
+
+    // Delegate to the vendor to generate credentials
+    return selectedVendor.get().getConnectionCredentials(connectionConfig);

Review Comment:
   Since `DefaultPolarisCredentialManager` multiplexes over type-specific lower 
level implementations, having them under the same java interface 
(`ConnectionCredentialVendor`) does not sound right to me.
   
   If a `ConnectionCredentialVendor` is impl. it type-specific, then 
`DefaultPolarisCredentialManager` should not be a sub-type of 
`ConnectionCredentialVendor` because it is not type-specific.
   
   All calls are made via the `PolarisCredentialManager` interface.
   
   WDYT about detaching `PolarisCredentialManager` from 
`ConnectionCredentialVendor` but keeping current 
`DefaultPolarisCredentialManager` code?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to