You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@linkis.apache.org by GitBox <gi...@apache.org> on 2021/10/28 02:44:30 UTC

[GitHub] [incubator-linkis] wpfysztqx opened a new pull request #1051: Supprort request spnego enabled Yarn resource restful interface When Yarn enable kerberos

wpfysztqx opened a new pull request #1051:
URL: https://github.com/apache/incubator-linkis/pull/1051


   Problem Description:
   The company's big data platform environment is HDP, and Kerberos is enabled. By default, it cannot directly access http://xx.xx.xx.xx:8088 of yarn. When I use spark engine, the Existing certification methods can not meet the requirements and always report errors
   
   Solution:
   add utils to solution of httpclient requets to request kerberos web


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org
For additional commands, e-mail: dev-help@linkis.apache.org


[GitHub] [incubator-linkis] peacewong commented on a change in pull request #1051: Supprort request spnego enabled Yarn resource restful interface When Yarn enable kerberos

Posted by GitBox <gi...@apache.org>.
peacewong commented on a change in pull request #1051:
URL: https://github.com/apache/incubator-linkis/pull/1051#discussion_r744448784



##########
File path: linkis-computation-governance/linkis-manager/linkis-resource-manager/src/main/java/org/apache/linkis/resourcemanager/utils/RequestKerberosUrlUtils.java
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.resourcemanager.utils;
+
+
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthSchemeProvider;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.AuthSchemes;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.config.Lookup;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.impl.auth.SPNegoSchemeFactory;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.security.auth.Subject;
+import javax.security.auth.kerberos.KerberosPrincipal;
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.Configuration;
+import javax.security.auth.login.LoginContext;
+import java.io.IOException;
+import java.security.Principal;
+import java.security.PrivilegedAction;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+public class RequestKerberosUrlUtils {
+    public static Logger logger = LoggerFactory.getLogger(RequestKerberosUrlUtils.class);
+    private String principal;
+    private String keyTabLocation;
+
+
+    public RequestKerberosUrlUtils(String principal, String keyTabLocation) {
+        super();
+        this.principal = principal;
+        this.keyTabLocation = keyTabLocation;
+    }
+
+    public RequestKerberosUrlUtils(String principal, String keyTabLocation, boolean isDebug) {
+        this(principal, keyTabLocation);
+        if (isDebug) {
+            System.setProperty("sun.security.spnego.debug", "true");
+            System.setProperty("sun.security.krb5.debug", "true");
+        }
+    }
+
+    public RequestKerberosUrlUtils(String principal, String keyTabLocation, String krb5Location, boolean isDebug) {
+        this(principal, keyTabLocation, isDebug);
+        System.setProperty("java.security.krb5.conf", krb5Location);
+    }
+
+    private static HttpClient buildSpengoHttpClient() {
+        HttpClientBuilder builder = HttpClientBuilder.create();
+        Lookup<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().
+                register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true)).build();
+        builder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
+        BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+        credentialsProvider.setCredentials(new AuthScope(null, -1, null), new Credentials() {
+            @Override
+            public Principal getUserPrincipal() {
+                return null;
+            }
+
+            @Override
+            public String getPassword() {
+                return null;
+            }
+        });
+        builder.setDefaultCredentialsProvider(credentialsProvider);
+        CloseableHttpClient httpClient = builder.build();
+        return httpClient;
+    }
+
+    public HttpResponse callRestUrl(final String url, final String userId) {
+        logger.warn(String.format("Calling KerberosHttpClient %s %s %s", this.principal, this.keyTabLocation, url));
+        Configuration config = new Configuration() {
+            @SuppressWarnings("serial")
+            @Override
+            public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
+                return new AppConfigurationEntry[]{new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
+                        AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, new HashMap<String, Object>() {
+                    {
+                        put("useTicketCache", "false");
+                        put("useKeyTab", "true");
+                        put("keyTab", keyTabLocation);
+                        put("refreshKrb5Config", "true");
+                        put("principal", principal);
+                        put("storeKey", "true");
+                        put("doNotPrompt", "true");
+                        put("isInitiator", "true");
+                        put("debug", "false");
+                    }
+                })};
+            }
+        };
+        Set<Principal> princ = new HashSet<Principal>(1);
+        princ.add(new KerberosPrincipal(userId));
+        Subject sub = new Subject(false, princ, new HashSet<Object>(), new HashSet<Object>());
+        try {
+            LoginContext lc = new LoginContext("Krb5Login", sub, null, config);
+            lc.login();
+            Subject serviceSubject = lc.getSubject();
+            return Subject.doAs(serviceSubject, new PrivilegedAction<HttpResponse>() {
+                HttpResponse httpResponse = null;
+
+                @Override
+                public HttpResponse run() {
+                    try {
+                        HttpUriRequest request = new HttpGet(url);
+                        HttpClient spnegoHttpClient = buildSpengoHttpClient();
+                        httpResponse = spnegoHttpClient.execute(request);
+                        return httpResponse;
+                    } catch (IOException ioe) {
+                        ioe.printStackTrace();
+                    }
+                    return httpResponse;
+                }
+            });
+        } catch (Exception le) {
+            le.printStackTrace();

Review comment:
       Log should be used here instead of print directly

##########
File path: linkis-computation-governance/linkis-manager/linkis-resource-manager/src/main/scala/org/apache/linkis/resourcemanager/external/yarn/YarnResourceRequester.scala
##########
@@ -212,8 +213,20 @@ class YarnResourceRequester extends ExternalResourceRequester with Logging {
     httpGet.addHeader("Accept", "application/json")
     if (this.provider.getConfigMap.get("authorEnable").asInstanceOf[Boolean])
       httpGet.addHeader(HttpHeaders.AUTHORIZATION, "Basic " + getAuthorizationStr)
-    val response = YarnResourceRequester.httpClient.execute(httpGet)
-    parse(EntityUtils.toString(response.getEntity()))
+    var httpResponse: HttpResponse = null
+    if(this.provider.getConfigMap.get("kerberosEnable") != null
+      && this.provider.getConfigMap.get("kerberosEnable").asInstanceOf[Boolean]){
+      val principalName = this.provider.getConfigMap.get("principalName").asInstanceOf[String]

Review comment:
       Do you need to consider the case where the parameter is empty?

##########
File path: db/linkis_dml.sql
##########
@@ -216,7 +216,7 @@ INNER JOIN linkis_cg_manager_label label ON relation.engine_type_label_id = labe
 
 
 insert  into `linkis_cg_rm_external_resource_provider`(`id`,`resource_type`,`name`,`labels`,`config`) values
-(1,'Yarn','sit',NULL,'{\r\n\"rmWebAddress\": \"@YARN_RESTFUL_URL\",\r\n\"hadoopVersion\": \"2.7.2\",\r\n\"authorEnable\":false,\r\n\"user\":\"hadoop\",\r\n\"pwd\":\"123456\"\r\n}');

Review comment:
       Does the installation need to adjust and modify these parameters?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org
For additional commands, e-mail: dev-help@linkis.apache.org


[GitHub] [incubator-linkis] peacewong merged pull request #1051: Supprort request spnego enabled Yarn resource restful interface When Yarn enable kerberos

Posted by GitBox <gi...@apache.org>.
peacewong merged pull request #1051:
URL: https://github.com/apache/incubator-linkis/pull/1051


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org
For additional commands, e-mail: dev-help@linkis.apache.org


[GitHub] [incubator-linkis] peacewong commented on a change in pull request #1051: Supprort request spnego enabled Yarn resource restful interface When Yarn enable kerberos

Posted by GitBox <gi...@apache.org>.
peacewong commented on a change in pull request #1051:
URL: https://github.com/apache/incubator-linkis/pull/1051#discussion_r740689699



##########
File path: linkis-computation-governance/linkis-manager/linkis-resource-manager/src/main/java/org/apache/linkis/resourcemanager/utils/RequestKerberosUrlUtils.java
##########
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2019 WeBank
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at

Review comment:
       The license needs to be modified to apache format




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org
For additional commands, e-mail: dev-help@linkis.apache.org


[GitHub] [incubator-linkis] peacewong commented on a change in pull request #1051: Supprort request spnego enabled Yarn resource restful interface When Yarn enable kerberos

Posted by GitBox <gi...@apache.org>.
peacewong commented on a change in pull request #1051:
URL: https://github.com/apache/incubator-linkis/pull/1051#discussion_r740689699



##########
File path: linkis-computation-governance/linkis-manager/linkis-resource-manager/src/main/java/org/apache/linkis/resourcemanager/utils/RequestKerberosUrlUtils.java
##########
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2019 WeBank
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at

Review comment:
       The license needs to be modified to apache format




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org
For additional commands, e-mail: dev-help@linkis.apache.org


[GitHub] [incubator-linkis] wpfysztqx commented on a change in pull request #1051: Supprort request spnego enabled Yarn resource restful interface When Yarn enable kerberos

Posted by GitBox <gi...@apache.org>.
wpfysztqx commented on a change in pull request #1051:
URL: https://github.com/apache/incubator-linkis/pull/1051#discussion_r740732782



##########
File path: linkis-computation-governance/linkis-manager/linkis-resource-manager/src/main/java/org/apache/linkis/resourcemanager/utils/RequestKerberosUrlUtils.java
##########
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2019 WeBank
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at

Review comment:
       Hi Wang!
    I have modified it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org
For additional commands, e-mail: dev-help@linkis.apache.org


[GitHub] [incubator-linkis] wpfysztqx commented on a change in pull request #1051: Supprort request spnego enabled Yarn resource restful interface When Yarn enable kerberos

Posted by GitBox <gi...@apache.org>.
wpfysztqx commented on a change in pull request #1051:
URL: https://github.com/apache/incubator-linkis/pull/1051#discussion_r740732782



##########
File path: linkis-computation-governance/linkis-manager/linkis-resource-manager/src/main/java/org/apache/linkis/resourcemanager/utils/RequestKerberosUrlUtils.java
##########
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2019 WeBank
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at

Review comment:
       Hi Wang!
    I have modified it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org
For additional commands, e-mail: dev-help@linkis.apache.org


[GitHub] [incubator-linkis] wpfysztqx commented on a change in pull request #1051: Supprort request spnego enabled Yarn resource restful interface When Yarn enable kerberos

Posted by GitBox <gi...@apache.org>.
wpfysztqx commented on a change in pull request #1051:
URL: https://github.com/apache/incubator-linkis/pull/1051#discussion_r748708526



##########
File path: linkis-computation-governance/linkis-manager/linkis-resource-manager/src/main/scala/org/apache/linkis/resourcemanager/external/yarn/YarnResourceRequester.scala
##########
@@ -212,8 +213,20 @@ class YarnResourceRequester extends ExternalResourceRequester with Logging {
     httpGet.addHeader("Accept", "application/json")
     if (this.provider.getConfigMap.get("authorEnable").asInstanceOf[Boolean])
       httpGet.addHeader(HttpHeaders.AUTHORIZATION, "Basic " + getAuthorizationStr)
-    val response = YarnResourceRequester.httpClient.execute(httpGet)
-    parse(EntityUtils.toString(response.getEntity()))
+    var httpResponse: HttpResponse = null
+    if(this.provider.getConfigMap.get("kerberosEnable") != null
+      && this.provider.getConfigMap.get("kerberosEnable").asInstanceOf[Boolean]){
+      val principalName = this.provider.getConfigMap.get("principalName").asInstanceOf[String]

Review comment:
        If the parameter is empty, use the else method directly 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org
For additional commands, e-mail: dev-help@linkis.apache.org


[GitHub] [incubator-linkis] peacewong commented on a change in pull request #1051: Supprort request spnego enabled Yarn resource restful interface When Yarn enable kerberos

Posted by GitBox <gi...@apache.org>.
peacewong commented on a change in pull request #1051:
URL: https://github.com/apache/incubator-linkis/pull/1051#discussion_r740689699



##########
File path: linkis-computation-governance/linkis-manager/linkis-resource-manager/src/main/java/org/apache/linkis/resourcemanager/utils/RequestKerberosUrlUtils.java
##########
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2019 WeBank
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at

Review comment:
       The license needs to be modified to apache format




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org
For additional commands, e-mail: dev-help@linkis.apache.org


[GitHub] [incubator-linkis] wpfysztqx commented on a change in pull request #1051: Supprort request spnego enabled Yarn resource restful interface When Yarn enable kerberos

Posted by GitBox <gi...@apache.org>.
wpfysztqx commented on a change in pull request #1051:
URL: https://github.com/apache/incubator-linkis/pull/1051#discussion_r740732782



##########
File path: linkis-computation-governance/linkis-manager/linkis-resource-manager/src/main/java/org/apache/linkis/resourcemanager/utils/RequestKerberosUrlUtils.java
##########
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2019 WeBank
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at

Review comment:
       Hi Wang!
    I have modified it.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@linkis.apache.org
For additional commands, e-mail: dev-help@linkis.apache.org