ahmarsuhail commented on code in PR #6874:
URL: https://github.com/apache/hadoop/pull/6874#discussion_r1675660341
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java:
##########
@@ -1402,6 +1406,79 @@ public static String getS3EncryptionKey(
}
}
+ /**
+ * Get any SSE context, without propagating exceptions from
+ * JCEKs files.
+ * @param bucket bucket to query for
+ * @param conf configuration to examine
+ * @return the encryption context value or ""
+ * @throws IllegalArgumentException bad arguments.
+ */
+ public static String getS3EncryptionContext(
Review Comment:
looks like this method is only used in tests?
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/auth/delegation/EncryptionSecretOperations.java:
##########
@@ -61,4 +61,21 @@ public static Optional<String> getSSEAwsKMSKey(final
EncryptionSecrets secrets)
return Optional.empty();
}
}
+
+ /**
+ * Gets the SSE-KMS context if present, else don't set it in the S3 request.
+ *
+ * @param secrets source of the encryption secrets.
+ * @return an optional AWS KMS encryption context to attach to a request.
+ */
+ public static Optional<String> getSSEAwsKMSEncryptionContext(final
EncryptionSecrets secrets) {
+ if ((secrets.getEncryptionMethod() == S3AEncryptionMethods.SSE_KMS
+ || secrets.getEncryptionMethod() == S3AEncryptionMethods.DSSE_KMS)
+ && secrets.hasEncryptionKey()
Review Comment:
can't you have encryption context without defining a secret key, if you're
just using an AWS KMS key? so then you shouldn't have this condition?
##########
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3AEncryptionDSSEKMSUserDefinedKeyWithEncryptionContext.java:
##########
@@ -0,0 +1,70 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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;
Review Comment:
your ITests are not very useful as they don't assert on anything. I also
don't think you need 3 new ITests that extend AbstractTestS3AEncryption.
I recommend that you add a single ITest, that writes an object with
encryption context. parameterize it for SSE-KMS default key, SS-KMS customer
key, DSSE-KMS. Then do a GET on the object and assert on the encryption
context.
##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AUtils.java:
##########
@@ -1493,7 +1570,10 @@ public static EncryptionSecrets
buildEncryptionSecrets(String bucket,
LOG.debug("Data is unencrypted");
break;
}
- return new EncryptionSecrets(encryptionMethod, encryptionKey);
+
+ String encryptionContext = getS3EncryptionContextBase64Encoded(bucket,
conf,
Review Comment:
nit: move this statement above the switch
##########
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestSSEConfiguration.java:
##########
@@ -147,39 +151,42 @@ void setProviderOption(final Configuration conf,
}
/**
- * Assert that the exception text from {@link #getAlgorithm(String, String)}
+ * Assert that the exception text from {@link #getAlgorithm(String, String,
String)}
* is as expected.
* @param expected expected substring in error
* @param alg algorithm to ask for
* @param key optional key value
+ * @param context optional encryption context value
* @throws Exception anything else which gets raised
*/
public void assertGetAlgorithmFails(String expected,
- final String alg, final String key) throws Exception {
+ final String alg, final String key, final String context) throws
Exception {
intercept(IOException.class, expected,
- () -> getAlgorithm(alg, key));
+ () -> getAlgorithm(alg, key, context));
}
private S3AEncryptionMethods getAlgorithm(S3AEncryptionMethods algorithm,
- String key)
+ String key,
+ String encryptionContext)
throws IOException {
- return getAlgorithm(algorithm.getMethod(), key);
+ return getAlgorithm(algorithm.getMethod(), key, encryptionContext);
}
- private S3AEncryptionMethods getAlgorithm(String algorithm, String key)
+ private S3AEncryptionMethods getAlgorithm(String algorithm, String key,
String encryptionContext)
throws IOException {
- return getEncryptionAlgorithm(BUCKET, buildConf(algorithm, key));
+ return getEncryptionAlgorithm(BUCKET, buildConf(algorithm, key,
encryptionContext));
}
/**
* Build a new configuration with the given S3-SSE algorithm
* and key.
* @param algorithm algorithm to use, may be null
* @param key key, may be null
+ * @param context encryption context, may be null
* @return the new config.
*/
@SuppressWarnings("deprecation")
- private Configuration buildConf(String algorithm, String key) {
+ private Configuration buildConf(String algorithm, String key, String
context) {
Review Comment:
nit: rename to encryptionContext
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]