DataSunrise Achieves AWS DevOps Competency Status in AWS DevSecOps and Monitoring, Logging, Performance

Apache Hive RBAC Configuration with SQL

Apache Hive RBAC Configuration with SQL

Introduction

This guide addresses common Apache Hive Role-Based Access Control (RBAC) configuration with SQL issues, specifically focusing on the challenges encountered when setting up admin roles and permissions with SQL queries. We'll walk through a real-world example of troubleshooting and resolving these issues in a Docker-based Hive environment.

Understanding the Problem

Apache Hive RBAC Configuration with SQL - Error encountered when trying to SET ROLE in Apache Hive due to insufficient permissions for root
Error encountered when trying to SET ROLE in Apache Hive due to insufficient permissions for root

Common Error Messages

When attempting to configure RBAC in Hive with queries like:

SHOW ROLES;
SET ROLE admin;
CREATE ROLE test_role;
GRANT ROLE test_role TO USER tester;

For example, for role creation query you might encounter various error messages depending on your connection method:

JDBC Connection (e.g., DBeaver)

SQL Error [1] [08S01]: org.apache.hive.service.cli.HiveSQLException: Error while processing statement: 
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. 
Current user : root is not allowed to add roles. User has to belong to ADMIN role and have it as current role, for this action.
Apache Hive RBAC Configuration with SQL - Error encountered when trying to CREATE ROLE in Apache Hive due to insufficient permissions for root
Error encountered when trying to CREATE ROLE in Apache Hive due to insufficient permissions for root

Hive CLI (e.g. beeline or hive -e)

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. 
Failed to retrieve roles for null: Required field 'principal_name' is unset! 
Struct:GetRoleGrantsForPrincipalRequest(principal_name:null, principal_type:USER)
Apache Hive RBAC Configuration with SQL - Error encountered when trying to SET ROLE in Apache Hive CLI
Error encountered when trying to SET ROLE in Apache Hive CLI

Root Causes

The issues typically stem from:

  1. Incomplete authentication configuration
  2. Incorrect authorization provider settings
  3. Missing user-to-role mappings
  4. Improper service account permissions

Environment Setup for Apache Hive RBAC Configuration with SQL

Prerequisites

Before proceeding, ensure you have:

  • Administrative access to your Hive environment
  • Ability to modify Hive configuration files
  • Access to restart Hive services
  • Basic understanding of XML configuration files

Locating Configuration Files

First, locate your Hive configuration file hive-site.xml directory. You can run these commands to check the common locations:

ls /etc/hive/conf/hive-site.xml
ls /etc/hadoop/conf/hive-site.xml
ls /usr/lib/hive/conf/hive-site.xml
ls /opt/hive/conf/hive-site.xml
ls $HIVE_HOME/conf/hive-site.xml

Or run this command to find the correct location:

find / -name "hive-site.xml" 2>/dev/null

File Permission Requirements

Ensure proper file permissions:

ls -l /opt/hive/conf/hive-site.xml
# Should show something like:
# -rw-r--r-- 1 root root 3342 Jan 31 16:04 /opt/hive/conf/hive-site.xml

Step-by-Step Solution for Apache Hive RBAC Configuration with SQL

1. Backup Existing Configuration

Always create a backup before making changes:

cp /opt/hive/conf/hive-site.xml /opt/hive/conf/hive-site.xml.backup

2. Update hive-site.xml

Create a new configuration file with all necessary settings:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <!-- Metastore Connection -->
    <property>
        <name>hive.metastore.uris</name>
        <value>thrift://hive-metastore:9083</value>
    </property>

    <!-- Database Configuration -->
    <property>
        <name>datanucleus.autoCreateSchema</name>
        <value>false</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:postgresql://hive-metastore-postgresql/metastore</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionDriverName</name>
        <value>org.postgresql.Driver</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>hive</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>hive</value>
    </property>

    <!-- Authentication & Authorization Configuration -->
    <property>
        <name>hive.security.authorization.enabled</name>
        <value>true</value>
    </property>
    <property>
        <name>hive.server2.enable.doAs</name>
        <value>false</value>
    </property>
    <property>
        <name>hive.users.in.admin.role</name>
        <value>root</value>
    </property>
    <property>
        <name>hive.server2.authentication</name>
        <value>NONE</value>
    </property>
    <property>
        <name>hive.security.authorization.manager</name>
        <value>org.apache.hadoop.hive.ql.security.authorization.StorageBasedAuthorizationProvider</value>
    </property>
    <property>
        <name>hive.metastore.pre.event.listeners</name>
        <value>org.apache.hadoop.hive.ql.security.authorization.AuthorizationPreEventListener</value>
    </property>
    <property>
        <name>hive.security.metastore.authorization.manager</name>
        <value>org.apache.hadoop.hive.ql.security.authorization.StorageBasedAuthorizationProvider</value>
    </property>
    <property>
        <name>hive.security.authenticator.manager</name>
        <value>org.apache.hadoop.hive.ql.security.HadoopDefaultAuthenticator</value>
    </property>
    <property>
        <name>hive.metastore.execute.setugi</name>
        <value>true</value>
    </property>
