|
@@ -21,8 +21,6 @@ import static org.apache.hadoop.yarn.service.utils.ServiceApiUtil.jsonSerDeser;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URI;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.security.PrivilegedExceptionAction;
|
|
|
import java.text.MessageFormat;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -40,13 +38,12 @@ import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
-import org.apache.hadoop.security.authentication.client.AuthenticationException;
|
|
|
-import org.apache.hadoop.security.authentication.util.KerberosUtil;
|
|
|
import org.apache.hadoop.yarn.api.ApplicationConstants;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationReport;
|
|
|
import org.apache.hadoop.yarn.client.api.AppAdminClient;
|
|
|
import org.apache.hadoop.yarn.client.api.YarnClient;
|
|
|
+import org.apache.hadoop.yarn.client.util.YarnClientUtils;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
|
|
import org.apache.hadoop.yarn.service.api.records.Component;
|
|
@@ -60,11 +57,6 @@ import org.apache.hadoop.yarn.service.conf.RestApiConstants;
|
|
|
import org.apache.hadoop.yarn.service.utils.ServiceApiUtil;
|
|
|
import org.apache.hadoop.yarn.util.RMHAUtils;
|
|
|
import org.eclipse.jetty.util.UrlEncoded;
|
|
|
-import org.ietf.jgss.GSSContext;
|
|
|
-import org.ietf.jgss.GSSException;
|
|
|
-import org.ietf.jgss.GSSManager;
|
|
|
-import org.ietf.jgss.GSSName;
|
|
|
-import org.ietf.jgss.Oid;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
@@ -92,54 +84,6 @@ public class ApiServiceClient extends AppAdminClient {
|
|
|
super.serviceInit(configuration);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Generate SPNEGO challenge request token.
|
|
|
- *
|
|
|
- * @param server - hostname to contact
|
|
|
- * @throws IOException
|
|
|
- * @throws InterruptedException
|
|
|
- */
|
|
|
- String generateToken(String server) throws IOException, InterruptedException {
|
|
|
- UserGroupInformation currentUser = UserGroupInformation.getCurrentUser();
|
|
|
- LOG.debug("The user credential is {}", currentUser);
|
|
|
- String challenge = currentUser
|
|
|
- .doAs(new PrivilegedExceptionAction<String>() {
|
|
|
- @Override
|
|
|
- public String run() throws Exception {
|
|
|
- try {
|
|
|
- // This Oid for Kerberos GSS-API mechanism.
|
|
|
- Oid mechOid = KerberosUtil.getOidInstance("GSS_KRB5_MECH_OID");
|
|
|
- GSSManager manager = GSSManager.getInstance();
|
|
|
- // GSS name for server
|
|
|
- GSSName serverName = manager.createName("HTTP@" + server,
|
|
|
- GSSName.NT_HOSTBASED_SERVICE);
|
|
|
- // Create a GSSContext for authentication with the service.
|
|
|
- // We're passing client credentials as null since we want them to
|
|
|
- // be read from the Subject.
|
|
|
- GSSContext gssContext = manager.createContext(
|
|
|
- serverName.canonicalize(mechOid), mechOid, null,
|
|
|
- GSSContext.DEFAULT_LIFETIME);
|
|
|
- gssContext.requestMutualAuth(true);
|
|
|
- gssContext.requestCredDeleg(true);
|
|
|
- // Establish context
|
|
|
- byte[] inToken = new byte[0];
|
|
|
- byte[] outToken = gssContext.initSecContext(inToken, 0,
|
|
|
- inToken.length);
|
|
|
- gssContext.dispose();
|
|
|
- // Base64 encoded and stringified token for server
|
|
|
- LOG.debug("Got valid challenge for host {}", serverName);
|
|
|
- return new String(BASE_64_CODEC.encode(outToken),
|
|
|
- StandardCharsets.US_ASCII);
|
|
|
- } catch (GSSException | IllegalAccessException
|
|
|
- | NoSuchFieldException | ClassNotFoundException e) {
|
|
|
- LOG.error("Error: {}", e);
|
|
|
- throw new AuthenticationException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- return challenge;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Calculate Resource Manager address base on working REST API.
|
|
|
*/
|
|
@@ -177,7 +121,7 @@ public class ApiServiceClient extends AppAdminClient {
|
|
|
.resource(sb.toString()).type(MediaType.APPLICATION_JSON);
|
|
|
if (useKerberos) {
|
|
|
String[] server = host.split(":");
|
|
|
- String challenge = generateToken(server[0]);
|
|
|
+ String challenge = YarnClientUtils.generateToken(server[0]);
|
|
|
builder.header(HttpHeaders.AUTHORIZATION, "Negotiate " +
|
|
|
challenge);
|
|
|
LOG.debug("Authorization: Negotiate {}", challenge);
|
|
@@ -289,7 +233,7 @@ public class ApiServiceClient extends AppAdminClient {
|
|
|
if (conf.get("hadoop.http.authentication.type").equals("kerberos")) {
|
|
|
try {
|
|
|
URI url = new URI(requestPath);
|
|
|
- String challenge = generateToken(url.getHost());
|
|
|
+ String challenge = YarnClientUtils.generateToken(url.getHost());
|
|
|
builder.header(HttpHeaders.AUTHORIZATION, "Negotiate " + challenge);
|
|
|
} catch (Exception e) {
|
|
|
throw new IOException(e);
|