Impala Authorization

Authorization determines which users are allowed to access which resources, and what operations they are allowed to perform. You use Apache Ranger for authorization. By default, when authorization is not enabled, Impala does all read and write operations with the privileges of the impala user, which is suitable for a development/test environment but not for a secure production environment. When authorization is enabled, Impala uses the OS user ID of the user who runs impala-shell or other client programs, and associates various privileges with each user.

See the following sections for details about using the Impala authorization features.

Parent topic: Impala Security

The Privilege Model

Privileges can be granted on different objects in the schema. Any privilege that can be granted is associated with a level in the object hierarchy. If a privilege is granted on a parent object in the hierarchy, the child object automatically inherits it. This is the same privilege model as Hive and other database systems.

The objects in the Impala schema hierarchy are:

  1. Server
  2. URI
  3. Database
  4. Table
  5. Column

The table-level privileges apply to views as well. Anywhere you specify a table name, you can specify a view name instead.

In Impala 2.3 and higher, you can specify privileges for individual columns.

The table below lists the minimum level of privileges and the scope required to execute SQL statements in Impala 3.0 and higher. The following notations are used:

  • The SERVER resource type in Ranger implies all databases, all tables, all columns, all UDFs, and all URIs.
  • ANY denotes the SELECT, INSERT, CREATE, ALTER, DROP, or REFRESH privilege.
  • ALL privilege denotes the SELECT, INSERT, CREATE, ALTER, DROP, and REFRESH privileges.
  • The owner of an object effectively has the ALL privilege on the object.
  • The parent levels of the specified scope are implicitly supported where a scope refers to the specific level in the object hierarchy that the privilege is granted. For example, if a privilege is listed with the TABLE scope, the same privilege granted on DATABASE and SERVER will allow the user to execute the specified SQL statement.
SQL StatementPrivilegesObject Type /

Resource Type

SELECTSELECTTABLE
WITH SELECTSELECTTABLE
EXPLAIN SELECTSELECTTABLE
INSERTINSERTTABLE
EXPLAIN INSERTINSERTTABLE
TRUNCATEINSERTTABLE
LOADINSERTTABLE
 ALLURI
CREATE DATABASECREATESERVER
CREATE DATABASE LOCATIONCREATESERVER
 ALLURI
CREATE TABLECREATEDATABASE
CREATE TABLE LIKECREATEDATABASE
 SELECT, INSERT, or REFRESHTABLE
CREATE TABLE AS SELECTCREATEDATABASE
 INSERTDATABASE
 SELECTTABLE
EXPLAIN CREATE TABLE AS SELECTCREATEDATABASE
 INSERTDATABASE
 SELECTTABLE
CREATE TABLE LOCATIONCREATETABLE
 ALLURI
CREATE VIEWCREATEDATABASE
 SELECTTABLE
ALTER DATABASE SET OWNERALL WITH GRANTDATABASE
ALTER TABLEALTERTABLE
ALTER TABLE SET LOCATIONALTERTABLE
 ALLURI
ALTER TABLE RENAMECREATEDATABASE
 ALLTABLE
ALTER TABLE SET OWNERALL WITH GRANTTABLE
ALTER VIEWALTERTABLE
 SELECTTABLE
ALTER VIEW RENAMECREATEDATABASE
 ALLTABLE
ALTER VIEW SET OWNERALL WITH GRANTVIEW
DROP DATABASEDROPDATABASE
DROP TABLEDROPTABLE
DROP VIEWDROPTABLE
CREATE FUNCTIONCREATEDATABASE
 ALLURI
