Skip to content

Commit b933cb2

Browse files
snmvaughanHarshitGupta11
authored andcommitted
HDFS-16686. GetJournalEditServlet fails to authorize valid Kerberos request (apache#4724)
1 parent beee1bf commit b933cb2

File tree

4 files changed

+275
-165
lines changed

4 files changed

+275
-165
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/GetJournalEditServlet.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828
import javax.servlet.ServletContext;
2929
import javax.servlet.ServletException;
30-
import javax.servlet.http.HttpServlet;
3130
import javax.servlet.http.HttpServletRequest;
3231
import javax.servlet.http.HttpServletResponse;
3332

3433
import org.apache.commons.text.StringEscapeUtils;
34+
import org.apache.hadoop.hdfs.server.namenode.DfsServlet;
3535
import org.slf4j.Logger;
3636
import org.slf4j.LoggerFactory;
3737
import org.apache.hadoop.classification.InterfaceAudience;
@@ -64,7 +64,7 @@
6464
* </ul>
6565
*/
6666
@InterfaceAudience.Private
67-
public class GetJournalEditServlet extends HttpServlet {
67+
public class GetJournalEditServlet extends DfsServlet {
6868

6969
private static final long serialVersionUID = -4635891628211723009L;
7070
private static final Logger LOG =
@@ -77,17 +77,11 @@ public class GetJournalEditServlet extends HttpServlet {
7777

7878
protected boolean isValidRequestor(HttpServletRequest request, Configuration conf)
7979
throws IOException {
80-
String remotePrincipal = request.getUserPrincipal().getName();
81-
String remoteShortName = request.getRemoteUser();
82-
if (remotePrincipal == null) { // This really shouldn't happen...
83-
LOG.warn("Received null remoteUser while authorizing access to " +
84-
"GetJournalEditServlet");
85-
return false;
86-
}
80+
UserGroupInformation ugi = getUGI(request, conf);
8781

8882
if (LOG.isDebugEnabled()) {
89-
LOG.debug("Validating request made by " + remotePrincipal +
90-
" / " + remoteShortName + ". This user is: " +
83+
LOG.debug("Validating request made by " + ugi.getUserName() +
84+
" / " + ugi.getShortUserName() + ". This user is: " +
9185
UserGroupInformation.getLoginUser());
9286
}
9387

@@ -115,26 +109,26 @@ protected boolean isValidRequestor(HttpServletRequest request, Configuration con
115109
for (String v : validRequestors) {
116110
if (LOG.isDebugEnabled())
117111
LOG.debug("isValidRequestor is comparing to valid requestor: " + v);
118-
if (v != null && v.equals(remotePrincipal)) {
112+
if (v != null && v.equals(ugi.getUserName())) {
119113
if (LOG.isDebugEnabled())
120-
LOG.debug("isValidRequestor is allowing: " + remotePrincipal);
114+
LOG.debug("isValidRequestor is allowing: " + ugi.getUserName());
121115
return true;
122116
}
123117
}
124118

125119
// Additionally, we compare the short name of the requestor to this JN's
126120
// username, because we want to allow requests from other JNs during
127121
// recovery, but we can't enumerate the full list of JNs.
128-
if (remoteShortName.equals(
122+
if (ugi.getShortUserName().equals(
129123
UserGroupInformation.getLoginUser().getShortUserName())) {
130124
if (LOG.isDebugEnabled())
131125
LOG.debug("isValidRequestor is allowing other JN principal: " +
132-
remotePrincipal);
126+
ugi.getUserName());
133127
return true;
134128
}
135129

136130
if (LOG.isDebugEnabled())
137-
LOG.debug("isValidRequestor is rejecting: " + remotePrincipal);
131+
LOG.debug("isValidRequestor is rejecting: " + ugi.getUserName());
138132
return false;
139133
}
140134

0 commit comments

Comments
 (0)