-
Notifications
You must be signed in to change notification settings - Fork 9.2k
[HADOOP-18562]: S3A: support custom S3 and STS headers. #6550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
066036b
c8168fd
cfe1f7c
7f58d07
917e214
e8ed19a
626d8b0
47baf34
4b26b50
0fba78f
d364ac4
6741625
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -775,6 +775,29 @@ private Constants() { | |
| "fs.s3a." + Constants.AWS_SERVICE_IDENTIFIER_STS.toLowerCase() | ||
| + ".signing-algorithm"; | ||
|
|
||
| /** Prefix for S3A client-specific properties. */ | ||
| public static final String FS_S3A_CLIENT_PREFIX = "fs.s3a.client."; | ||
|
|
||
| /** Custom headers postfix. */ | ||
| public static final String CUSTOM_HEADERS_POSTFIX = ".custom.headers"; | ||
|
|
||
| /** | ||
| * List of custom headers to be set on the service client. | ||
| * Multiple parameters can be used to specify custom headers. | ||
| * fs.s3a.client.s3.custom.headers - headers to add on all the s3 requests. | ||
| * fs.s3a.client.sts.custom.headers - headers to add on all the sts requests. | ||
| * Examples | ||
| * CustomHeader {@literal ->} 'Header1:Value1' | ||
| * CustomHeaders {@literal ->} 'Header1=Value1:Value2,Header2=Value1' | ||
| */ | ||
| public static final String CUSTOM_HEADERS_STS = | ||
| FS_S3A_CLIENT_PREFIX + Constants.AWS_SERVICE_IDENTIFIER_STS.toLowerCase() | ||
|
||
| + CUSTOM_HEADERS_POSTFIX; | ||
|
|
||
| public static final String CUSTOM_HEADERS_S3 = | ||
| FS_S3A_CLIENT_PREFIX + Constants.AWS_SERVICE_IDENTIFIER_S3.toLowerCase() | ||
| + CUSTOM_HEADERS_POSTFIX; | ||
|
|
||
| public static final String S3N_FOLDER_SUFFIX = "_$folder$"; | ||
| public static final String FS_S3A_BLOCK_SIZE = "fs.s3a.block.size"; | ||
| public static final String FS_S3A = "s3a"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,9 @@ | |
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.time.Duration; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.slf4j.Logger; | ||
|
|
@@ -72,6 +75,8 @@ | |
| import static org.apache.hadoop.fs.s3a.Constants.SIGNING_ALGORITHM_STS; | ||
| import static org.apache.hadoop.fs.s3a.Constants.SOCKET_TIMEOUT; | ||
| import static org.apache.hadoop.fs.s3a.Constants.USER_AGENT_PREFIX; | ||
| import static org.apache.hadoop.fs.s3a.Constants.CUSTOM_HEADERS_S3; | ||
| import static org.apache.hadoop.fs.s3a.Constants.CUSTOM_HEADERS_STS; | ||
| import static org.apache.hadoop.fs.s3a.impl.ConfigurationHelper.enforceMinimumDuration; | ||
| import static org.apache.hadoop.fs.s3a.impl.ConfigurationHelper.getDuration; | ||
| import static org.apache.hadoop.util.Preconditions.checkArgument; | ||
|
|
@@ -116,6 +121,8 @@ public static ClientOverrideConfiguration.Builder createClientConfigBuilder(Conf | |
|
|
||
| initUserAgent(conf, overrideConfigBuilder); | ||
|
|
||
| initRequestHeaders(conf, overrideConfigBuilder, awsServiceIdentifier); | ||
|
|
||
| String signer = conf.getTrimmed(SIGNING_ALGORITHM, ""); | ||
| if (!signer.isEmpty()) { | ||
| LOG.debug("Signer override = {}", signer); | ||
|
|
@@ -407,6 +414,36 @@ private static void initSigner(Configuration conf, | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * | ||
|
||
| * @param conf hadoop configuration | ||
| * @param clientConfig client configuration to update | ||
| * @param awsServiceIdentifier service name | ||
| */ | ||
| private static void initRequestHeaders(Configuration conf, | ||
| ClientOverrideConfiguration.Builder clientConfig, String awsServiceIdentifier) { | ||
| String configKey = null; | ||
| switch (awsServiceIdentifier) { | ||
| case AWS_SERVICE_IDENTIFIER_S3: | ||
| configKey = CUSTOM_HEADERS_S3; | ||
| break; | ||
| case AWS_SERVICE_IDENTIFIER_STS: | ||
| configKey = CUSTOM_HEADERS_STS; | ||
| break; | ||
| default: | ||
| // Nothing to do. The original signer override is already setup | ||
|
||
| } | ||
| if (configKey != null) { | ||
| Map<String, String> awsClientCustomHeadersMap = | ||
| S3AUtils.getTrimmedStringCollectionSplitByEquals(conf, configKey); | ||
| awsClientCustomHeadersMap.forEach((header, valueString) -> { | ||
| List<String> headerValues = Arrays.asList(valueString.split(":")); | ||
steveloughran marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| clientConfig.putHeader(header, headerValues); | ||
| }); | ||
| LOG.debug("headers for {} client = {}", awsServiceIdentifier, clientConfig.headers()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Configures request timeout in the client configuration. | ||
| * This is independent of the timeouts set in the sync and async HTTP clients; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add an {@value} tag for this and the strings below, for better IDE experience