Skip to content

Commit 5de7b71

Browse files
authored
Merge branch 'apache:trunk' into HADOOP-18427
2 parents 5a453fb + 42c8f61 commit 5de7b71

File tree

63 files changed

+3101
-442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3101
-442
lines changed

hadoop-client-modules/hadoop-client-api/pom.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@
9898
<createSourcesJar>true</createSourcesJar>
9999
<shadeSourcesContent>true</shadeSourcesContent>
100100
</configuration>
101-
<dependencies>
102-
<dependency>
103-
<groupId>org.apache.hadoop</groupId>
104-
<artifactId>hadoop-maven-plugins</artifactId>
105-
<version>${project.version}</version>
106-
</dependency>
107-
</dependencies>
108101
<executions>
109102
<execution>
110103
<phase>package</phase>
@@ -254,8 +247,7 @@
254247
</relocation>
255248
</relocations>
256249
<transformers>
257-
<!-- Needed until MSHADE-182 -->
258-
<transformer implementation="org.apache.hadoop.maven.plugin.shade.resource.ServicesResourceTransformer"/>
250+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
259251
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/>
260252
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
261253
<resource>NOTICE.txt</resource>

hadoop-client-modules/hadoop-client-minicluster/pom.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,6 @@
671671
<plugin>
672672
<groupId>org.apache.maven.plugins</groupId>
673673
<artifactId>maven-shade-plugin</artifactId>
674-
<dependencies>
675-
<dependency>
676-
<groupId>org.apache.hadoop</groupId>
677-
<artifactId>hadoop-maven-plugins</artifactId>
678-
<version>${project.version}</version>
679-
</dependency>
680-
</dependencies>
681674
<executions>
682675
<execution>
683676
<phase>package</phase>
@@ -1052,8 +1045,7 @@
10521045
</relocation>
10531046
</relocations>
10541047
<transformers>
1055-
<!-- Needed until MSHADE-182 -->
1056-
<transformer implementation="org.apache.hadoop.maven.plugin.shade.resource.ServicesResourceTransformer"/>
1048+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
10571049
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/>
10581050
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
10591051
<resources>

