Skip to content

Commit 36af4a9

Browse files
author
Brandon Li
committed
HDFS-7942. NFS: support regexp grouping in nfs.exports.allowed.hosts. Contributed by Brandon Li
1 parent 82eda77 commit 36af4a9

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/NfsExports.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private static Match getMatch(String line) {
391391
return new CIDRMatch(privilege,
392392
new SubnetUtils(pair[0], pair[1]).getInfo());
393393
} else if (host.contains("*") || host.contains("?") || host.contains("[")
394-
|| host.contains("]")) {
394+
|| host.contains("]") || host.contains("(") || host.contains(")")) {
395395
if (LOG.isDebugEnabled()) {
396396
LOG.debug("Using Regex match for '" + host + "' and " + privilege);
397397
}

hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/TestNfsExports.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
public class TestNfsExports {
2525

26-
private final String address1 = "192.168.0.1";
27-
private final String address2 = "10.0.0.1";
26+
private final String address1 = "192.168.0.12";
27+
private final String address2 = "10.0.0.12";
2828
private final String hostname1 = "a.b.com";
2929
private final String hostname2 = "a.b.org";
3030

@@ -164,6 +164,24 @@ public void testRegexHostRO() {
164164
matcher.getAccessPrivilege(address1, hostname2));
165165
}
166166

167+
@Test
168+
public void testRegexGrouping() {
169+
NfsExports matcher = new NfsExports(CacheSize, ExpirationPeriod,
170+
"192.168.0.(12|34)");
171+
Assert.assertEquals(AccessPrivilege.READ_ONLY,
172+
matcher.getAccessPrivilege(address1, hostname1));
173+
// address1 will hit the cache
174+
Assert.assertEquals(AccessPrivilege.READ_ONLY,
175+
matcher.getAccessPrivilege(address1, hostname2));
176+
177+
matcher = new NfsExports(CacheSize, ExpirationPeriod, "\\w*.a.b.com");
178+
Assert.assertEquals(AccessPrivilege.READ_ONLY,
179+
matcher.getAccessPrivilege("1.2.3.4", "web.a.b.com"));
180+
// address "1.2.3.4" will hit the cache
181+
Assert.assertEquals(AccessPrivilege.READ_ONLY,
182+
matcher.getAccessPrivilege("1.2.3.4", "email.a.b.org"));
183+
}
184+
167185
@Test
168186
public void testMultiMatchers() throws Exception {
169187
long shortExpirationPeriod = 1 * 1000 * 1000 * 1000; // 1s

hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,8 @@ Release 2.7.0 - UNRELEASED
12321232
HDFS-6841. Use Time.monotonicNow() wherever applicable instead of Time.now()
12331233
(Vinayakumar B via kihwal)
12341234

1235+
HDFS-7942. NFS: support regexp grouping in nfs.exports.allowed.hosts (brandonli)
1236+
12351237
BREAKDOWN OF HDFS-7584 SUBTASKS AND RELATED JIRAS
12361238

12371239
HDFS-7720. Quota by Storage Type API, tools and ClientNameNode

hadoop-hdfs-project/hadoop-hdfs/src/site/markdown/HdfsNfsGateway.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,12 @@ It's strongly recommended for the users to update a few configuration properties
144144
* By default, the export can be mounted by any client. To better control the access,
145145
users can update the following property. The value string contains machine name and
146146
access privilege, separated by whitespace
147-
characters. The machine name format can be a single host, a Java regular expression, or an IPv4 address. The access
147+
characters. The machine name format can be a single host, a "*", a Java regular expression, or an IPv4 address. The access
148148
privilege uses rw or ro to specify read/write or read-only access of the machines to exports. If the access privilege is not provided, the default is read-only. Entries are separated by ";".
149-
For example: "192.168.0.0/22 rw ; host.\*\\.example\\.com ; host1.test.org ro;". Only the NFS gateway needs to restart after
150-
this property is updated.
149+
For example: "192.168.0.0/22 rw ; \\\\w\*\\\\.example\\\\.com ; host1.test.org ro;". Only the NFS gateway needs to restart after
150+
this property is updated. Note that, here Java regular expression is differnt with the regrulation expression used in
151+
Linux NFS export table, such as, using "\\\\w\*\\\\.example\\\\.com" instead of "\*.example.com", "192\\\\.168\\\\.0\\\\.(11|22)"
152+
instead of "192.168.0.[11|22]" and so on.
151153

152154
<property>
153155
<name>nfs.exports.allowed.hosts</name>

0 commit comments

Comments
 (0)