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


##########
polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsSessionTagsBuilder.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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.storage.aws;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.polaris.core.auth.PolarisPrincipal;
+import org.apache.polaris.core.storage.CredentialVendingContext;
+import software.amazon.awssdk.services.sts.model.Tag;
+
+/**
+ * Utility class for building AWS STS session tags from credential vending 
context. These tags
+ * appear in CloudTrail events for correlation between catalog operations and 
S3 data access.
+ */
+public final class AwsSessionTagsBuilder {
+
+  // AWS limit for session tag values
+  static final int MAX_TAG_VALUE_LENGTH = 256;
+
+  /** Placeholder value used when a tag value is null or empty. */
+  static final String TAG_VALUE_UNKNOWN = "unknown";
+
+  private AwsSessionTagsBuilder() {
+    // Utility class - prevent instantiation
+  }
+
+  /**
+   * Builds a list of AWS STS session tags from the principal and credential 
vending context. These
+   * tags will appear in CloudTrail events for correlation purposes.
+   *
+   * @param principal the principal requesting credentials (provides name and 
activated roles)
+   * @param context the credential vending context containing catalog, 
namespace, and table
+   * @return a list of STS Tags to attach to the AssumeRole request
+   */
+  public static List<Tag> buildSessionTags(
+      PolarisPrincipal principal, CredentialVendingContext context) {
+    List<Tag> tags = new ArrayList<>();
+
+    // Extract principal name and roles
+    String principalName = principal.getName();
+    Set<String> roles = principal.getRoles();

Review Comment:
   This makes `StorageAccessConfig` caching more obscure and potentially 
incorrect. As discussed in #3339 , the cache currently uses only the principal 
name as part of the key, so any changes in principal roles under the same name 
could result in false positive cache hits. False in the sense that the previous 
config with a credential session having old roles in the tags can be reused, 
which the principal's roles are different at access time.
   
   All in all, this is a complex problem to fix in the current Polaris 
codebase. I believe it is best tackled in a dedicated PR.
   
   For this PR, I'd propose to only use attributes that are covered by the 
storage credential's cache 
[key](https://github.com/apache/polaris/blob/27ae684304c6c62e5ee516404eee1419bc5d67f8/polaris-core/src/main/java/org/apache/polaris/core/storage/cache/StorageCredentialCache.java#L126).



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