|
@@ -17,6 +17,11 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.hdfs.server.namenode;
|
|
|
|
|
|
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_KRB_HTTPS_USER_NAME_KEY;
|
|
|
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_USER_NAME_KEY;
|
|
|
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_SECONDARY_NAMENODE_KRB_HTTPS_USER_NAME_KEY;
|
|
|
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_SECONDARY_NAMENODE_USER_NAME_KEY;
|
|
|
+
|
|
|
import java.io.IOException;
|
|
|
import java.security.PrivilegedExceptionAction;
|
|
|
import java.util.Map;
|
|
@@ -27,10 +32,12 @@ import javax.servlet.http.HttpServlet;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import org.apache.commons.logging.Log;
|
|
|
+import org.apache.commons.logging.LogFactory;
|
|
|
+import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.apache.hadoop.util.StringUtils;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* This class is used in Namesystem's jetty to retrieve a file.
|
|
|
* Typically used by the Secondary NameNode to retrieve image and
|
|
@@ -38,7 +45,7 @@ import org.apache.hadoop.util.StringUtils;
|
|
|
*/
|
|
|
public class GetImageServlet extends HttpServlet {
|
|
|
private static final long serialVersionUID = -7669068179452648952L;
|
|
|
-
|
|
|
+ private static final Log LOG = LogFactory.getLog(GetImageServlet.class);
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public void doGet(final HttpServletRequest request,
|
|
|
final HttpServletResponse response
|
|
@@ -48,6 +55,16 @@ public class GetImageServlet extends HttpServlet {
|
|
|
ServletContext context = getServletContext();
|
|
|
final FSImage nnImage = (FSImage)context.getAttribute("name.system.image");
|
|
|
final TransferFsImage ff = new TransferFsImage(pmap, request, response);
|
|
|
+ Configuration conf = (Configuration)getServletContext().getAttribute("name.conf");
|
|
|
+ if(UserGroupInformation.isSecurityEnabled() &&
|
|
|
+ !isValidRequestor(request.getRemoteUser(), conf)) {
|
|
|
+ response.sendError(HttpServletResponse.SC_FORBIDDEN,
|
|
|
+ "Only Namenode and Secondary Namenode may access this servlet");
|
|
|
+ LOG.warn("Received non-NN/SNN request for image or edits from "
|
|
|
+ + request.getRemoteHost());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
UserGroupInformation.getCurrentUser().doAs(new PrivilegedExceptionAction<Void>() {
|
|
|
|
|
|
@Override
|
|
@@ -79,4 +96,25 @@ public class GetImageServlet extends HttpServlet {
|
|
|
response.getOutputStream().close();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private boolean isValidRequestor(String remoteUser, Configuration conf) {
|
|
|
+ if(remoteUser == null) { // This really shouldn't happen...
|
|
|
+ LOG.warn("Received null remoteUser while authorizing access to getImage servlet");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ String [] validRequestors = {conf.get(DFS_NAMENODE_KRB_HTTPS_USER_NAME_KEY),
|
|
|
+ conf.get(DFS_NAMENODE_USER_NAME_KEY),
|
|
|
+ conf.get(DFS_SECONDARY_NAMENODE_KRB_HTTPS_USER_NAME_KEY),
|
|
|
+ conf.get(DFS_SECONDARY_NAMENODE_USER_NAME_KEY) };
|
|
|
+
|
|
|
+ for(String v : validRequestors) {
|
|
|
+ if(v != null && v.equals(remoteUser)) {
|
|
|
+ if(LOG.isDebugEnabled()) LOG.debug("isValidRequestor is allowing: " + remoteUser);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(LOG.isDebugEnabled()) LOG.debug("isValidRequestor is rejecting: " + remoteUser);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|