[ 
https://issues.apache.org/jira/browse/HIVE-21783?focusedWorklogId=249811&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-249811
 ]

ASF GitHub Bot logged work on HIVE-21783:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 29/May/19 04:44
            Start Date: 29/May/19 04:44
    Worklog Time Spent: 10m 
      Work Description: ashutosh-bapat commented on pull request #648: 
HIVE-21783: Accept Hive connections from the same domain without authentication.
URL: https://github.com/apache/hive/pull/648#discussion_r288391312
 
 

 ##########
 File path: service/src/java/org/apache/hive/service/auth/PlainSaslHelper.java
 ##########
 @@ -75,6 +89,70 @@ private PlainSaslHelper() {
     throw new UnsupportedOperationException("Can't initialize class");
   }
 
+  public static final class DualSaslTransportFactory extends TTransportFactory 
{
+    TTransportFactory otherFactory;
+    TTransportFactory noAuthFactory;
+    String hiveHost;
+
+    public DualSaslTransportFactory(TTransportFactory otherFactory, String 
hiveHost)
+            throws LoginException {
+      this.noAuthFactory = 
getPlainTransportFactory(AuthMethods.NONE.toString());
+      this.otherFactory = otherFactory;
+      this.hiveHost = hiveHost;
+    }
+
+    // Return true if the IP address is from the same domain as the server.
+    private boolean isSameDomainConnection(InetAddress remoteInetAddress) {
+      String[] hiveHostSplit = null;
+      if (hiveHost != null) {
+        hiveHostSplit = hiveHost.split("\\.");
+      }
+
+      String clientHostName = remoteInetAddress.getCanonicalHostName();
+      String[] clientHostSplit = null;
+      if (clientHostName != null) {
+        clientHostSplit = clientHostName.split("\\.");
+      }
+
+      // TODO: the callers should also pass the server address or obtain in by 
using some other
+      //  method. Then check whether the connection's remote address is from 
the same domain as
+      //  the server. For now, for the sake of testing, return true. We need 
to understand what
+      //  exactly it means to have connection from the same domain.
+      // For now, two hosts are in the same domain if the last two parts in 
their hostname are same.
+      if (hiveHostSplit.length >= 2 && clientHostSplit.length >= 2) {
+        if (hiveHostSplit[0] != null && 
hiveHostSplit[0].equalsIgnoreCase(clientHostSplit[0]) &&
+            hiveHostSplit[1] != null && 
hiveHostSplit[1].equalsIgnoreCase(clientHostSplit[1])) {
+          return true;
+        }
+      }
+
+      return false;
+    }
+
+    @Override
+    public TTransport getTransport(final TTransport trans) {
+      TSocket tSocket = null;
+      // Attempt to avoid authentication if only we can fetch the client IP 
address and it
+      // happens to be from the same domain as the server.
+      if (trans instanceof TSocket) {
+        tSocket = (TSocket) trans;
+      } else if (trans instanceof TSaslServerTransport) {
+        TSaslServerTransport saslTrans = (TSaslServerTransport) trans;
+        tSocket = (TSocket)(saslTrans.getUnderlyingTransport());
+      }
+      InetAddress remoteAddress = tSocket != null ? 
tSocket.getSocket().getInetAddress() : null;
+      if (remoteAddress != null && isSameDomainConnection(remoteAddress)) {
+        LOG.info("No authentication performed because the client connection is 
from the same " +
 
 Review comment:
   Thejas's comment: Add host name of remoteAddress also in the LOG.info output.
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 249811)
    Time Spent: 50m  (was: 40m)

> Avoid authentication for connection from the same domain
> --------------------------------------------------------
>
>                 Key: HIVE-21783
>                 URL: https://issues.apache.org/jira/browse/HIVE-21783
>             Project: Hive
>          Issue Type: New Feature
>          Components: HiveServer2
>            Reporter: Ashutosh Bapat
>            Assignee: Ashutosh Bapat
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> When a connection comes from the same domain do not authenticate the user. 
> This is similar to NONE authentication but only for the connection from the 
> same domain.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to