-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
[HADOOP-18562]: S3A: support custom S3 and STS headers. #6550
Open
PradhanPrerak
wants to merge
12
commits into
apache:trunk
Choose a base branch
from
PradhanPrerak:trunk
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+132
−0
Open
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
066036b
[SPARK-38958]: Override S3 Client in Spark Write/Read calls
PradhanPrerak39 c8168fd
Merge branch 'apache:trunk' into trunk
PradhanPrerak cfe1f7c
Merge branch 'apache:trunk' into trunk
PradhanPrerak 7f58d07
Merge branch 'apache:trunk' into trunk
PradhanPrerak 917e214
address comments
PradhanPrerak e8ed19a
Merge branch 'apache:trunk' into trunk
PradhanPrerak 626d8b0
address comments
PradhanPrerak 47baf34
renames variable
PradhanPrerak 4b26b50
retrigger checks
PradhanPrerak 0fba78f
check style fixes
PradhanPrerak d364ac4
Merge branch 'apache:trunk' into trunk
PradhanPrerak 6741625
change delimiter to semicolon (;) and adress comments
PradhanPrerak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
+ 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"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
} | ||
} | ||
|
||
/** | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need a title here |
||
* @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.
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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