DROP FUNCTIONDROPDATABASE
COMPUTE STATSALTER and SELECTTABLE
DROP STATSALTERTABLE
INVALIDATE METADATAREFRESHSERVER
INVALIDATE METADATA <table>REFRESHTABLE
REFRESH <table>REFRESHTABLE
REFRESH AUTHORIZATIONREFRESHSERVER
REFRESH FUNCTIONSREFRESHDATABASE
COMMENT ON DATABASEALTERDATABASE
COMMENT ON TABLEALTERTABLE
COMMENT ON VIEWALTERTABLE
COMMENT ON COLUMNALTERTABLE
DESCRIBE DATABASESELECT, INSERT, or REFRESHDATABASE
DESCRIBE <table/view>SELECT, INSERT, or REFRESHTABLE
If the user has the SELECT privilege at the COLUMN level, only the columns the user has access will show.SELECTCOLUMN
USEANYTABLE
SHOW DATABASESANYTABLE
SHOW TABLESANYTABLE
SHOW FUNCTIONSSELECT, INSERT, or REFRESHDATABASE
SHOW PARTITIONSSELECT, INSERT, or REFRESHTABLE
SHOW TABLE STATSSELECT, INSERT, or REFRESHTABLE
SHOW COLUMN STATSSELECT, INSERT, or REFRESHTABLE
SHOW FILESSELECT, INSERT, or REFRESHTABLE
SHOW CREATE TABLESELECT, INSERT, or REFRESHTABLE
SHOW CREATE VIEWSELECT, INSERT, or REFRESHTABLE
SHOW CREATE FUNCTIONSELECT, INSERT, or REFRESHDATABASE
SHOW RANGE PARTITIONS (Kudu only)SELECT, INSERT, or REFRESHTABLE
UPDATE (Kudu only)ALLTABLE
EXPLAIN UPDATE (Kudu only)ALLTABLE
UPSERT (Kudu only)ALLTABLE
WITH UPSERT (Kudu only)ALLTABLE
EXPLAIN UPSERT (Kudu only)ALLTABLE
DELETE (Kudu only)ALLTABLE
EXPLAIN DELETE (Kudu only)ALLTABLE

Privileges are managed via the GRANT and REVOKE SQL statements that require the Ranger service enabled.

If you change privileges outside of Impala, e.g. adding a user, removing a user, modifying privileges, you must clear the Impala Catalog server cache by running the REFRESH AUTHORIZATION statement. REFRESH AUTHORIZATION is not required if you make the changes to privileges within Impala.

Object Ownership in Ranger

Object ownership for tables, views and databases is enabled by default in Impala.

To define owner specific privileges, go to ranger UI and define appropriate policies on the {OWNER} user.

The CREATE statements implicitly make the user running the statement the owner of the object. For example, if User A creates a database, foo, via the CREATE DATABASE statement, User A now owns the foo database and is authorized to perform any operation on the foo database.

An ownership can be transferred to another user or role via the ALTER DATABASE, ALTER TABLE, or ALTER VIEW with the SET OWNER clause.

Note: Currently, due to a known issue (IMPALA-8937), until the ownership information is fully loaded in the coordinator catalog cache, the owner of a table might not be able to see the table when executing the SHOW TABLES statement The owner can still query the table.

Starting Impala with Ranger Authorization Enabled

To enable authorization in an Impala cluster using Ranger:

  1. Add the following options to the IMPALA_SERVER_ARGS and the IMPALA_CATALOG_ARGS settings in the /etc/default/impala configuration file:
    • -server_name: Specify the same name for all impalad nodes and the catalogd in the cluster.
    • -ranger_service_type=hive
    • -ranger_app_id: Set it to the Ranger application id.
    • -authorization_provider=ranger
  2. Restart the catalogd and all impalad daemons.

Managing Privileges

You set up privileges through the GRANT and REVOKE statements in either Impala or Hive.

For information about using the Impala GRANT and REVOKE statements, see GRANT Statement (Impala 2.0 or higher only) and REVOKE Statement (Impala 2.0 or higher only).

Changing Privileges from Outside of Impala

If you make a change to privileges in Ranger from outside of Impala, e.g. adding a user, removing a user, modifying privileges, there are two options to propagate the change:

  • Use the ranger.plugin.hive.policy.pollIntervalMs property to specify how often to do a Ranger refresh. The property is specified in ranger-hive-security.xml in the conf directory under your Impala home directory.
  • Run the INVALIDATE METADATA or REFRESH AUTHORIZATION statement to force a refresh.

If you make a change to privileges within Impala, INVALIDATE METADATA is not required.

Warning: As INVALIDATE METADATA is an expensive operation, you should use it judiciously.

