comphead commented on code in PR #7680:
URL: https://github.com/apache/datafusion-comet/pull/7680#discussion_r4637038976


##########
docs/source/user-guide/latest/iceberg.md:
##########
@@ -571,6 +571,12 @@ carries the catalog's `hadoop.*` overrides. Also gated 
explicitly: any `encrypti
 `write.object-storage.enabled=true`, and `write.location-provider.impl`. An 
`io-impl` table
 property is ignored, because iceberg-java reads `io-impl` from catalog 
properties only.
 
+With `S3FileIO`, `client.factory` is admitted only as 
`org.apache.iceberg.aws.AssumeRoleAwsClientFactory`
+with `client.assume-role.arn` and `client.assume-role.region` set, and that 
region becomes the write
+region. The write falls back when the factory is combined with a different 
`client.region` or
+`s3.region`, static S3 keys, a credential-provider class, or 
`s3.allow-anonymous`,
+`s3.disable-ec2-metadata` or `s3.disable-config-load` set to `true`.

Review Comment:
   Two observable differences from the factory are not listed. First, 
iceberg-java names the session `iceberg-aws-<uuid>` when 
`client.assume-role.session-name` is unset 
(`AssumeRoleAwsClientFactory.genSessionName`), while opendal/reqsign sends 
`reqsign` (your CloudTrail output shows it). A trust policy with an 
`sts:RoleSessionName` condition that works for the JVM writer will deny the 
native one, and the query fails instead of falling back. Second, the native STS 
call goes to the regional endpoint of `client.assume-role.region`, whereas the 
factory's STS client takes its region from the default provider chain (`sts()` 
sets none). I expect this matters only with a restricted STS route, but I have 
not tested it. Please add both to the accepted divergences, or decline when a 
trust-policy-sensitive setup cannot be ruled out.



##########
spark/src/main/scala/org/apache/comet/serde/operator/CometIcebergNativeWrite.scala:
##########
@@ -1093,8 +1147,19 @@ object CometIcebergNativeWrite extends 
CometOperatorSerde[IcebergWriteExec] {
     }
 
   private val requireSupportedS3FileIOProperties: TriggerRule = ctx =>
-    s3DataLocation(ctx).flatMap { _ =>
-      unsupportedSettingsReason("S3 FileIO", 
unsupportedS3FileIOProperties(ctx.fileIOProperties))
+    s3DataLocation(ctx).flatMap { location =>
+      // Resolving a ResolvingFileIO's delegate instantiates it.
+      lazy val s3FileIO = IcebergReflection
+        .getFileIO(ctx.table)
+        .flatMap(io => IcebergReflection.resolveFileIOClass(io, location))
+        .exists(cls =>
+          IcebergReflection
+            .classNameInHierarchy(cls, 
Set(IcebergReflection.ClassNames.S3_FILE_IO)))
+      unsupportedSettingsReason(
+        "S3 FileIO",
+        unsupportedS3FileIOProperties(
+          ctx.fileIOProperties,
+          ctx.fileIOProperties.contains(S3FileIOClientFactoryProperty) && 
s3FileIO))

Review Comment:
   The rule that decides `s3FileIO` is not covered. The new tests call 
`unsupportedS3FileIOProperties(..., s3FileIO = true/false)` directly, so the 
`HadoopFileIO` fallback test only proves a boolean parameter, not that a 
`ResolvingFileIO` resolving to `HadoopFileIO`, a failed `resolveFileIOClass`, 
or an `S3FileIO` subclass lands on the right side. `gcsDataLocationRejection` 
takes the resolved `Option[Class[_]]` for this reason. Consider the same shape 
here so a test can feed `S3FileIO`, `HadoopFileIO` and `None`. Also note 
`classNameInHierarchy` admits any subclass of `S3FileIO`, which can override 
client creation and ignore the factory. An exact class match would fail closed.



##########
spark/src/main/scala/org/apache/comet/serde/operator/CometIcebergNativeWrite.scala:
##########
@@ -1054,21 +1066,35 @@ object CometIcebergNativeWrite extends 
CometOperatorSerde[IcebergWriteExec] {
       .toMap + (CometS3CredentialProviderClassProperty -> 
HadoopS3ACredentialAdapterClass)
 
   /** Return unsupported FileIO S3/client property names in deterministic 
order. */
-  private[comet] def unsupportedS3FileIOProperties(properties: Map[String, 
String]): Seq[String] =
-    unsupportedS3FileIOProperties(properties, IcebergAwsProperties)
+  private[comet] def unsupportedS3FileIOProperties(
+      properties: Map[String, String],
+      s3FileIO: Boolean = false): Seq[String] =
+    unsupportedS3FileIOProperties(properties, IcebergAwsProperties, s3FileIO)
 
   private[comet] def unsupportedS3FileIOProperties(
       properties: Map[String, String],
-      icebergAwsProperties: IcebergAwsPropertyNames): Seq[String] = {
+      icebergAwsProperties: IcebergAwsPropertyNames,
+      s3FileIO: Boolean): Seq[String] = {
     val customCredentialProviderConfigured = properties
       .get(CometS3CredentialProviderClassProperty)
       .exists(_.trim.nonEmpty)
 
+    val assumeRole = usesAssumeRoleClientFactory(properties)

Review Comment:
   Without `client.factory`, iceberg-java ignores `client.assume-role.*` 
(`AwsClientFactories.from` defaults to `DefaultAwsClientFactory`, and a 
`HadoopFileIO` write goes through S3A). But `client.assume-role.arn`, 
`external-id` and `session-name` are in `SupportedS3FileIOProperties` 
unconditionally, and the test at `unsupported(assumeRole - "client.factory") == 
Seq("client.assume-role.region")` shows that an ARN without the factory is 
still admitted when no region is set. The native writer then assumes the role 
while the JVM writer would have used the default credentials, so the write 
happens under a different identity. This predates the PR, but the PR 
description states the rule and this is the place to enforce it. Consider 
declining the ARN, external id and session name unless `assumeRole` holds and 
the FileIO is `S3FileIO`.



##########
spark/src/main/scala/org/apache/comet/serde/operator/CometIcebergNativeWrite.scala:
##########
@@ -1079,9 +1105,37 @@ object CometIcebergNativeWrite extends 
CometOperatorSerde[IcebergWriteExec] {
       }
       .map(_._1)
       .toSeq
+      .++(assumeRoleConflicts)
+      .distinct
       .sorted
   }
 
+  private def assumeRoleConflictingProperties(properties: Map[String, 
String]): Seq[String] = {
+    val region = properties(AssumeRoleRegionProperty)
+    Seq(CometS3CredentialProviderClassProperty).filter(
+      properties.get(_).exists(_.trim.nonEmpty)) ++
+      NativeS3RegionProperties.filter(properties.get(_).exists(_ != region)) ++
+      AssumeRoleConflictingCredentialProperties.filter(properties.contains) ++
+      AssumeRoleConflictingCredentialFlags.filter(
+        properties.get(_).exists(java.lang.Boolean.parseBoolean))

Review Comment:
   `Boolean.parseBoolean` only accepts `true`, but the pinned iceberg-rust 
reads these three flags with `is_truthy` (`crates/storage/opendal/src/s3.rs` 
and `utils.rs` at `de0a6ac`), which accepts `true`, `t`, `1` and `on` 
case-insensitively. So `s3.allow-anonymous=1`, `s3.disable-config-load=on` or 
`s3.disable-ec2-metadata=t` pass this check, iceberg-java reads them as false, 
and the native writer then skips signing or drops the env/IMDS credential 
sources that AssumeRole needs as its source. The write fails in the task 
instead of falling back. Please use the same truthiness as iceberg-rust here 
and add those spellings to the test, which only uses `true`.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to