Uploaded image for project: 'Apache Submarine'
  1. Apache Submarine
  2. SUBMARINE-487

submarine-spark-security: JNA does not work in uber jar

    XMLWordPrintableJSON

Details

    Description

      In order to create a uber jar, Java JNA packages are being renamed. Renaming JNA packages makes JNI fail.

       
      1. ranger-plugins-common requires JNA through com.kstruct:gethostname4j
          See the following code: https://github.com/apache/ranger/blob/release-ranger-2.0.0/agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTUtils.java#L83

      2. gethostname4j uses JNA, through net.java.dev.jna:jna
          See the followingcode: https://github.com/mattsheppard/gethostname4j/blob/master/src/main/java/com/kstruct/gethostname4j/Hostname.java#L30

      3. net.java.dev.jna:jna uses JNI
          See the following code: https://github.com/java-native-access/jna/blob/master/src/com/sun/jna/Native.java#L1018

      4. The native library used by net.java.dev.jna:jna is libjnidispatch.so.
          libjnidispatch.so was compiled with the package com.sun.jna (example for linux-x86-64):

      readelf -aW libjnidispatch.so | grep Java_com_sun_jna_Native_getNativeVersion
         178: 000000000000bde0    24 FUNC    GLOBAL DEFAULT   12 Java_com_sun_jna_Native_getNativeVersion
         227: 000000000000bde0    24 FUNC    GLOBAL DEFAULT   12 Java_com_sun_jna_Native_getNativeVersion
      

       

      Because maven-shade-plugin is renaming JNA packages, JNA fails when trying to call the native method getNativeVersion (which is always called when using JNA for the first time):

      Exception in thread "HiveServer2-Handler-Pool: Thread-81" java.lang.UnsatisfiedLinkError: submarine_spark_ranger_project.com.sun.jna.Native.getNativeVersion()Ljava/lang/String;
          at submarine_spark_ranger_project.com.sun.jna.Native.getNativeVersion(Native Method)
          at submarine_spark_ranger_project.com.sun.jna.Native.<clinit>(Native.java:197)
          at submarine_spark_ranger_project.com.kstruct.gethostname4j.Hostname$UnixCLibrary.<clinit>(Hostname.java:12)
          at submarine_spark_ranger_project.com.kstruct.gethostname4j.Hostname.getHostname(Hostname.java:30)
          at org.apache.ranger.plugin.util.RangerRESTUtil
      

      Attachments

        Issue Links

          Activity

            People

              gumartinm Gustavo Martin
              gumartinm Gustavo Martin
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: