Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public S3SecretManagerImpl(OzoneConfiguration configuration,
public S3SecretValue getS3Secret(String kerberosID) throws IOException {
Preconditions.checkArgument(Strings.isNotBlank(kerberosID),
"kerberosID cannot be null or empty.");
String awsAccessKeyStr = DigestUtils.md5Hex(kerberosID);
byte[] awsAccessKey = awsAccessKeyStr.getBytes(UTF_8);
byte[] awsAccessKey = kerberosID.getBytes(UTF_8);
S3SecretValue result = null;
omMetadataManager.getLock().acquireS3SecretLock(kerberosID);
try {
Expand All @@ -77,33 +76,31 @@ public S3SecretValue getS3Secret(String kerberosID) throws IOException {
result = S3SecretValue.fromProtobuf(
OzoneManagerProtocolProtos.S3Secret.parseFrom(s3Secret));
}
result.setAwsAccessKey(awsAccessKeyStr);
} finally {
omMetadataManager.getLock().releaseS3SecretLock(kerberosID);
}
LOG.trace("Secret for kerberosID:{},accessKey:{}, proto:{}", kerberosID,
awsAccessKeyStr, result);
LOG.trace("Secret for accessKey:{}, proto:{}", kerberosID, result);
return result;
}

@Override
public String getS3UserSecretString(String awsAccessKeyId)
public String getS3UserSecretString(String kerberosID)
throws IOException {
Preconditions.checkArgument(Strings.isNotBlank(awsAccessKeyId),
Preconditions.checkArgument(Strings.isNotBlank(kerberosID),
"awsAccessKeyId cannot be null or empty.");
LOG.trace("Get secret for awsAccessKey:{}", awsAccessKeyId);
LOG.trace("Get secret for awsAccessKey:{}", kerberosID);

byte[] s3Secret;
omMetadataManager.getLock().acquireS3SecretLock(awsAccessKeyId);
omMetadataManager.getLock().acquireS3SecretLock(kerberosID);
try {
s3Secret = omMetadataManager.getS3SecretTable()
.get(awsAccessKeyId.getBytes(UTF_8));
.get(kerberosID.getBytes(UTF_8));
if (s3Secret == null) {
throw new OzoneSecurityException("S3 secret not found for " +
"awsAccessKeyId " + awsAccessKeyId, S3_SECRET_NOT_FOUND);
"awsAccessKeyId " + kerberosID, S3_SECRET_NOT_FOUND);
}
} finally {
omMetadataManager.getLock().releaseS3SecretLock(awsAccessKeyId);
omMetadataManager.getLock().releaseS3SecretLock(kerberosID);
}

return OzoneManagerProtocolProtos.S3Secret.parseFrom(s3Secret)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.apache.hadoop.ozone.om.helpers;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos;

/**
Expand All @@ -26,12 +25,10 @@
public class S3SecretValue {
private String kerberosID;
private String awsSecret;
private String awsAccessKey;

public S3SecretValue(String kerberosID, String awsSecret) {
this.kerberosID = kerberosID;
this.awsSecret = awsSecret;
this.awsAccessKey = DigestUtils.md5Hex(kerberosID);
}

public String getKerberosID() {
Expand All @@ -51,11 +48,7 @@ public void setAwsSecret(String awsSecret) {
}

public String getAwsAccessKey() {
return awsAccessKey;
}

public void setAwsAccessKey(String awsAccessKey) {
this.awsAccessKey = awsAccessKey;
return kerberosID;
}

public static S3SecretValue fromProtobuf(
Expand All @@ -72,6 +65,6 @@ public OzoneManagerProtocolProtos.S3Secret getProtobuf() {

@Override
public String toString() {
return "awsAccessKey=" + awsAccessKey + "\nawsSecret=" + awsSecret;
return "awsAccessKey=" + kerberosID + "\nawsSecret=" + awsSecret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.apache.hadoop.ozone.om.helpers.OmMultipartCommitUploadPartInfo;
import org.apache.hadoop.ozone.om.helpers.OmMultipartInfo;
import org.apache.hadoop.ozone.om.helpers.OmMultipartUploadCompleteInfo;
import org.apache.hadoop.ozone.s3.util.OzoneS3Util;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.test.LambdaTestUtils;
import org.apache.hadoop.util.Time;
Expand All @@ -92,6 +93,8 @@
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.either;
import org.junit.Assert;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
Expand Down Expand Up @@ -288,6 +291,23 @@ public void testCreateS3Bucket()
Assert.assertTrue(volume.getCreationTime() >= currentTime);
}

@Test
public void testCreateSecureS3Bucket() throws IOException {
long currentTime = Time.now();
String userName = "ozone/[email protected]";
String bucketName = UUID.randomUUID().toString();
String s3VolumeName = OzoneS3Util.getVolumeName(userName);
store.createS3Bucket(s3VolumeName, bucketName);
String volumeName = store.getOzoneVolumeName(bucketName);
assertEquals(volumeName, "s3" + s3VolumeName);

OzoneVolume volume = store.getVolume(volumeName);
OzoneBucket bucket = volume.getBucket(bucketName);
Assert.assertEquals(bucketName, bucket.getName());
Assert.assertTrue(bucket.getCreationTime() >= currentTime);
Assert.assertTrue(volume.getCreationTime() >= currentTime);
}


@Test
public void testListS3Buckets()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.StringUtils;

import static org.apache.hadoop.ozone.s3.util.OzoneS3Util.getVolumeName;
import static org.apache.hadoop.ozone.s3.util.S3Consts.ENCODING_TYPE;
import org.apache.http.HttpStatus;
import org.slf4j.Logger;
Expand Down Expand Up @@ -196,9 +198,10 @@ public Response list(
public Response put(@PathParam("bucket") String bucketName, @Context
HttpHeaders httpHeaders) throws IOException, OS3Exception {

String userName = getAuthenticationHeaderParser().getAccessKeyID();
String volumeName = getVolumeName(getAuthenticationHeaderParser().
getAccessKeyID());

String location = createS3Bucket(userName, bucketName);
String location = createS3Bucket(volumeName, bucketName);

LOG.info("Location is {}", location);
return Response.status(HttpStatus.SC_OK).header("Location", location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.hadoop.ozone.s3.util.OzoneS3Util.getVolumeName;

/**
* Top level rest endpoint.
*/
Expand Down Expand Up @@ -63,8 +65,9 @@ public Response get()
.header("Location", "/static/")
.build();
}
String userName = authenticationHeaderParser.getAccessKeyID();
Iterator<? extends OzoneBucket> bucketIterator = listS3Buckets(userName,
String volumeName = getVolumeName(authenticationHeaderParser.
getAccessKeyID());
Iterator<? extends OzoneBucket> bucketIterator = listS3Buckets(volumeName,
null);

while (bucketIterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,25 @@ public class Credential {
@SuppressWarnings("StringSplitter")
public void parseCredential() throws OS3Exception {
String[] split = credential.split("/");
if (split.length == 5) {
switch (split.length) {
case 5:
// Ex: dkjad922329ddnks/20190321/us-west-1/s3/aws4_request
accessKeyID = split[0].trim();
date = split[1].trim();
awsRegion = split[2].trim();
awsService = split[3].trim();
awsRequest = split[4].trim();
} else {
return;
case 6:
// Access id is kerberos principal.
// Ex: testuser/[email protected]/20190321/us-west-1/s3/aws4_request
accessKeyID = split[0] + "/" +split[1];
date = split[2].trim();
awsRegion = split[3].trim();
awsService = split[4].trim();
awsRequest = split[5].trim();
return;
default:
LOG.error("Credentials not in expected format. credential:{}",
credential);
throw S3ErrorTable.newError(S3ErrorTable.MALFORMED_HEADER, credential);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.ozone.s3.util;

import org.apache.commons.codec.digest.DigestUtils;
import java.util.Objects;

/**
* Ozone util for S3 related operations.
*/
public final class OzoneS3Util {

private OzoneS3Util() {
}

public static String getVolumeName(String userName) {
Objects.requireNonNull(userName);
return DigestUtils.md5Hex(userName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.hadoop.ozone.s3.header.AuthenticationHeaderParser;

import static org.junit.Assert.assertEquals;
import org.apache.hadoop.ozone.s3.util.OzoneS3Util;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -61,10 +62,11 @@ public void testListBucket() throws Exception {
ListBucketResponse response =
(ListBucketResponse) rootEndpoint.get().getEntity();
assertEquals(0, response.getBucketsNum());
String volumeName = OzoneS3Util.getVolumeName(userName);

String bucketBaseName = "bucket-" + getClass().getName();
for(int i = 0; i < 10; i++) {
objectStoreStub.createS3Bucket(userName, bucketBaseName + i);
objectStoreStub.createS3Bucket(volumeName, bucketBaseName + i);
}
response = (ListBucketResponse) rootEndpoint.get().getEntity();
assertEquals(10, response.getBucketsNum());
Expand Down