Pre-install

  • Apache Ranger

    This plugin works as a ranger rest client with Apache Ranger admin server to do privilege check. Thus, a ranger server need to be installed ahead and available to use.

  • Building(optional)

    If your ranger admin or spark distribution is not compatible with the official pre-built artifact in maven central. You need to build the plugin targeting the spark/ranger you are using by yourself.

Install

Use either the shaded jar kyuubi-spark-authz-shaded_*.jar or the kyuubi-spark-authz_*.jar with its transitive dependencies available for spark runtime classpath, such as

  • Copied to $SPARK_HOME/jars, or
  • Specified to spark.jars configuration

Configure

Settings for Connecting Ranger Admin

ranger-spark-security.xml

  • Create ranger-spark-security.xml in $SPARK_HOME/conf and add the following configurations for pointing to the right Ranger admin server.
  1. <configuration>
  2. <property>
  3. <name>ranger.plugin.spark.policy.rest.url</name>
  4. <value>ranger admin address like http://ranger-admin.org:6080</value>
  5. </property>
  6. <property>
  7. <name>ranger.plugin.spark.service.name</name>
  8. <value>a ranger hive service name</value>
  9. </property>
  10. <property>
  11. <name>ranger.plugin.spark.policy.cache.dir</name>
  12. <value>./a ranger hive service name/policycache</value>
  13. </property>
  14. <property>
  15. <name>ranger.plugin.spark.policy.pollIntervalMs</name>
  16. <value>5000</value>
  17. </property>
  18. <property>
  19. <name>ranger.plugin.spark.policy.source.impl</name>
  20. <value>org.apache.ranger.admin.client.RangerAdminRESTClient</value>
  21. </property>
  22. </configuration>
Using Macros in Row Level Filters

Macros are now supported for using user/group/tag in row filter expressions, introduced in Ranger 2.3. This feature helps significantly simplify row filter expressions by using user/group/tag’s attributes instead of explicit conditions. Considering a user with an attribute born_city of value Guangzhou, the row filter condition as city='${{USER.born_city}}' will be transformed to city='Guangzhou' in execution plan. More supported macros and usage refer to RANGER-3605 and RANGER-3550. Add the following configs to ranger-spark-security.xml to enable UserStore Enricher required by macros.

  1. <property>
  2. <name>ranger.plugin.spark.enable.implicit.userstore.enricher</name>
  3. <value>true</value>
  4. <description>Enable UserStoreEnricher for fetching user and group attributes if using macros or scripts in row-filters since Ranger 2.3</description>
  5. </property>
  6. <property>
  7. <name>ranger.plugin.hive.policy.cache.dir</name>
  8. <value>./a ranger hive service name/policycache</value>
  9. <description>As Authz plugin reuses hive service def, a policy cache path is required for caching UserStore and Tags for "hive" service def, while "ranger.plugin.spark.policy.cache.dir config" is the path for caching policies in service. </description>
  10. </property>
Showing all disallowed privileges

By default, Authz plugin checks required privileges one by one and throw the first unsatisfied privilege in exception. By setting ranger.plugin.spark.authorize.in.single.call to true, Authz plugin executes access checks in single call and throws all disallowed privileges in exception message.

  1. <property>
  2. <name>ranger.plugin.spark.authorize.in.single.call</name>
  3. <value>true</value>
  4. <description>Enable access checks in single call with all disallowed privileges thrown in exception. Default value is false.</description>
  5. </property>

ranger-spark-audit.xml

Create ranger-spark-audit.xml in $SPARK_HOME/conf and add the following configurations to enable/disable auditing.

  1. <configuration>
  2. <property>
  3. <name>xasecure.audit.is.enabled</name>
  4. <value>true</value>
  5. </property>
  6. <property>
  7. <name>xasecure.audit.destination.db</name>
  8. <value>false</value>
  9. </property>
  10. <property>
  11. <name>xasecure.audit.destination.db.jdbc.driver</name>
  12. <value>com.mysql.jdbc.Driver</value>
  13. </property>
  14. <property>
  15. <name>xasecure.audit.destination.db.jdbc.url</name>
  16. <value>jdbc:mysql://10.171.161.78/ranger</value>
  17. </property>
  18. <property>
  19. <name>xasecure.audit.destination.db.password</name>
  20. <value>rangeradmin</value>
  21. </property>
  22. <property>
  23. <name>xasecure.audit.destination.db.user</name>
  24. <value>rangeradmin</value>
  25. </property>
  26. </configuration>

Settings for Spark Session Extensions

Add org.apache.kyuubi.plugin.spark.authz.ranger.RangerSparkExtension to the spark configuration spark.sql.extensions.

  1. spark.sql.extensions=org.apache.kyuubi.plugin.spark.authz.ranger.RangerSparkExtension