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


##########
runtime/service/src/main/java/org/apache/polaris/service/identity/provider/DefaultServiceIdentityProvider.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.identity.provider;
+
+import com.google.common.annotations.VisibleForTesting;
+import jakarta.annotation.Nonnull;
+import jakarta.inject.Inject;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.polaris.core.admin.model.AuthenticationParameters;
+import org.apache.polaris.core.admin.model.ConnectionConfigInfo;
+import org.apache.polaris.core.admin.model.ServiceIdentityInfo;
+import org.apache.polaris.core.context.RealmContext;
+import org.apache.polaris.core.identity.ServiceIdentityType;
+import org.apache.polaris.core.identity.credential.ServiceIdentityCredential;
+import org.apache.polaris.core.identity.dpo.AwsIamServiceIdentityInfoDpo;
+import org.apache.polaris.core.identity.dpo.ServiceIdentityInfoDpo;
+import org.apache.polaris.core.identity.provider.ServiceIdentityProvider;
+import org.apache.polaris.core.secrets.SecretReference;
+import org.apache.polaris.service.identity.RealmServiceIdentityConfiguration;
+import 
org.apache.polaris.service.identity.ResolvableServiceIdentityConfiguration;
+import org.apache.polaris.service.identity.ServiceIdentityConfiguration;
+
+/**
+ * Default implementation of {@link ServiceIdentityProvider} that provides 
service identity
+ * credentials from statically configured values.
+ *
+ * <p>This implementation loads service identity configurations at startup and 
uses them to provide
+ * identity information and credentials on demand. All resolution is done 
lazily - credentials are
+ * only created when actually needed for authentication.
+ */
+public class DefaultServiceIdentityProvider implements ServiceIdentityProvider 
{
+  public static final String DEFAULT_REALM_KEY = 
ServiceIdentityConfiguration.DEFAULT_REALM_KEY;
+  public static final String DEFAULT_REALM_NSS = "system:default";
+  private static final String IDENTITY_INFO_REFERENCE_URN_FORMAT =
+      "urn:polaris-secret:default-identity-provider:%s:%s";
+
+  private final String realm;
+  private final RealmServiceIdentityConfiguration config;
+
+  public DefaultServiceIdentityProvider() {
+    this.realm = DEFAULT_REALM_KEY;
+    this.config = null;
+  }
+
+  @Inject
+  public DefaultServiceIdentityProvider(
+      RealmContext realmContext, ServiceIdentityConfiguration 
serviceIdentityConfiguration) {
+    ServiceIdentityConfiguration.RealmConfigEntry entry =
+        serviceIdentityConfiguration.forRealm(realmContext);
+    this.realm = entry.realm();
+    this.config = entry.config();
+  }
+
+  @Override
+  public Optional<ServiceIdentityInfoDpo> allocateServiceIdentity(
+      @Nonnull ConnectionConfigInfo connectionConfig) {
+    if (config == null || connectionConfig.getAuthenticationParameters() == 
null) {
+      return Optional.empty();
+    }
+
+    AuthenticationParameters.AuthenticationTypeEnum authType =
+        connectionConfig.getAuthenticationParameters().getAuthenticationType();
+
+    // Map authentication type to service identity type and check if configured
+    return switch (authType) {
+      case SIGV4 ->
+          config.awsIamServiceIdentity().isPresent()
+              ? Optional.of(
+                  new AwsIamServiceIdentityInfoDpo(
+                      buildIdentityInfoReference(realm, 
ServiceIdentityType.AWS_IAM)))
+              : Optional.empty();
+      default -> Optional.empty();
+    };
+  }
+
+  @Override
+  public Optional<ServiceIdentityInfo> getServiceIdentityInfo(
+      @Nonnull ServiceIdentityInfoDpo serviceIdentityInfo) {
+    if (config == null) {
+      return Optional.empty();
+    }
+
+    // Find the configuration matching the reference and return metadata only
+    SecretReference actualRef = serviceIdentityInfo.getIdentityInfoReference();
+
+    return config.serviceIdentityConfigurations().stream()
+        .filter(
+            identityConfig ->
+                buildIdentityInfoReference(realm, 
identityConfig.getType()).equals(actualRef))

Review Comment:
   So we're effectively using `SecretReference` as an identifier for service 
identities.
   
   I think it is ok for now, but it feels like an unnecessary binding. I 
suppose in general, identities do not have to be 1:1 with secrets.
   
   I'm ok continuing with current code for now, but it may be necessary to 
refactor that at some point (but I do not have a concrete use case yet).



##########
polaris-core/src/main/java/org/apache/polaris/core/connection/ConnectionConfigInfoDpo.java:
##########


Review Comment:
   nit: `correponding` -> `corresponding`?



##########
polaris-core/src/main/java/org/apache/polaris/core/identity/dpo/ServiceIdentityInfoDpo.java:
##########
@@ -72,10 +74,25 @@ public SecretReference getIdentityInfoReference() {
   }
 
   /**
-   * Converts this persistence object to the corresponding API model. During 
the conversion, some
-   * fields will be dropped, e.g. the reference to the service identity's 
credential
+   * Converts this persistence object to the corresponding API model.
+   *
+   * <p>The conversion uses the provided {@link ServiceIdentityProvider} to 
retrieve the user-facing
+   * identity information (e.g., AWS IAM ARN) without exposing sensitive 
credentials. The credential
+   * reference stored in this DPO is not included in the API model.
+   *
+   * @param serviceIdentityProvider the service identity provider used to 
retrieve display
+   *     information
+   * @return the API model representation, or null if the provider is null or 
cannot resolve the
+   *     identity
    */
-  public abstract @Nonnull ServiceIdentityInfo asServiceIdentityInfoModel();
+  public @Nullable ServiceIdentityInfo asServiceIdentityInfoModel(
+      ServiceIdentityProvider serviceIdentityProvider) {
+    if (serviceIdentityProvider == null) {

Review Comment:
   if `serviceIdentityProvider` is `null`, why would the caller even call this 
method?
   
   Currently `serviceIdentityProvider` is ultimately injected, so it should not 
be `null`, right?



##########
polaris-core/src/main/java/org/apache/polaris/core/entity/CatalogEntity.java:
##########
@@ -108,6 +110,10 @@ public static CatalogEntity fromCatalog(RealmConfig 
realmConfig, Catalog catalog
   }
 
   public Catalog asCatalog() {

Review Comment:
   This method is not called in Apache Polaris code. Should be deprecate it?



##########
polaris-core/src/main/java/org/apache/polaris/core/identity/credential/ServiceIdentityCredential.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.identity.credential;
+
+import jakarta.annotation.Nonnull;
+import jakarta.annotation.Nullable;
+import org.apache.polaris.core.admin.model.ServiceIdentityInfo;
+import org.apache.polaris.core.identity.ServiceIdentityType;
+import org.apache.polaris.core.identity.dpo.ServiceIdentityInfoDpo;
+import org.apache.polaris.core.secrets.SecretReference;
+import software.amazon.awssdk.annotations.NotNull;
+
+/**
+ * Represents a service identity credential used by Polaris to authenticate to 
external systems.
+ *
+ * <p>This class encapsulates both the service identity metadata (e.g., AWS 
IAM ARN) and the
+ * associated credentials (e.g., AWS access keys) needed to authenticate as 
the Polaris service when
+ * accessing external catalog services.
+ *
+ * <p>The credential contains:
+ *
+ * <ul>
+ *   <li>Identity type (e.g., AWS_IAM)
+ *   <li>A {@link SecretReference} pointing to where the credential 
configuration is stored
+ *   <li>The actual authentication credentials (implementation-specific, e.g.,
+ *       AwsCredentialsProvider)
+ * </ul>
+ */
+public abstract class ServiceIdentityCredential {
+  private final ServiceIdentityType identityType;
+  private SecretReference identityInfoReference;

Review Comment:
   nit: naming is a bit skewed in code and javadoc. Here we have "identity 
reference", javadoc says "pointing to where the credential configuration is 
stored". This is related to my other comment about reusing `SecretReference` as 
the identifier for the identity object instance, but could we make it explicit 
in javadoc to avoid confusion?



##########
runtime/service/src/main/java/org/apache/polaris/service/identity/provider/DefaultServiceIdentityProvider.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * 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.identity.provider;
+
+import com.google.common.annotations.VisibleForTesting;
+import jakarta.annotation.Nonnull;
+import jakarta.inject.Inject;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.polaris.core.admin.model.AuthenticationParameters;
+import org.apache.polaris.core.admin.model.ConnectionConfigInfo;
+import org.apache.polaris.core.admin.model.ServiceIdentityInfo;
+import org.apache.polaris.core.context.RealmContext;
+import org.apache.polaris.core.identity.ServiceIdentityType;
+import org.apache.polaris.core.identity.credential.ServiceIdentityCredential;
+import org.apache.polaris.core.identity.dpo.AwsIamServiceIdentityInfoDpo;
+import org.apache.polaris.core.identity.dpo.ServiceIdentityInfoDpo;
+import org.apache.polaris.core.identity.provider.ServiceIdentityProvider;
+import org.apache.polaris.core.secrets.SecretReference;
+import org.apache.polaris.service.identity.RealmServiceIdentityConfiguration;
+import 
org.apache.polaris.service.identity.ResolvableServiceIdentityConfiguration;
+import org.apache.polaris.service.identity.ServiceIdentityConfiguration;
+
+/**
+ * Default implementation of {@link ServiceIdentityProvider} that provides 
service identity
+ * credentials from statically configured values.
+ *
+ * <p>This implementation loads service identity configurations at startup and 
uses them to provide
+ * identity information and credentials on demand. All resolution is done 
lazily - credentials are
+ * only created when actually needed for authentication.
+ */
+public class DefaultServiceIdentityProvider implements ServiceIdentityProvider 
{
+  public static final String DEFAULT_REALM_KEY = 
ServiceIdentityConfiguration.DEFAULT_REALM_KEY;
+  public static final String DEFAULT_REALM_NSS = "system:default";
+  private static final String IDENTITY_INFO_REFERENCE_URN_FORMAT =
+      "urn:polaris-secret:default-identity-provider:%s:%s";
+
+  private final String realm;
+  private final RealmServiceIdentityConfiguration config;
+
+  public DefaultServiceIdentityProvider() {
+    this.realm = DEFAULT_REALM_KEY;
+    this.config = null;
+  }
+
+  @Inject

Review Comment:
   Do we need this annotation? This bean has a producer method in 
`ServiceProducers` and does not have a scope annotation... I believe this 
`@Inject` is useless.
   
   Did you mean to put `@RequestScoped` on this class and remove the trivial 
producer method?
   
   I know current codebase has a mix of these approaches (which is ok). My 
personal preference is slightly in favour of putting `@RequestScoped` on bean 
classes (unless the producer has non-trivial logic). This is optional (but if 
not going this way, then we probably need to remove this `@Inject` to avoid 
confusion).



##########
runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java:
##########
@@ -672,6 +681,11 @@ private Map<String, SecretReference> 
extractSecretReferences(
                   
AuthenticationParametersDpo.INLINE_BEARER_TOKEN_REFERENCE_KEY, secretReference);
               break;
             }
+          case SIGV4:
+            {
+              // SigV4 authentication is not secret-based

Review Comment:
   Did you mean it's based on service identity? (which can be associated with a 
secret)



##########
runtime/defaults/src/main/resources/application.properties:
##########
@@ -197,6 +197,19 @@ polaris.oidc.principal-roles-mapper.type=default
 # polaris.storage.gcp.token=token
 # polaris.storage.gcp.lifespan=PT1H
 
+# Polaris Service Identity Config

Review Comment:
   nit: this feature does not seem to be ready for end-users yet, so it might 
be preferable to avoid adding (commented out) config examples at this time. 
Advanced users can probably figure it out anyway from code and previous config 
entries.



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