-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-16794. S3A reverts KMS encryption to the bucket's default KMS … #1875
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
Closed
Closed
Changes from all commits
Commits
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
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
102 changes: 102 additions & 0 deletions
102
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/EncryptionTestUtils.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,102 @@ | ||
| /* | ||
| * 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 java.io.IOException; | ||
|
|
||
| import com.amazonaws.services.s3.model.ObjectMetadata; | ||
|
|
||
| import org.apache.commons.codec.digest.DigestUtils; | ||
| import org.apache.commons.net.util.Base64; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
|
|
||
| import static org.apache.hadoop.fs.s3a.Constants.SERVER_SIDE_ENCRYPTION_KEY; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNull; | ||
|
|
||
| public final class EncryptionTestUtils { | ||
|
|
||
| /** Private constructor */ | ||
| private EncryptionTestUtils() { | ||
| } | ||
|
|
||
| public static final String AWS_KMS_SSE_ALGORITHM = "aws:kms"; | ||
|
|
||
| public static final String SSE_C_ALGORITHM = "AES256"; | ||
|
|
||
| /** | ||
| * Decodes the SERVER_SIDE_ENCRYPTION_KEY from base64 into an AES key, then | ||
| * gets the md5 of it, then encodes it in base64 so it will match the version | ||
| * that AWS returns to us. | ||
| * | ||
| * @return md5'd base64 encoded representation of the server side encryption | ||
| * key | ||
| */ | ||
| public static String convertKeyToMd5(FileSystem fs) { | ||
| String base64Key = fs.getConf().getTrimmed( | ||
| SERVER_SIDE_ENCRYPTION_KEY | ||
| ); | ||
| byte[] key = Base64.decodeBase64(base64Key); | ||
| byte[] md5 = DigestUtils.md5(key); | ||
| return Base64.encodeBase64String(md5).trim(); | ||
| } | ||
|
|
||
| /** | ||
| * Assert that a path is encrypted with right encryption settings. | ||
| * @param path file path. | ||
| * @param algorithm encryption algorithm. | ||
| * @param kmsKeyArn full kms key. | ||
| */ | ||
| public static void assertEncrypted(S3AFileSystem fs, | ||
| final Path path, | ||
| final S3AEncryptionMethods algorithm, | ||
| final String kmsKeyArn) | ||
| throws IOException { | ||
| ObjectMetadata md = fs.getObjectMetadata(path); | ||
| String details = String.format( | ||
| "file %s with encryption algorithm %s and key %s", | ||
| path, | ||
| md.getSSEAlgorithm(), | ||
| md.getSSEAwsKmsKeyId()); | ||
| switch(algorithm) { | ||
| case SSE_C: | ||
| assertNull("Metadata algorithm should have been null in " | ||
| + details, | ||
| md.getSSEAlgorithm()); | ||
| assertEquals("Wrong SSE-C algorithm in " | ||
| + details, | ||
| SSE_C_ALGORITHM, md.getSSECustomerAlgorithm()); | ||
| String md5Key = convertKeyToMd5(fs); | ||
| assertEquals("getSSECustomerKeyMd5() wrong in " + details, | ||
| md5Key, md.getSSECustomerKeyMd5()); | ||
| break; | ||
| case SSE_KMS: | ||
| assertEquals("Wrong algorithm in " + details, | ||
| AWS_KMS_SSE_ALGORITHM, md.getSSEAlgorithm()); | ||
| assertEquals("Wrong KMS key in " + details, | ||
| kmsKeyArn, | ||
| md.getSSEAwsKmsKeyId()); | ||
| break; | ||
| default: | ||
| assertEquals("AES256", md.getSSEAlgorithm()); | ||
| } | ||
| } | ||
|
|
||
| } |
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.
This does not "removes the encryption settings from the configuration". Could you explain why that is not required in branch-3.2 and/or update the java doc here?
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.
Yes comment is misleading. I had to fix the merge conflict and as removeBaseAndBucketOverrides() was not present earlier I had to delete that line thinking it is not required.
Although I can see the same method is present in S3ATestUtils but with different parameters and it is not used in this test.
@steveloughran Do you also think tests might break here if bucket level conf are set?
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.
it may well
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.
I tried setting the bucket level conf for fs.s3a.bucket.mthakur-data.server-side-encryption.key and some tests for eg. ITestS3AEncryptionSSES3 started failing. I even tried adding the removeBaseAndBucketOverrides call but it doesn't help.
I tried setting then same bucket level conf in apache/trunk as well and the tests are succeeding there.
The reason for test failure is
java.io.IOException: AES256 is enabled but an encryption key was set in fs.s3a.server-side-encryption.key (key of length 76 ending with 8) at org.apache.hadoop.fs.s3a.S3AUtils.getEncryptionAlgorithm(S3AUtils.java:1440) at org.apache.hadoop.fs.s3a.S3AFileSystem.initialize(S3AFileSystem.java:316) at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:3298) at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:476)removeBaseAndBucketOverrides() call essentially removes this parameter not sure how it is getting added in FileSystem initialisation flow again. It is too hard to compare and debug the difference between branch-3.2 and trunk as there are many changes. Any pointers in this regards would be greatly appreciated.
Also could someone please trigger the test based on their configs and share the results. Thanks.
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.
I can reproduce the test failure. I ran the test with
fs.s3a.bucket.BUCKETNAME.server-side-encryption.keyset inauth-keys.xml.I set the S3 bucket default encryption policy as SSE-KMS, and that is not changing the
ITestS3AEncryptionSSES3test failure (as expected). Well, testITestS3AEncryptionWithDefaultS3Settingscould pass then (again, as expected).Uh oh!
There was an error while loading. Please reload this page.
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.
OK, I did some investigation, and the observation is as following:
addConfResource(CONTRACT_XML);function after creating and patching the conf object, see here.addConfResource(CONTRACT_XML);should be considered a tricky unrelated bug, not brought by this patch. Most likely it is fixed by HADOOP-16626 intrunk. Guess that's why we don't see test failures there. I'm wondering howtrunkis not failing this...? Was HADOOP-16626 enough?removeBucketOverrides(), and you have the change inS3AContractnot callingaddConfResource(CONTRACT_XML);, then you can test with this: you add multipletestEncryption()and multipletestEncryptionOverRename()test cases inAbstractTestS3AEncryption(example). Guess what, only one test fail and all others are failing...How interesting? This seems very related to static resource loading when creating S3AFileSystem...I'll stop here since I for now have no more context. I will request @steveloughran to provide more help. Shall we backport HADOOP-16626 to
branch-3.2and see?