Apache Ranger provides a centralized permission management framework. When integrated with Spark, the Ranger Plugin enables fine-grained access control over Spark SQL access to resources such as databases, tables, and columns, enhancing data security.
Prerequisites
You have created a Livy Gateway. For more information, see Gateway Management.
The following engine versions are recommended:
-
esr-4.x: esr-4.3.0 or later.
-
esr-3.x: esr-3.3.0 or later.
-
esr-2.x: esr-2.7.0 or later.
Usage notes
Ranger primarily provides authorization, while user authentication requires an authentication service such as LDAP. For more information, see Configure and enable LDAP authentication for a Livy Gateway.
Procedure
Step 1: Prepare the network
Before you begin, you must configure the network to ensure connectivity between Serverless Spark and your Virtual Private Cloud (VPC). This allows the Ranger Plugin to connect to your Ranger Admin service and retrieve permission information. For more information, see Interconnect EMR Serverless Spark with other VPCs.
Step 2: Configure Ranger Plugin
To enable Ranger authorization for a Livy Gateway, you must first stop the gateway and then add the following configurations.
-
From the Normal Network Connection drop-down list, select the name of the connection that you created.
-
In livy.conf, add the following configuration:
livy.impersonation.enabled true -
In spark-defaults.conf, add the following configurations:
spark.ranger.plugin.enabled true spark.emr.serverless.user.defined.jars /opt/ranger/ranger-spark.jar ranger.plugin.spark.policy.rest.url http://<ranger_admin_ip>:<ranger_admin_port>The following table describes the parameters.
Parameter
Description
spark.ranger.plugin.enabledSet this to
trueto enable Ranger authorization.spark.emr.serverless.user.defined.jarsThe path to a custom JAR file.
Set this to
/opt/ranger/ranger-spark.jarto use the Ranger Plugin included with Serverless Spark.ranger.plugin.spark.policy.rest.urlThe address of the Ranger Admin service. The format is
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 are connecting to the Ranger service on an EMR on ECS cluster, set<ranger_admin_ip>to the internal IP address of the master node and<ranger_admin_port>to 6080. -
After you finish editing, restart the gateway to apply the configuration changes.
Step 3: (Optional) Configure Ranger Audit
You can configure Ranger to send audit information to storage destinations such as Solr and HDFS. By default, Ranger Audit is disabled in Serverless Spark. To enable this feature, add the required Ranger Audit parameters in Spark Configuration.
For example, to configure a connection to Solr on EMR, add the following properties in Spark Configuration.
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 storing audit information 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 based on your actual requirements. -
xasecure.audit.destination.solr.userandxasecure.audit.destination.solr.password: If Basic Authentication is enabled for the Solr service, provide the username and password.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, andxasecure.audit.destination.solr.passwordin the ranger-spark-audit.xml configuration file of the Ranger-plugin service.
After the configuration is complete, you can submit a job on EMR Serverless Spark, navigate to the Ranger UI, and view user access audit information on the Access tab in Ranger Audit. For information about how to access the Ranger UI, see Access the web UI for open-source components from the console.
You can view audit information in the Ranger UI only if Solr is configured as the storage destination. If audit information is stored in other destinations, such as HDFS, it is not visible in the Ranger UI.

Step 4: Test connection
Use a Jupyter Notebook to test the connection. If you attempt to access a database, table, or other resource for which you do not have permissions, a Permission denied message is returned.
-
When you test permissions, note the default permission policies added by Ranger. For example, by default, all users can switch between and create databases, and resource owners have all permissions on their resources. As a best practice, have one user (User A) create resources, such as databases and tables, and have another user (User B) validate the permissions. If you use the same user to perform both actions, the owner's default permissions may lead you to incorrectly conclude that your custom permission settings are not effective.
-
If the Ranger Admin service is misconfigured, SQL queries might run successfully without returning a permission error, but the access control policies are not actually enforced.