Copilot commented on code in PR #11853: URL: https://github.com/apache/gravitino/pull/11853#discussion_r3543830260
########## iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/credential/IcebergServerCredentialUtils.java: ########## @@ -0,0 +1,112 @@ +/* + * 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.gravitino.iceberg.common.credential; + +import java.util.HashMap; +import java.util.Map; +import org.apache.gravitino.credential.AwsIrsaCredential; +import org.apache.gravitino.credential.Credential; +import org.apache.gravitino.credential.CredentialPropertyUtils; +import org.apache.gravitino.credential.S3TokenCredential; + +/** Utilities for applying Gravitino credentials to server-side Iceberg catalog properties. */ +public final class IcebergServerCredentialUtils { + + /** Iceberg property that names an AWS SDK v2 credentials provider class. */ + public static final String CLIENT_CREDENTIALS_PROVIDER = "client.credentials-provider"; + + /** Prefix stripped by Iceberg before passing properties to the credentials provider. */ + public static final String CLIENT_CREDENTIALS_PROVIDER_PREFIX = "client.credentials-provider."; + + private static final String ICEBERG_S3_ACCESS_KEY_ID = "s3.access-key-id"; + private static final String ICEBERG_S3_SECRET_ACCESS_KEY = "s3.secret-access-key"; + private static final String ICEBERG_S3_SESSION_TOKEN = "s3.session-token"; + private static final String ICEBERG_S3_SESSION_TOKEN_EXPIRES_AT_MS = + "s3.session-token-expires-at-ms"; + + /** + * Applies credentials to Iceberg catalog properties. + * + * <p>Expiring S3 credentials are represented by a refreshable AWS SDK credentials provider; + * non-expiring and non-S3 credentials are converted to regular Iceberg properties. + * + * @param catalogName catalog name + * @param credentials credentials to apply + * @param credentialProviderProperties properties passed to the refreshable provider + * @param targetProperties mutable Iceberg catalog properties + */ + public static void applyCredentials( + String catalogName, + Credential[] credentials, + Map<String, String> credentialProviderProperties, + Map<String, String> targetProperties) { + Map<String, String> effectiveProviderProperties = new HashMap<>(); + if (credentialProviderProperties != null) { + effectiveProviderProperties.putAll(credentialProviderProperties); + } + effectiveProviderProperties.put( + GravitinoIcebergAwsCredentialsProvider.CATALOG_NAME, catalogName); + effectiveProviderProperties.putIfAbsent( + GravitinoIcebergAwsCredentialsProvider.SOURCE, + GravitinoIcebergAwsCredentialsProvider.SOURCE_LOCAL); + + for (Credential credential : credentials) { + if (isExpiringS3Credential(credential)) { + configureRefreshableAwsProvider(effectiveProviderProperties, targetProperties); + } else { + CredentialPropertyUtils.applyIcebergCredentials( + new Credential[] {credential}, targetProperties); + } + } + } Review Comment: `applyCredentials` configures the refreshable AWS provider inside the per-credential loop. If the credentials array contains both an expiring S3 credential (AwsIrsa/S3Token) and a non-expiring S3 credential (e.g., S3SecretKeyCredential), the later `applyIcebergCredentials` call can re-introduce `s3.*` keys after they were removed, leaving both static keys and `client.credentials-provider` set. This can cause Iceberg to use the wrong credentials source and defeats the intent of using a refreshable provider. Configure the refreshable provider once (after applying non-expiring/non-S3 credentials) when any expiring S3 credential is present, and skip applying expiring S3 credentials as static properties. -- 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]
