-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-16445. Allow separate custom signing algorithms for S3 and DDB #1332
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
586cff1
HADOOP-16445. Allow separate custom signing algorithms for S3 and DDB
sidseth 38a3f36
Incorporated review comments, and other changes.
sidseth 52d44c2
Checkstyle fixes.
sidseth 3fbe3b0
Removed deprecation warnings
sidseth d1ba60e
re-ordered imports
sidseth 007360f
More import order fixes
sidseth 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 hidden or 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 |
|---|---|---|
|
|
@@ -343,9 +343,43 @@ private Constants() { | |
| public static final String SERVER_SIDE_ENCRYPTION_KEY = | ||
| "fs.s3a.server-side-encryption.key"; | ||
|
|
||
| //override signature algorithm used for signing requests | ||
| /** | ||
| * List of custom Signers. The signer class will be loaded, and the signer | ||
| * name will be associated with this signer class in the S3 SDK. e.g. Single | ||
| * CustomSigner -> 'CustomSigner:org.apache...CustomSignerClass Multiple | ||
| * CustomSigners -> 'CSigner1:CustomSignerClass1,CSigner2:CustomerSignerClass2 | ||
| */ | ||
| public static final String CUSTOM_SIGNERS = "fs.s3a.custom.signers"; | ||
|
|
||
| /** | ||
| * There's 3 parameters that can be used to specify a non-default signing | ||
| * algorithm. fs.s3a.signing-algorithm - This property has existed for the | ||
| * longest time. If specified, without either of the other 2 properties being | ||
| * specified, this signing algorithm will be used for S3 and DDB (S3Guard). | ||
| * The other 2 properties override this value for S3 or DDB. | ||
|
Contributor
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. also: other uses like STS. Maybe say "non S3 requests, such as to DDB (for S3Guard) or to STS." |
||
| * fs.s3a.s3.signing-algorithm - Allows overriding the S3 Signing algorithm. | ||
| * This does not affect DDB. Specifying this property without specifying | ||
| * fs.s3a.signing-algorithm will only update the signing algorithm for S3 | ||
| * requests, and the default will be used for DDB fs.s3a.ddb.signing-algorithm | ||
| * - Allows overriding the DDB Signing algorithm. This does not affect S3. | ||
| * Specifying this property without specifying fs.s3a.signing-algorithm will | ||
| * only update the signing algorithm for DDB requests, and the default will be | ||
| * used for S3 | ||
| */ | ||
| public static final String SIGNING_ALGORITHM = "fs.s3a.signing-algorithm"; | ||
|
|
||
| public static final String SIGNING_ALGORITHM_S3 = | ||
| "fs.s3a." + Constants.AWS_SERVICE_IDENTIFIER_S3.toLowerCase() | ||
| + ".signing-algorithm"; | ||
|
|
||
| public static final String SIGNING_ALGORITHM_DDB = | ||
| "fs.s3a." + Constants.AWS_SERVICE_IDENTIFIER_DDB.toLowerCase() | ||
| + "signing-algorithm"; | ||
|
|
||
| public static final String SIGNING_ALGORITHM_STS = | ||
| "fs.s3a." + Constants.AWS_SERVICE_IDENTIFIER_STS.toLowerCase() | ||
| + "signing-algorithm"; | ||
|
|
||
| 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"; | ||
|
|
@@ -789,4 +823,7 @@ private Constants() { | |
| public static final String S3GUARD_CONSISTENCY_RETRY_INTERVAL_DEFAULT = | ||
| "2s"; | ||
|
|
||
| public static final String AWS_SERVICE_IDENTIFIER_S3 = "S3"; | ||
| public static final String AWS_SERVICE_IDENTIFIER_DDB = "DDB"; | ||
| public static final String AWS_SERVICE_IDENTIFIER_STS = "STS"; | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
99 changes: 99 additions & 0 deletions
99
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/SignerManager.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /* | ||
| * 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.hadoop.fs.s3a; | ||
|
|
||
| import com.amazonaws.auth.Signer; | ||
| import com.amazonaws.auth.SignerFactory; | ||
| import java.io.Closeable; | ||
|
Contributor
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. usual and predictable comments about imports |
||
| import java.io.IOException; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
|
|
||
| import static org.apache.hadoop.fs.s3a.Constants.CUSTOM_SIGNERS; | ||
|
|
||
| /** | ||
| * Class to handle custom signers. | ||
| */ | ||
| public class SignerManager implements Closeable { | ||
|
|
||
| private static final Logger LOG = LoggerFactory | ||
| .getLogger(SignerManager.class); | ||
|
|
||
|
|
||
| public SignerManager() { | ||
| } | ||
|
|
||
| /** | ||
| * Initialize custom signers and register them with the AWS SDK. | ||
| * | ||
| * @param conf Hadoop configuration | ||
| */ | ||
| public void initCustomSigners(Configuration conf) { | ||
| String[] customSigners = conf.getTrimmedStrings(CUSTOM_SIGNERS); | ||
| if (customSigners == null || customSigners.length == 0) { | ||
| // No custom signers specified, nothing to do. | ||
| LOG.debug("No custom signers specified"); | ||
| return; | ||
| } | ||
|
|
||
| for (String customSigner : customSigners) { | ||
| String[] parts = customSigner.split(":"); | ||
| if (parts.length != 2) { | ||
| String message = | ||
| "Invalid format (Expected name:SignerClass) for CustomSigner: [" | ||
| + customSigner | ||
| + "]"; | ||
| LOG.error(message); | ||
| throw new IllegalArgumentException(message); | ||
| } | ||
| maybeRegisterSigner(parts[0], parts[1], conf); | ||
| } | ||
| } | ||
|
|
||
| /* | ||
| * Make sure the signer class is registered once with the AWS SDK | ||
| */ | ||
| private static void maybeRegisterSigner(String signerName, | ||
| String signerClassName, Configuration conf) { | ||
| try { | ||
| SignerFactory.getSignerByTypeAndService(signerName, null); | ||
| } catch (IllegalArgumentException e) { | ||
| // Signer is not registered with the AWS SDK. | ||
| // Load the class and register the signer. | ||
| Class<? extends Signer> clazz = null; | ||
| try { | ||
| clazz = (Class<? extends Signer>) conf.getClassByName(signerClassName); | ||
| } catch (ClassNotFoundException cnfe) { | ||
| throw new RuntimeException(String | ||
| .format("Signer class [%s] not found for signer [%s]", | ||
| signerClassName, signerName), cnfe); | ||
| } | ||
| LOG.debug("Registering Custom Signer - [{}->{}]", signerName, | ||
| clazz.getName()); | ||
| synchronized (SignerManager.class) { | ||
| SignerFactory.registerSigner(signerName, clazz); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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.
you are going to have to add these to the aws docs I'm afraid. This is probably time to start a new "signing" section