Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A9011200D18 for ; Wed, 27 Sep 2017 05:29:29 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9D2191609EA; Wed, 27 Sep 2017 03:29:29 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 93F481609D7 for ; Wed, 27 Sep 2017 05:29:28 +0200 (CEST) Received: (qmail 76361 invoked by uid 500); 27 Sep 2017 03:29:27 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 76352 invoked by uid 99); 27 Sep 2017 03:29:27 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Sep 2017 03:29:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6F3E2F325E; Wed, 27 Sep 2017 03:29:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: yqlin@apache.org To: common-commits@hadoop.apache.org Message-Id: <752b5984f613419a92b9a5c6192009d1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HDFS-12525. Ozone: OzoneClient: Verify bucket/volume name in create calls. Contributed by Nandakumar. Date: Wed, 27 Sep 2017 03:29:25 +0000 (UTC) archived-at: Wed, 27 Sep 2017 03:29:29 -0000 Repository: hadoop Updated Branches: refs/heads/HDFS-7240 a7df79ca5 -> ea4751902 HDFS-12525. Ozone: OzoneClient: Verify bucket/volume name in create calls. Contributed by Nandakumar. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/ea475190 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/ea475190 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/ea475190 Branch: refs/heads/HDFS-7240 Commit: ea4751902d1cdd048dc3bbfe7f0e8a0ab1bdbf6f Parents: a7df79c Author: Yiqun Lin Authored: Wed Sep 27 11:28:45 2017 +0800 Committer: Yiqun Lin Committed: Wed Sep 27 11:28:45 2017 +0800 ---------------------------------------------------------------------- .../apache/hadoop/ozone/client/ObjectStore.java | 4 + .../hadoop/ozone/client/OzoneClientUtils.java | 80 ++++++++++++++++++++ .../apache/hadoop/ozone/client/OzoneVolume.java | 4 + .../hadoop/ozone/web/utils/OzoneUtils.java | 71 +---------------- .../ozone/client/rpc/TestOzoneRpcClient.java | 19 +++++ 5 files changed, 109 insertions(+), 69 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/ea475190/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java index f8bb21a..49addf7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/ObjectStore.java @@ -50,6 +50,7 @@ public class ObjectStore { */ public void createVolume(String volumeName) throws IOException { Preconditions.checkNotNull(volumeName); + OzoneClientUtils.verifyResourceName(volumeName); proxy.createVolume(volumeName); } @@ -63,6 +64,7 @@ public class ObjectStore { throws IOException { Preconditions.checkNotNull(volumeName); Preconditions.checkNotNull(volumeArgs); + OzoneClientUtils.verifyResourceName(volumeName); proxy.createVolume(volumeName, volumeArgs); } @@ -74,6 +76,7 @@ public class ObjectStore { */ public OzoneVolume getVolume(String volumeName) throws IOException { Preconditions.checkNotNull(volumeName); + OzoneClientUtils.verifyResourceName(volumeName); OzoneVolume volume = proxy.getVolumeDetails(volumeName); volume.setClientProxy(proxy); return volume; @@ -86,6 +89,7 @@ public class ObjectStore { */ public void deleteVolume(String volumeName) throws IOException { Preconditions.checkNotNull(volumeName); + OzoneClientUtils.verifyResourceName(volumeName); proxy.deleteVolume(volumeName); } } http://git-wip-us.apache.org/repos/asf/hadoop/blob/ea475190/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/OzoneClientUtils.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/OzoneClientUtils.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/OzoneClientUtils.java index 32bc2c3..9ccd23c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/OzoneClientUtils.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/OzoneClientUtils.java @@ -28,6 +28,7 @@ import org.apache.hadoop.ipc.RPC; import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.ozone.OzoneConfigKeys; import org.apache.hadoop.ozone.OzoneConfiguration; +import org.apache.hadoop.ozone.OzoneConsts; import org.apache.hadoop.scm.ScmConfigKeys; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpRequestBase; @@ -731,4 +732,83 @@ public final class OzoneClientUtils { .build(); return client; } + + /** + * verifies that bucket name / volume name is a valid DNS name. + * + * @param resName Bucket or volume Name to be validated + * + * @throws IllegalArgumentException + */ + public static void verifyResourceName(String resName) + throws IllegalArgumentException { + + if (resName == null) { + throw new IllegalArgumentException("Bucket or Volume name is null"); + } + + if ((resName.length() < OzoneConsts.OZONE_MIN_BUCKET_NAME_LENGTH) || + (resName.length() > OzoneConsts.OZONE_MAX_BUCKET_NAME_LENGTH)) { + throw new IllegalArgumentException( + "Bucket or Volume length is illegal, " + + "valid length is 3-63 characters"); + } + + if ((resName.charAt(0) == '.') || (resName.charAt(0) == '-')) { + throw new IllegalArgumentException( + "Bucket or Volume name cannot start with a period or dash"); + } + + if ((resName.charAt(resName.length() - 1) == '.') || + (resName.charAt(resName.length() - 1) == '-')) { + throw new IllegalArgumentException( + "Bucket or Volume name cannot end with a period or dash"); + } + + boolean isIPv4 = true; + char prev = (char) 0; + + for (int index = 0; index < resName.length(); index++) { + char currChar = resName.charAt(index); + + if (currChar != '.') { + isIPv4 = ((currChar >= '0') && (currChar <= '9')) && isIPv4; + } + + if (currChar > 'A' && currChar < 'Z') { + throw new IllegalArgumentException( + "Bucket or Volume name does not support uppercase characters"); + } + + if ((currChar != '.') && (currChar != '-')) { + if ((currChar < '0') || (currChar > '9' && currChar < 'a') || + (currChar > 'z')) { + throw new IllegalArgumentException("Bucket or Volume name has an " + + "unsupported character : " + + currChar); + } + } + + if ((prev == '.') && (currChar == '.')) { + throw new IllegalArgumentException("Bucket or Volume name should not " + + "have two contiguous periods"); + } + + if ((prev == '-') && (currChar == '.')) { + throw new IllegalArgumentException( + "Bucket or Volume name should not have period after dash"); + } + + if ((prev == '.') && (currChar == '-')) { + throw new IllegalArgumentException( + "Bucket or Volume name should not have dash after period"); + } + prev = currChar; + } + + if (isIPv4) { + throw new IllegalArgumentException( + "Bucket or Volume name cannot be an IPv4 address or all numeric"); + } + } } http://git-wip-us.apache.org/repos/asf/hadoop/blob/ea475190/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java index 575fb25..64c35bc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/client/OzoneVolume.java @@ -148,6 +148,7 @@ public class OzoneVolume { throws IOException { Preconditions.checkNotNull(proxy, "Client proxy is not set."); Preconditions.checkNotNull(bucketName); + OzoneClientUtils.verifyResourceName(bucketName); proxy.createBucket(name, bucketName); } @@ -162,6 +163,7 @@ public class OzoneVolume { Preconditions.checkNotNull(proxy, "Client proxy is not set."); Preconditions.checkNotNull(bucketName); Preconditions.checkNotNull(bucketArgs); + OzoneClientUtils.verifyResourceName(bucketName); proxy.createBucket(name, bucketName, bucketArgs); } @@ -174,6 +176,7 @@ public class OzoneVolume { public OzoneBucket getBucket(String bucketName) throws IOException { Preconditions.checkNotNull(proxy, "Client proxy is not set."); Preconditions.checkNotNull(bucketName); + OzoneClientUtils.verifyResourceName(bucketName); OzoneBucket bucket = proxy.getBucketDetails(name, bucketName); bucket.setClientProxy(proxy); return bucket; @@ -187,6 +190,7 @@ public class OzoneVolume { public void deleteBucket(String bucketName) throws IOException { Preconditions.checkNotNull(proxy, "Client proxy is not set."); Preconditions.checkNotNull(bucketName); + OzoneClientUtils.verifyResourceName(bucketName); proxy.deleteBucket(name, bucketName); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/ea475190/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/utils/OzoneUtils.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/utils/OzoneUtils.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/utils/OzoneUtils.java index 6459626..f3854f8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/utils/OzoneUtils.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/utils/OzoneUtils.java @@ -24,6 +24,7 @@ import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ozone.OzoneConfigKeys; import org.apache.hadoop.ozone.OzoneConsts; +import org.apache.hadoop.ozone.client.OzoneClientUtils; import org.apache.hadoop.ozone.client.io.LengthInputStream; import org.apache.hadoop.ozone.web.exceptions.ErrorTable; import org.apache.hadoop.ozone.web.exceptions.OzoneException; @@ -86,75 +87,7 @@ public final class OzoneUtils { */ public static void verifyResourceName(String resName) throws IllegalArgumentException { - - if (resName == null) { - throw new IllegalArgumentException("Bucket or Volume name is null"); - } - - if ((resName.length() < OzoneConsts.OZONE_MIN_BUCKET_NAME_LENGTH) || - (resName.length() > OzoneConsts.OZONE_MAX_BUCKET_NAME_LENGTH)) { - throw new IllegalArgumentException( - "Bucket or Volume length is illegal, " + - "valid length is 3-63 characters"); - } - - if ((resName.charAt(0) == '.') || (resName.charAt(0) == '-')) { - throw new IllegalArgumentException( - "Bucket or Volume name cannot start with a period or dash"); - } - - if ((resName.charAt(resName.length() - 1) == '.') || - (resName.charAt(resName.length() - 1) == '-')) { - throw new IllegalArgumentException( - "Bucket or Volume name cannot end with a period or dash"); - } - - boolean isIPv4 = true; - char prev = (char) 0; - - for (int index = 0; index < resName.length(); index++) { - char currChar = resName.charAt(index); - - if (currChar != '.') { - isIPv4 = ((currChar >= '0') && (currChar <= '9')) && isIPv4; - } - - if (currChar > 'A' && currChar < 'Z') { - throw new IllegalArgumentException( - "Bucket or Volume name does not support uppercase characters"); - } - - - if ((currChar != '.') && (currChar != '-')) { - if ((currChar < '0') || (currChar > '9' && currChar < 'a') || - (currChar > 'z')) { - throw new IllegalArgumentException("Bucket or Volume name has an " + - "unsupported character : " + - currChar); - } - } - - if ((prev == '.') && (currChar == '.')) { - throw new IllegalArgumentException("Bucket or Volume name should not " + - "have two contiguous periods"); - } - - if ((prev == '-') && (currChar == '.')) { - throw new IllegalArgumentException( - "Bucket or Volume name should not have period after dash"); - } - - if ((prev == '.') && (currChar == '-')) { - throw new IllegalArgumentException( - "Bucket or Volume name should not have dash after period"); - } - prev = currChar; - } - - if (isIPv4) { - throw new IllegalArgumentException( - "Bucket or Volume name cannot be an IPv4 address or all numeric"); - } + OzoneClientUtils.verifyResourceName(resName); } /** http://git-wip-us.apache.org/repos/asf/hadoop/blob/ea475190/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClient.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClient.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClient.java index 385f9f9..b07e72c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/client/rpc/TestOzoneRpcClient.java @@ -117,6 +117,14 @@ public class TestOzoneRpcClient { } @Test + public void testInvalidVolumeCreation() throws IOException { + thrown.expectMessage("Bucket or Volume name has an unsupported" + + " character : #"); + String volumeName = "invalid#name"; + store.createVolume(volumeName); + } + + @Test public void testVolumeAlreadyExist() throws IOException, OzoneException { String volumeName = UUID.randomUUID().toString(); @@ -248,6 +256,17 @@ public class TestOzoneRpcClient { } @Test + public void testInvalidBucketCreation() throws IOException { + thrown.expectMessage("Bucket or Volume name has an unsupported" + + " character : #"); + String volumeName = UUID.randomUUID().toString(); + String bucketName = "invalid#bucket"; + store.createVolume(volumeName); + OzoneVolume volume = store.getVolume(volumeName); + volume.createBucket(bucketName); + } + + @Test public void testAddBucketAcl() throws IOException, OzoneException { String volumeName = UUID.randomUUID().toString(); --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org