hadoop-client-modules/hadoop-client-runtime/pom.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@
128128
<plugin>
129129
<groupId>org.apache.maven.plugins</groupId>
130130
<artifactId>maven-shade-plugin</artifactId>
131-
<dependencies>
132-
<dependency>
133-
<groupId>org.apache.hadoop</groupId>
134-
<artifactId>hadoop-maven-plugins</artifactId>
135-
<version>${project.version}</version>
136-
</dependency>
137-
</dependencies>
138131
<executions>
139132
<execution>
140133
<phase>package</phase>
@@ -397,8 +390,7 @@
397390
-->
398391
</relocations>
399392
<transformers>
400-
<!-- Needed until MSHADE-182 -->
401-
<transformer implementation="org.apache.hadoop.maven.plugin.shade.resource.ServicesResourceTransformer"/>
393+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
402394
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/>
403395
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
404396
<resources>

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/util/SampleStat.java

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,37 @@
2727
public class SampleStat {
2828
private final MinMax minmax = new MinMax();
2929
private long numSamples = 0;
30-
private double a0, a1, s0, s1, total;
30+
private double mean, s;
3131

3232
/**
3333
* Construct a new running sample stat
3434
*/
3535
public SampleStat() {
36-
a0 = s0 = 0.0;
37-
total = 0.0;
36+
mean = 0.0;
37+
s = 0.0;
3838
}
3939

4040
public void reset() {
4141
numSamples = 0;
42-
a0 = s0 = 0.0;
43-
total = 0.0;
42+
mean = 0.0;
43+
s = 0.0;
4444
minmax.reset();
4545
}
4646

4747
// We want to reuse the object, sometimes.
48-
void reset(long numSamples, double a0, double a1, double s0, double s1,
49-
double total, MinMax minmax) {
50-
this.numSamples = numSamples;
51-
this.a0 = a0;
52-
this.a1 = a1;
53-
this.s0 = s0;
54-
this.s1 = s1;
55-
this.total = total;
56-
this.minmax.reset(minmax);
48+
void reset(long numSamples1, double mean1, double s1, MinMax minmax1) {
49+
numSamples = numSamples1;
50+
mean = mean1;
51+
s = s1;
52+
minmax.reset(minmax1);
5753
}
5854

5955
/**
6056
* Copy the values to other (saves object creation and gc.)
6157
* @param other the destination to hold our values
6258
*/
6359
public void copyTo(SampleStat other) {
64-
other.reset(numSamples, a0, a1, s0, s1, total, minmax);
60+
other.reset(numSamples, mean, s, minmax);
6561
}
6662

6763
/**
@@ -78,24 +74,22 @@ public SampleStat add(double x) {
7874
* Add some sample and a partial sum to the running stat.
7975
* Note, min/max is not evaluated using this method.
8076
* @param nSamples number of samples
81-
* @param x the partial sum
77+
* @param xTotal the partial sum
8278
* @return self
8379
*/
84-
public SampleStat add(long nSamples, double x) {
80+
public SampleStat add(long nSamples, double xTotal) {
8581
numSamples += nSamples;
86-
total += x;
8782

88-
if (numSamples == 1) {
89-
a0 = a1 = x;
90-
s0 = 0.0;
91-
}
92-
else {
93-
// The Welford method for numerical stability
94-
a1 = a0 + (x - a0) / numSamples;
95-
s1 = s0 + (x - a0) * (x - a1);
96-
a0 = a1;
97-
s0 = s1;
98-
}
83+
// use the weighted incremental version of Welford's algorithm to get
84+
// numerical stability while treating the samples as being weighted
85+
// by nSamples
86+
// see https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
87+
88+
double x = xTotal / nSamples;
89+
double meanOld = mean;
90+
91+
mean += ((double) nSamples / numSamples) * (x - meanOld);
92+
s += nSamples * (x - meanOld) * (x - mean);
9993
return this;
10094
}
10195

@@ -110,21 +104,21 @@ public long numSamples() {
110104
* @return the total of all samples added
111105
*/
112106
public double total() {
113-
return total;
107+
return mean * numSamples;
114108
}
115109

116110
/**
117111
* @return the arithmetic mean of the samples
118112
*/
119113
public double mean() {
120-
return numSamples > 0 ? (total / numSamples) : 0.0;
114+
return numSamples > 0 ? mean : 0.0;
121115
}
122116

123117
/**
124118
* @return the variance of the samples
125119
*/
126120
public double variance() {
127-
return numSamples > 1 ? s1 / (numSamples - 1) : 0.0;
121+
return numSamples > 1 ? s / (numSamples - 1) : 0.0;
128122
}
129123

130124
/**

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.security.GeneralSecurityException;
3131
import java.security.KeyStore;
3232
import java.util.ArrayList;
33+
import java.util.Arrays;
3334
import java.util.Collections;
3435
import java.util.Hashtable;
3536
import java.util.Iterator;
@@ -252,6 +253,10 @@ public class LdapGroupsMapping
252253
public static final String POSIX_GID_ATTR_KEY = LDAP_CONFIG_PREFIX + ".posix.attr.gid.name";
253254
public static final String POSIX_GID_ATTR_DEFAULT = "gidNumber";
254255

256+
public static final String GROUP_SEARCH_FILTER_PATTERN =
257+
LDAP_CONFIG_PREFIX + ".group.search.filter.pattern";
258+
public static final String GROUP_SEARCH_FILTER_PATTERN_DEFAULT = "";
259+
255260
/*
256261
* Posix attributes
257262
*/
@@ -337,6 +342,7 @@ public class LdapGroupsMapping
337342
private int numAttempts;
338343
private volatile int numAttemptsBeforeFailover;
339344
private volatile String ldapCtxFactoryClassName;
345+
private volatile String[] groupSearchFilterParams;
340346

341347
/**
342348
* Returns list of groups for a user.
@@ -437,8 +443,14 @@ Set<String> lookupGroup(SearchResult result, DirContext c,
437443
Set<String> groupDNs = new HashSet<>();
438444

439445
NamingEnumeration<SearchResult> groupResults;
440-
// perform the second LDAP query
441-
if (isPosix) {
446+
447+
String[] resolved = resolveCustomGroupFilterArgs(result);
448+
// If custom group filter argument is supplied, use that!!!
449+
if (resolved != null) {
450+
groupResults =
451+
c.search(groupbaseDN, groupSearchFilter, resolved, SEARCH_CONTROLS);
452+
} else if (isPosix) {
453+
// perform the second LDAP query
442454
groupResults = lookupPosixGroup(result, c);
443455
} else {
444456
String userDn = result.getNameInNamespace();
@@ -462,6 +474,25 @@ Set<String> lookupGroup(SearchResult result, DirContext c,
462474
return groups;
463475
}
464476

477+
private String[] resolveCustomGroupFilterArgs(SearchResult result)
478+
throws NamingException {
479+
if (groupSearchFilterParams != null) {
480+
String[] filterElems = new String[groupSearchFilterParams.length];
481+
for (int i = 0; i < groupSearchFilterParams.length; i++) {
482+
// Specific handling for userDN.
483+
if (groupSearchFilterParams[i].equalsIgnoreCase("userDN")) {
484+
filterElems[i] = result.getNameInNamespace();
485+
} else {
486+
filterElems[i] =
487+
result.getAttributes().get(groupSearchFilterParams[i]).get()
488+
.toString();
489+
}
490+
}
491+
return filterElems;
492+
}
493+
return null;
494+
}
495+
465496
/**
466497
* Perform LDAP queries to get group names of a user.
467498
*
@@ -781,6 +812,12 @@ public synchronized void setConf(Configuration conf) {
781812
conf.get(POSIX_UID_ATTR_KEY, POSIX_UID_ATTR_DEFAULT);
782813
posixGidAttr =
783814
conf.get(POSIX_GID_ATTR_KEY, POSIX_GID_ATTR_DEFAULT);
815+
String groupSearchFilterParamCSV = conf.get(GROUP_SEARCH_FILTER_PATTERN,
816+
GROUP_SEARCH_FILTER_PATTERN_DEFAULT);
817+
if(groupSearchFilterParamCSV!=null && !groupSearchFilterParamCSV.isEmpty()) {
818+
LOG.debug("Using custom group search filters: {}", groupSearchFilterParamCSV);
819+
groupSearchFilterParams = groupSearchFilterParamCSV.split(",");
820+
}
784821

785822
int dirSearchTimeout = conf.getInt(DIRECTORY_SEARCH_TIMEOUT,
786823
DIRECTORY_SEARCH_TIMEOUT_DEFAULT);
@@ -795,7 +832,16 @@ public synchronized void setConf(Configuration conf) {
795832
returningAttributes = new String[] {
796833
groupNameAttr, posixUidAttr, posixGidAttr};
797834
}
798-
SEARCH_CONTROLS.setReturningAttributes(returningAttributes);
835+
836+
// If custom group filter is being used, fetch attributes in the filter
837+
// as well.
838+
ArrayList<String> customAttributes = new ArrayList<>();
839+
if (groupSearchFilterParams != null) {
840+
customAttributes.addAll(Arrays.asList(groupSearchFilterParams));
841+
}
842+
customAttributes.addAll(Arrays.asList(returningAttributes));
843+
SEARCH_CONTROLS
844+
.setReturningAttributes(customAttributes.toArray(new String[0]));
799845

800846
// LDAP_CTX_FACTORY_CLASS_DEFAULT is not open to unnamed modules
801847
// in Java 11+, so the default value is set to null to avoid

hadoop-common-project/hadoop-common/src/main/resources/core-default.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,18 @@
585585
</description>
586586
</property>
587587

588+
<property>
589+
<name>hadoop.security.group.mapping.ldap.group.search.filter.pattern</name>
590+
<value></value>
591+
<description>
592+
Comma separated values that needs to be substituted in the group search
593+
filter during group lookup. The values are substituted in the order they
594+
appear in the list, the first value will replace {0} the second {1} and
595+
so on.
596+
</description>
597+
</property>
598+
599+
588600
<property>
589601
<name>hadoop.security.group.mapping.providers</name>
590602
<value></value>

hadoop-common-project/hadoop-common/src/site/markdown/GroupsMapping.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ This is the limit for each ldap query. If `hadoop.security.group.mapping.ldap.s
8585
`hadoop.security.group.mapping.ldap.base` configures how far to walk up the groups hierarchy when resolving groups.
8686
By default, with a limit of 0, in order to be considered a member of a group, the user must be an explicit member in LDAP. Otherwise, it will traverse the group hierarchy `hadoop.security.group.mapping.ldap.search.group.hierarchy.levels` levels up.
8787

88+
It is possible to have custom group search filters with different arguments using
89+
the configuration `hadoop.security.group.mapping.ldap.group.search.filter.pattern`, we can configure comma separated values here and the values configured will be fetched from the LDAP attributes and will be replaced in the group
90+
search filter in the order they appear here, say if the first entry here is uid, so uid will be fetched from the attributes and the value fetched
91+
will be used in place of {0} in the group search filter, similarly the second value configured will replace {1} and so on.
92+
93+
Note: If `hadoop.security.group.mapping.ldap.group.search.filter.pattern` is configured, the group search will always be done assuming this group
94+
search filter pattern irrespective of any other parameters.
95+
8896
### Bind user(s) ###
8997
If the LDAP server does not support anonymous binds,
9098
set the distinguished name of the user to bind in `hadoop.security.group.mapping.ldap.bind.user`.

0 commit comments

Comments
 (0)