</configuration>

3. Restart HiveServer2

# Find hiveserver2 location
which hiveserver2
# Stop the service
hiveserver2 stop
# Wait for complete shutdown
sleep 5
# Start the service
hiveserver2 start
# Wait for startup
sleep 10

Testing and Verification for Apache Hive RBAC Configuration with SQL

1. Verify Service Status

ps aux | grep hiveserver2
netstat -tulpn | grep 10000

2. Test RBAC Configuration

Using DBeaver or another JDBC client/connection:

SHOW ROLES;
SET ROLE admin;
CREATE ROLE user_role;

GRANT ROLE test_role TO USER tester;
Apache Hive RBAC Configuration with SQL - Granting a role to a user in Apache Hive with the GRANT ROLE command
Granting a role to a user in Apache Hive with the GRANT ROLE command

Using hive -e/beeline:

Apache Hive RBAC Configuration with SQL - Displaying updated roles after granting a role to a user
Displaying updated roles after granting a role to a user

Apache Hive RBAC Configuration with SQL Troubleshooting

Common Issues and Solutions

1. Principal Name Null Error If you see:

Required field 'principal_name' is unset!

Solution: Verify the hive.security.authenticator.manager setting is correct and HiveServer2 has been restarted.

2. User Not in Admin Role If you see:

root doesn't belong to role admin

Solution: Check the hive.users.in.admin.role property and ensure it contains your username.

3. Configuration Not Taking Effect

Solution:

  • Verify file permissions
  • Confirm HiveServer2 restart
  • Check logs for startup errors

Advanced Configuration for Apache Hive RBAC

Custom Authentication Providers

For environments requiring custom authentication:

<property>
    <name>hive.security.authenticator.manager</name>
    <value>com.your.custom.AuthenticatorManager</value>
</property>

Multiple Admin Users

To configure multiple admin users:

<property>
    <name>hive.users.in.admin.role</name>
    <value>root,admin1,admin2</value>
</property>

Further Considerations

  1. Security Best Practices

    • Regularly rotate passwords
    • Implement proper audit logging
    • Use SSL/TLS for connections
  2. Performance Impact

    • Monitor query performance after enabling RBAC
    • Adjust memory settings if needed
  3. Maintenance

    • Regular backup of configuration files
    • Document all custom settings
    • Maintain user-role mapping documentation

DataSunrise Integration for Apache Hive:
Advanced Solution for Simplified RBAC, Security & Compliance

While the native Hive RBAC configuration provides basic access control capabilities, enterprise environments often require more robust security, compliance, and auditing features. DataSunrise offers comprehensive integration with Apache Hive that extends these capabilities:

Apache Hive RBAC Configuration with SQL - Successfully setting a role for a user in Apache Hive
Successfully setting a role for a user in Apache Hive

Key Features

Enhanced RBAC Management

Dynamic Data Protection

Compliance and Audit

Security Features

Advanced Capabilities

DataSunrise provides a comprehensive feature-rich solution for organizations requiring enterprise-grade security and compliance features, that builds upon and enhances Hive's native RBAC capabilities. Explore the supported Apache Hive features, or experience it firsthand by scheduling a demo to see DataSunrise in action.

References

  1. Apache Hive Security Documentation
  2. Storage Based Authorization in the Metastore Server
  3. Setting Up Hive Authorization
  4. SQL Standard Based Hive Authorization
  5. Language Manual Authorization

This guide is based on real-world experience with Apache Hive 2.3.2 in a Docker environment. Your specific environment might require different adjustments to these configurations.

Next

Data Masking for Apache Impala

Data Masking for Apache Impala

Learn More

