Skip to content

Commit afc077d

Browse files
committed
restrict encryption client imports
1 parent ef3534e commit afc077d

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

hadoop-tools/hadoop-aws/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,16 @@
464464
<bannedImport>org.apache.hadoop.mapred.**</bannedImport>
465465
</bannedImports>
466466
</restrictImports>
467+
<restrictImports>
468+
<includeTestCode>false</includeTestCode>
469+
<reason>Restrict encryption client imports to encryption client factory</reason>
470+
<exclusions>
471+
<exclusion>org.apache.hadoop.fs.s3a.EncryptionS3ClientFactory</exclusion>
472+
</exclusions>
473+
<bannedImports>
474+
<bannedImport>software.amazon.encryption.s3.**</bannedImport>
475+
</bannedImports>
476+
</restrictImports>
467477
</rules>
468478
</configuration>
469479
</execution>

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import software.amazon.awssdk.core.retry.RetryUtils;
2525
import software.amazon.awssdk.services.s3.model.S3Exception;
2626
import software.amazon.awssdk.services.s3.model.S3Object;
27-
import software.amazon.encryption.s3.S3EncryptionClientException;
2827

2928
import org.apache.commons.lang3.StringUtils;
3029
import org.apache.hadoop.classification.InterfaceAudience;
@@ -76,6 +75,7 @@
7675
import static org.apache.hadoop.fs.s3a.Constants.*;
7776
import static org.apache.hadoop.fs.s3a.audit.AuditIntegration.maybeTranslateAuditException;
7877
import static org.apache.hadoop.fs.s3a.impl.ErrorTranslation.isUnknownBucket;
78+
import static org.apache.hadoop.fs.s3a.impl.ErrorTranslation.maybeExtractSdkException;
7979
import static org.apache.hadoop.fs.s3a.impl.InstantiationIOException.instantiationException;
8080
import static org.apache.hadoop.fs.s3a.impl.InstantiationIOException.isAbstract;
8181
import static org.apache.hadoop.fs.s3a.impl.InstantiationIOException.isNotInstanceOf;
@@ -173,13 +173,7 @@ public static IOException translateException(@Nullable String operation,
173173
StringUtils.isNotEmpty(path)? (" on " + path) : "",
174174
exception);
175175

176-
// Exceptions from encryption client are wrapped in S3EncryptionClientException, so unwrap.
177-
if (exception instanceof S3EncryptionClientException) {
178-
exception = (SdkException) exception.getCause();
179-
if (exception != null && exception.getCause() instanceof AwsServiceException) {
180-
exception = (SdkException) exception.getCause();
181-
}
182-
}
176+
exception = maybeExtractSdkException(exception);
183177

184178
if (!(exception instanceof AwsServiceException)) {
185179
// exceptions raised client-side: connectivity, auth, network problems...

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/AWSClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
import software.amazon.awssdk.http.apache.ApacheHttpClient;
3333
import software.amazon.awssdk.http.apache.ProxyConfiguration;
3434
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
35-
import software.amazon.awssdk.thirdparty.org.apache.http.client.utils.URIBuilder;
3635

3736
import org.apache.hadoop.conf.Configuration;
3837
import org.apache.hadoop.fs.s3a.S3AUtils;
3938
import org.apache.hadoop.fs.s3a.auth.SignerFactory;
4039
import org.apache.hadoop.util.VersionInfo;
40+
import org.apache.http.client.utils.URIBuilder;
4141

4242
import static org.apache.hadoop.fs.s3a.Constants.AWS_SERVICE_IDENTIFIER_S3;
4343
import static org.apache.hadoop.fs.s3a.Constants.AWS_SERVICE_IDENTIFIER_STS;

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/ErrorTranslation.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.reflect.Constructor;
2323

2424
import software.amazon.awssdk.awscore.exception.AwsServiceException;
25+
import software.amazon.awssdk.core.exception.SdkException;
2526

2627
import org.apache.hadoop.fs.PathIOException;
2728

@@ -48,6 +49,9 @@ public final class ErrorTranslation {
4849
private ErrorTranslation() {
4950
}
5051

52+
static final String ENCRYPTION_CLIENT_EXCEPTION =
53+
"software.amazon.encryption.s3.S3EncryptionClientException";
54+
5155
/**
5256
* Does this exception indicate that the AWS Bucket was unknown.
5357
* @param e exception.
@@ -106,6 +110,19 @@ public static IOException maybeExtractIOException(String path, Throwable thrown)
106110

107111
}
108112

113+
public static SdkException maybeExtractSdkException(SdkException exception) {
114+
SdkException extractedException = exception;
115+
if (exception.toString().contains(ENCRYPTION_CLIENT_EXCEPTION)) {
116+
extractedException = (SdkException) exception.getCause();
117+
if (extractedException != null
118+
&& extractedException.getCause() instanceof AwsServiceException) {
119+
extractedException = (SdkException) extractedException.getCause();
120+
}
121+
}
122+
123+
return extractedException;
124+
}
125+
109126
/**
110127
* Given an outer and an inner exception, create a new IOE
111128
* of the inner type, with the outer exception as the cause.

0 commit comments

Comments
 (0)