Granting Privileges on URI

URIs represent the file paths you specify as part of statements such as CREATE EXTERNAL TABLE and LOAD DATA. Typically, you specify what look like UNIX paths, but these locations can also be prefixed with hdfs:// to make clear that they are really URIs. To set privileges for a URI, specify the name of a directory, and the privilege applies to all the files in that directory and any directories underneath it.

URIs must start with hdfs://, s3a://, adl://, or file://. If a URI starts with an absolute path, the path will be appended to the default filesystem prefix. For example, if you specify:

  1. GRANT ALL ON URI '/tmp';

The above statement effectively becomes the following where the default filesystem is HDFS.

  1. GRANT ALL ON URI 'hdfs://localhost:20500/tmp';

When defining URIs for HDFS, you must also specify the NameNode. For example:

  1. GRANT ALL ON URI file:///path/to/dir TO <role>
  2. GRANT ALL ON URI hdfs://namenode:port/path/to/dir TO <role>

Warning: Because the NameNode host and port must be specified, it is strongly recommended that you use High Availability (HA). This ensures that the URI will remain constant even if the NameNode changes. For example:

  1. GRANT ALL ON URI hdfs://ha-nn-uri/path/to/dir TO <role>

Examples of Setting up Authorization for Security Scenarios

The following examples show how to set up authorization to grant privileges on objects to groups of users via roles.

A User with No Privileges

If a user has no privileges at all, that user cannot access any schema objects in the system. The error messages do not disclose the names or existence of objects that the user is not authorized to read.

This is the experience you want a user to have if they somehow log into a system where they are not an authorized Impala user. Or in a real deployment, a user might have no privileges because they are not a member of any of the authorized groups.

Examples of Privileges for Administrative Users

In this example, the SQL statements grant the entire_server role all privileges on both the databases and URIs within the server.

  1. CREATE ROLE entire_server;
  2. GRANT ROLE entire_server TO GROUP admin_group;
  3. GRANT ALL ON SERVER server1 TO ROLE entire_server;

A User with Privileges for Specific Databases and Tables

If a user has privileges for specific tables in specific databases, the user can access those things but nothing else. They can see the tables and their parent databases in the output of SHOW TABLES and SHOW DATABASES, USE the appropriate databases, and perform the relevant actions (SELECT and/or INSERT) based on the table privileges. To actually create a table requires the ALL privilege at the database level, so you might define separate roles for the user that sets up a schema and other users or applications that perform day-to-day operations on the tables.

  1. CREATE ROLE one_database;
  2. GRANT ROLE one_database TO GROUP admin_group;
  3. GRANT ALL ON DATABASE db1 TO ROLE one_database;
  4. CREATE ROLE instructor;
  5. GRANT ROLE instructor TO GROUP trainers;
  6. GRANT ALL ON TABLE db1.lesson TO ROLE instructor;
  7. # This particular course is all about queries, so the students can SELECT but not INSERT or CREATE/DROP.
  8. CREATE ROLE student;
  9. GRANT ROLE student TO GROUP visitors;
  10. GRANT SELECT ON TABLE db1.training TO ROLE student;

Privileges for Working with External Data Files

When data is being inserted through the LOAD DATA statement or is referenced from an HDFS location outside the normal Impala database directories, the user also needs appropriate permissions on the URIs corresponding to those HDFS locations.

In this example:

  • The external_table role can insert into and query the Impala table, external_table.sample.
  • The staging_dir role can specify the HDFS path /user/impala-user/external_data with the LOAD DATA statement. When Impala queries or loads data files, it operates on all the files in that directory, not just a single file, so any Impala LOCATION parameters refer to a directory rather than an individual file.
  1. CREATE ROLE external_table;
  2. GRANT ROLE external_table TO GROUP impala_users;
  3. GRANT ALL ON TABLE external_table.sample TO ROLE external_table;
  4. CREATE ROLE staging_dir;
  5. GRANT ROLE staging TO GROUP impala_users;
  6. GRANT ALL ON URI 'hdfs://127.0.0.1:8020/user/impala-user/external_data' TO ROLE staging_dir;

