All Products
Search
Document Center

E-MapReduce:Enable Ranger authorization for a Spark Thrift server

Last Updated:Oct 10, 2026

The Ranger plugin enables fine-grained access control for Spark SQL queries on databases, tables, and columns. You can configure the Ranger plugin for your Spark Thrift server sessions to enforce authorization policies managed in Ranger Admin.

Limitations

Supported Serverless Spark engine versions:

  • esr-4.x: esr-4.2.0 and later

  • esr-3.x: esr-3.0.1 and later

  • esr-2.x: esr-2.4.1 and later

Usage notes

Ranger handles authorization only. Identity authentication requires a separate service such as LDAP. For more information, see Configure and enable LDAP authentication for a Spark Thrift server.

Prerequisites

You have created a Spark Thrift server session. For more information, see Manage Spark Thrift server sessions.

Procedure

Step 1: Prepare the network

Ensure that Serverless Spark can communicate with your virtual private cloud (VPC) so the Ranger plugin can connect to Ranger Admin and retrieve authorization policies. For more information, see Establish network connectivity between EMR Serverless Spark and other VPCs.

Step 2: Configure the Ranger plugin

To enable Ranger authorization, first stop the Spark Thrift server session. From the Normal Network Connection drop-down list, select the network connection you created. Then, in the Spark Configuration section, add the following properties. Restart the session to apply the changes.

Option 1: Built-in Ranger plugin

spark.ranger.plugin.enabled                true
spark.jars                                 /opt/ranger/ranger-spark.jar
ranger.plugin.spark.policy.rest.url        http://<ranger_admin_ip>:<ranger_admin_port>

Replace <ranger_admin_ip> and <ranger_admin_port> with the internal IP address and port of your Ranger Admin service. If you connect to the Ranger service in an EMR on ECS cluster, you can use the internal IP address of the master node for <ranger_admin_ip> and 6080 for <ranger_admin_port>.

Option 2: Custom Ranger plugin

If you need to use a custom Ranger plugin, upload it to Object Storage Service (OSS) and use the following parameters to specify the custom JAR file and class name.

spark.jars                                 oss://<bucket>/path/to/user-ranger-spark.jar
spark.ranger.plugin.class                  <class_name>
spark.ranger.plugin.enabled                true
ranger.plugin.spark.policy.rest.url        http://<ranger_admin_ip>:<ranger_admin_port>

Replace the following placeholders with your actual information:

  • spark.jars: The OSS path to your custom JAR file.

  • spark.ranger.plugin.class: The name of the Spark extension class in your custom Ranger plugin.

  • <ranger_admin_ip> and <ranger_admin_port>: The internal IP address and port of your Ranger Admin service. If you connect to the Ranger service in an EMR on ECS cluster, you can use the internal IP address of the master node for <ranger_admin_ip> and 6080 for <ranger_admin_port>.

Step 3: (Optional) Configure Ranger Audit

Ranger supports different storage backends for audit records, such as Solr and HDFS. By default, Ranger Audit is disabled in Serverless Spark. To enable it, add the relevant Ranger Audit parameters in the Spark Configuration section.

For example, to configure a connection to Solr on an EMR cluster, add the following properties to the Spark Configuration section.

xasecure.audit.is.enabled                  true
xasecure.audit.destination.solr            true
xasecure.audit.destination.solr.urls       http://<solr_ip>:<solr_port>/solr/ranger_audits
xasecure.audit.destination.solr.user       <user>
xasecure.audit.destination.solr.password   <password>

Parameters:

  • xasecure.audit.is.enabled: Enables or disables Ranger Audit.

  • xasecure.audit.destination.solr: Enables or disables storing audit records in Solr.

  • xasecure.audit.destination.solr.urls: The URL of the Solr service. Replace <solr_ip> and <solr_port> with the IP address and port of your Solr service. Configure the rest of the URL as needed.

  • xasecure.audit.destination.solr.user and xasecure.audit.destination.solr.password: The username and password for Solr, required if basic authentication is enabled.

    If you connect to Ranger in an EMR on ECS cluster, you can find the values for xasecure.audit.destination.solr.urls, xasecure.audit.destination.solr.user, and xasecure.audit.destination.solr.password in the ranger-spark-audit.xml configuration file of the Ranger-plugin service.

    image

After configuration, you can submit jobs on EMR Serverless Spark and view user access audit records on the Access tab in the Ranger web UI. For more information, see Access the web UIs of open source components in the console.

Note

These records will not be visible in the Ranger web UI if you use HDFS or another unsupported backend.

image

Step 4: Test connectivity

When you connect with Beeline, accessing a database, table, or other resource without proper authorization triggers a permission error.

0: jdbc:hive2://pre-emr-spark-gateway-cn-hang> create table test(id int);
Error: org.apache.hive.service.cli.HiveSQLException: Error running query: org.apache.kyuubi.plugin.spark.authz.AccessControlException: Permission denied: user [test] does not have [create] privilege on [database=testdb/table=test]
	at org.apache.spark.sql.hive.thriftserver.HiveThriftServerErrors$.runningQueryError(HiveThriftServerErrors.scala:44)
	at org.apache.spark.sql.hive.thriftserver.SparkExecuteStatementOperation.org$apache$spark$sql$hive$thriftserver$SparkExecuteStatementOperation$$execute(SparkExecuteStatementOperation.scala:325)
	at org.apache.spark.sql.hive.thriftserver.SparkExecuteStatementOperation$$anon$2$$anon$3.$anonfun$run$2(SparkExecuteStatementOperation.scala:230)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
	at org.apache.spark.sql.hive.thriftserver.SparkOperation.withLocalProperties(SparkOperation.scala:79)
	at org.apache.spark.sql.hive.thriftserver.SparkOperation.withLocalProperties$(SparkOperation.scala:63)
	at org.apache.spark.sql.hive.thriftserver.SparkExecuteStatementOperation.withLocalProperties(SparkExecuteStatementOperation.scala:43)
	at org.apache.spark.sql.hive.thriftserver.SparkExecuteStatementOperation$$anon$2$$anon$3.run(SparkExecuteStatementOperation.scala:230)
	at org.apache.spark.sql.hive.thriftserver.SparkExecuteStatementOperation$$anon$2$$anon$3.run(SparkExecuteStatementOperation.scala:225)
	at java.security.AccessController.doPrivileged(Native Method)
	at javax.security.auth.Subject.doAs(Subject.java:422)
	at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1730)
	at org.apache.spark.sql.hive.thriftserver.SparkExecuteStatementOperation$$anon$2.run(SparkExecuteStatementOperation.scala:239)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:750)
Note
  • When you test permissions, be aware of the default permission policies in Ranger. For example, by default, all users can switch and create databases, and the owner of a resource has all permissions on that resource. To perform a valid test, we recommend that you create resources, such as a database and a table, as User A and then try to access them as User B to verify the permissions. If you test with a single user, the owner permission policy might lead you to incorrectly conclude that your permission settings are ineffective.

  • If Ranger Admin is misconfigured, SQL statements might succeed without returning a permission error, meaning authorization is not being enforced.