Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 36 ยท Tuning and Integration

Security and HiveServer2

Secure a Hive deployment: HiveServer2 authentication with Kerberos and LDAP, SQL-standard authorization and Ranger policies, column masking, views for row and column limits, and encryption.

A warehouse holds the most sensitive data a company has, so Hive security has several layers. Think of them as four questions: who are you (authentication), what may you do (authorization), who sees which values (masking and views), and is the data protected at rest and in transit (encryption). Each is configured in a different place.

Real security settings need a cluster, so Hive and Hadoop configuration is read-only here. The editors model the ideas (grants, views, masking) with SQLite, which has no users but can show how views limit what a query sees.

HiveServer2

Clients do not talk to the metastore or storage directly. They connect to HiveServer2 (HS2): it authenticates the client, parses and compiles the SQL, enforces authorization, starts the query on Tez or LLAP and streams results back. The metastore (HMS) is a separate service that other engines also use. HS2 listens on port 10000 (binary Thrift) or 10001 (HTTP mode, useful behind proxies and gateways such as Knox), and exposes a web UI on 10002 with running queries and sessions.

flowchart LR
    C["Beeline / JDBC / BI tool"] -->|"authenticate"| HS2["HiveServer2"]
    HS2 -->|"authorize"| AZ["Ranger or SQL-standard authorization"]
    HS2 --> HMS[("Metastore")]
    HS2 --> ENG["Tez / LLAP"]
    ENG --> ST[("HDFS / object store")]

Every query passes through HiveServer2, which is where identity and permissions are checked.

Authentication

Method Use
Kerberos Standard for secured Hadoop clusters; tickets, no passwords on the wire
LDAP / Active Directory Username and password checked against a directory (use TLS)
PAM Operating-system accounts
Custom provider Your own Java class
SAML / JWT (newer versions) Single sign-on through gateways

Key settings in hive-site.xml:

TEXT
hive.server2.authentication = KERBEROS    (or LDAP, PAM, CUSTOM, NONE)
hive.server2.authentication.kerberos.principal = hive/[email protected]
hive.server2.authentication.kerberos.keytab = /etc/security/keytabs/hive.service.keytab
hive.server2.thrift.sasl.qop = auth-conf        (encrypt Thrift traffic)
hive.server2.use.SSL = true

NONE means anyone can claim any username, which is fine only for a local sandbox. Beeline over Kerberos looks like beeline -u "jdbc:hive2://host:10000/default;principal=hive/[email protected]" after kinit; over LDAP you pass -n user -p password, or better read the password from a file or prompt instead of typing it into scripts.

Impersonation

With hive.server2.enable.doAs = true, HS2 runs queries as the end user, so HDFS permissions apply to that person. With false, queries run as the hive service user and authorization inside Hive (Ranger or SQL grants) is the only gate. Modern secured deployments usually choose false plus Ranger, because it allows fine-grained policy and central audit.

Authorization models

Storage-based authorization

Hive checks the HDFS permissions of the table directory (read permission to select, write to insert). It protects tables only as far as HDFS ACLs do, and cannot express column-level rules, so it is limited.

SQL-standard authorization

GRANT-based security managed from SQL, in the style of a traditional database:

SQL
SET ROLE ADMIN;
CREATE ROLE analysts;
GRANT ROLE analysts TO USER alice;
GRANT SELECT ON TABLE sales TO ROLE analysts;
GRANT INSERT ON TABLE staging TO USER etl_job;
REVOKE SELECT ON TABLE sales FROM ROLE analysts;

SHOW GRANT ROLE analysts ON TABLE sales;
SHOW CURRENT ROLES;

Privileges are SELECT, INSERT, UPDATE, DELETE and ALL, with WITH GRANT OPTION to delegate. It applies only through HiveServer2 clients; engines that read files directly (Spark reading HDFS) bypass it unless HDFS permissions also hold.

Apache Ranger

In most production clusters, Apache Ranger is the authorization layer. A Ranger plugin inside HS2 checks each query against central policies and writes an audit log of every access. Policies can grant by database, table, column and UDF, to users, groups or roles, with conditions (IP ranges, time). The same Ranger policies cover HDFS, Kafka and HBase, which keeps rules consistent across the platform.

Controlling what values users see

Views

Before Ranger, the portable way to hide columns or rows was a view: grant access to the view, not the table.

SQL
CREATE VIEW customers_support AS
SELECT id, first_name, city                -- no email, no phone
FROM customers
WHERE country = 'DE';                      -- only one region

GRANT SELECT ON TABLE customers_support TO ROLE support;

The idea works in any database, so you can try it:

SQL A view that hides columns and rows (SQLite stand-in) ยท database: shop

Press Run (or Ctrl + Enter) to see the result here.

Column masking and row filters

Ranger can apply dynamic masking, so the same query shows different data per user: show the last four characters, hash the value, show NULL or a fixed value. Row-level filters add a hidden WHERE condition (for example region = 'EU') for given groups. Because this happens in HS2 at run time, you do not duplicate data or maintain many views.

You can imitate masking with expressions:

SQL Masking an email (SQLite stand-in) ยท database: shop

Press Run (or Ctrl + Enter) to see the result here.

Encryption

  • In transit: TLS for HiveServer2 (hive.server2.use.SSL), SASL privacy (auth-conf) for Thrift, and encrypted shuffle and RPC in Hadoop.
  • At rest: HDFS transparent encryption with encryption zones and a key management server (Ranger KMS or Hadoop KMS), or encryption in the object store (SSE-S3, SSE-KMS). Hive tables placed in an encryption zone are encrypted automatically; the data inside files is unreadable without key access.
  • Secrets: never hard-code passwords. Use credential providers (hadoop credential create) for metastore database and S3 keys, and store keytabs with strict file permissions.

Operations checklist

  1. Disable NONE authentication outside sandboxes; use Kerberos or LDAP over TLS.
  2. Use Ranger (or SQL-standard grants) and give people roles, not individual grants.
  3. Restrict ADD JAR, CREATE FUNCTION, TRANSFORM and dfs/shell commands for normal users, because they run code (UDFs). Hive exposes hive.security.authorization.sqlstd.confwhitelist and similar settings to limit which SET commands users may run.
  4. Protect the metastore database and its service port; it holds all table metadata.
  5. Review audit logs regularly and alert on unusual large reads.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does HiveServer2 do?

    HS2 is the query gateway; the metastore stores metadata and HDFS stores data.
  2. 2. With hive.server2.enable.doAs = false, queries run as:

    Then HDFS sees only the service user, and Ranger or SQL grants decide who can read what.
  3. 3. Which tool provides central policies, column masking and audit logs for Hive?

    Ranger plugs into HiveServer2 for fine-grained authorization, masking, row filters and auditing.
  4. 4. How can a plain view help with security?

    Users see only what the view's query returns, so sensitive columns can stay hidden.

Summary

  • HiveServer2 authenticates, authorizes, compiles and runs queries; use Kerberos or LDAP over TLS, never NONE, in production.
  • Authorize with Ranger (preferred) or SQL-standard GRANT/REVOKE on roles.
  • Limit visible data with views, or with Ranger masking and row filters.
  • Encrypt in transit (TLS/SASL) and at rest (HDFS encryption zones, object-store encryption).
  • Restrict code-running features such as ADD JAR and TRANSFORM.

Next: Project: Web Log Analytics