Need Our Support Team Help?

Our experts will be glad to answer your questions.

Countryx
United States
United Kingdom
France
Germany
Australia
Afghanistan
Islands
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua and Barbuda
Argentina
Armenia
Aruba
Austria
Azerbaijan
Bahamas
Bahrain
Bangladesh
Barbados
Belarus
Belgium
Belize
Benin
Bermuda
Bhutan
Bolivia
Bosnia and Herzegovina
Botswana
Bouvet
Brazil
British Indian Ocean Territory
Brunei Darussalam
Bulgaria
Burkina Faso
Burundi
Cambodia
Cameroon
Canada
Cape Verde
Cayman Islands
Central African Republic
Chad
Chile
China
Christmas Island
Cocos (Keeling) Islands
Colombia
Comoros
Congo, Republic of the
Congo, The Democratic Republic of the
Cook Islands
Costa Rica
Cote D'Ivoire
Croatia
Cuba
Cyprus
Czech Republic
Denmark
Djibouti
Dominica
Dominican Republic
Ecuador
Egypt
El Salvador
Equatorial Guinea
Eritrea
Estonia
Ethiopia
Falkland Islands (Malvinas)
Faroe Islands
Fiji
Finland
French Guiana
French Polynesia
French Southern Territories
Gabon
Gambia
Georgia
Ghana
Gibraltar
Greece
Greenland
Grenada
Guadeloupe
Guam
Guatemala
Guernsey
Guinea
Guinea-Bissau
Guyana
Haiti
Heard Island and Mcdonald Islands
Holy See (Vatican City State)
Honduras
Hong Kong
Hungary
Iceland
India
Indonesia
Iran, Islamic Republic Of
Iraq
Ireland
Isle of Man
Israel
Italy
Jamaica
Japan
Jersey
Jordan
Kazakhstan
Kenya
Kiribati
Korea, Democratic People's Republic of
Korea, Republic of
Kuwait
Kyrgyzstan
Lao People's Democratic Republic
Latvia
Lebanon
Lesotho
Liberia
Libyan Arab Jamahiriya
Liechtenstein
Lithuania
Luxembourg
Macao
Madagascar
Malawi
Malaysia
Maldives
Mali
Malta
Marshall Islands
Martinique
Mauritania
Mauritius
Mayotte
Mexico
Micronesia, Federated States of
Moldova, Republic of
Monaco
Mongolia
Montserrat
Morocco
Mozambique
Myanmar
Namibia
Nauru
Nepal
Netherlands
Netherlands Antilles
New Caledonia
New Zealand
Nicaragua
Niger
Nigeria
Niue
Norfolk Island
North Macedonia, Republic of
Northern Mariana Islands
Norway
Oman
Pakistan
Palau
Palestinian Territory, Occupied
Panama
Papua New Guinea
Paraguay
Peru
Philippines
Pitcairn
Poland
Portugal
Puerto Rico
Qatar
Reunion
Romania
Russian Federation
Rwanda
Saint Helena
Saint Kitts and Nevis
Saint Lucia
Saint Pierre and Miquelon
Saint Vincent and the Grenadines
Samoa
San Marino
Sao Tome and Principe
Saudi Arabia
Senegal
Serbia and Montenegro
Seychelles
Sierra Leone
Singapore
Slovakia
Slovenia
Solomon Islands
Somalia
South Africa
South Georgia and the South Sandwich Islands
Spain
Sri Lanka
Sudan
Suriname
Svalbard and Jan Mayen
Swaziland
Sweden
Switzerland
Syrian Arab Republic
Taiwan, Province of China
Tajikistan
Tanzania, United Republic of
Thailand
Timor-Leste
Togo
Tokelau
Tonga
Trinidad and Tobago
Tunisia
Turkey
Turkmenistan
Turks and Caicos Islands
Tuvalu
Uganda
Ukraine
United Arab Emirates
United States Minor Outlying Islands
Uruguay
Uzbekistan
Vanuatu
Venezuela
Viet Nam
Virgin Islands, British
Virgin Islands, U.S.
Wallis and Futuna
Western Sahara
Yemen
Zambia
Zimbabwe
Choose a topicx
General Information
Sales
Customer Service and Technical Support
Partnership and Alliance Inquiries
General information:
info@datasunrise.com
Customer Service and Technical Support:
support.datasunrise.com
Partnership and Alliance Inquiries:
partner@datasunrise.com