Separating Administrator Responsibility from Read and Write Privileges

To create a database, you need the full privilege on that database while day-to-day operations on tables within that database can be performed with lower levels of privilege on a specific table. Thus, you might set up separate roles for each database or application: an administrative one that could create or drop the database, and a user-level one that can access only the relevant tables.

In this example, the responsibilities are divided between users in 3 different groups:

  • Members of the supergroup group have the training_sysadmin role and so can set up a database named training.
  • Members of the impala_users group have the instructor role and so can create, insert into, and query any tables in the training database, but cannot create or drop the database itself.
  • Members of the visitor group have the student role and so can query those tables in the training database.
  1. CREATE ROLE training_sysadmin;
  2. GRANT ROLE training_sysadmin TO GROUP supergroup;
  3. GRANT ALL ON DATABASE training TO ROLE training_sysadmin;
  4. CREATE ROLE instructor;
  5. GRANT ROLE instructor TO GROUP impala_users;
  6. GRANT ALL ON TABLE training.course1 TO ROLE instructor;
  7. CREATE ROLE student;
  8. GRANT ROLE student TO GROUP visitor;
  9. GRANT SELECT ON TABLE training.course1 TO ROLE student;

Setting Up Schema Objects for a Secure Impala Deployment

In your role definitions, you must specify privileges at the level of individual databases and tables, or all databases or all tables within a database. To simplify the structure of these rules, plan ahead of time how to name your schema objects so that data with different authorization requirements are divided into separate databases.

If you are adding security on top of an existing Impala deployment, you can rename tables or even move them between databases using the ALTER TABLE statement.

The DEFAULT Database in a Secure Deployment

Because of the extra emphasis on granular access controls in a secure deployment, you should move any important or sensitive information out of the DEFAULT database into a named database. Sometimes you might need to give privileges on the DEFAULT database for administrative reasons, for example, as a place you can reliably specify with a USE statement when preparing to drop a database.

Ranger Column Masking

Ranger column masking hides sensitive columnar data in Impala query output. For example, you can define a policy that reveals only the first or last four characters of column data. Column masking is enabled by default. The Impala behavior mimics Hive behavior with respect to column masking. For more information, see the Apache Ranger documentation.

The following table lists all supported, built-in mask types for defining column masking in a policy using the Ranger REST API.

TypeNameDescriptionTransformer
MASKRedactReplace lowercase with ‘x’, uppercase with ‘X’, digits with ‘0’mask({col})
MASK_SHOW_LAST_4Partial mask: show last 4Show last 4 characters; replace rest with ‘x’mask_show_last_n({col}, 4, ‘x’, ‘x’, ‘x’, -1, ‘1’)
MASK_SHOW_FIRST_4Partial mask: show first 4Show first 4 characters; replace rest with ‘x’mask_show_first_n({col}, 4, ‘x’, ‘x’, ‘x’, -1, ‘1’)
MASK_HASHHashHash the valuemask_hash({col})
MASK_NULLNullifyReplace with NULLN/A
MASK_NONEUnmasked (retain original value)No maskingN/A
MASK_DATE_SHOW_YEARDate: show only yearDate: show only yearmask({col}, ‘x’, ‘x’, ‘x’, -1, ‘1’, 1, 0, -1)
CUSTOMCustomCustomN/A

Limitations on Mask Functions

The mask functions in Hive are implemented through GenericUDFs. Even though Impala users can call Hive UDFs, Impala does not yet support Hive GenericUDFs, so you cannot use Hive’s mask functions in Impala. However, Impala has builtin mask functions that are implemented through overloads. In Impala, when using mask functions, not all parameter combinations are supported. These mask functions are introduced in Impala 3.4

The following list includes all the implemented overloads.

  • Overloads used by Ranger default masking policies,
  • Overloads with simple arguments,
  • Overload with all arguments in int type for full functionality. Char argument needs to be converted to their ASCII value.

To list the available overloads, use the following query:

  1. show functions in _impala_builtins like "mask*";

Note:

  • An error message that states “No matching function with signature: mask…“ implies that Impala does not contain the corresponding overload.