LoginSignup
0
0

More than 5 years have passed since last update.

Apache Hive + Rangerでの行単位 Filtering とカラム単位のマスキング

Posted at

1. Overview

最初、ビッグデータでデータの権限制御はHDFSファイルベース、フォルダベースでしかなかったが、
やはりテーブル単位だけではなく、カラム単位、行単位でも制御したい。

Source : Row-level filtering and column-masking using Apache Ranger policies in Apache Hive

現在、
* Apache Hive+Rangerの組み合わせで、Allowだけではなく、Denyでも出来る
* また、User/Group単位で制御も出来る
* 更に、動的な属性(例えばIPアドレス、アクセス時の時間帯など)によりアクセス権限を動的に決めることも出来る
* 行単位で制御可能
* カラム単位で制御可能

2. ユースケース:行単位Filter

Table: customer
+----+------------+-----------+--------------+---------------+----------------+
| id | name_first | name_last | addr_country | date_of_birth | phone_num      |
+----+------------+-----------+--------------+---------------+----------------+
|  1 | Mackenzy   | Smith     | US           | 1993-12-18    | 123-456-7890   |
|  2 | Sherlyn    | Miller    | US           | 1975-03-22    | 234-567-8901   |
|  3 | Khiana     | Wilson    | US           | 1989-08-14    | 345-678-9012   |
|  4 | Jack       | Thompson  | US           | 1962-10-28    | 456-789-0123   |
|  5 | Audrey     | Taylor    | UK           | 1985-01-11    | 12-3456-7890   |
|  6 | Ruford     | Walker    | UK           | 1976-05-19    | 23-4567-8901   |
|  7 | Marta      | Lloyd     | UK           | 1981-07-23    | 34-5678-9012   |
|  8 | Derick     | Schneider | DE           | 1982-04-17    | 12-345-67890   |
|  9 | Anna       | Richter   | DE           | 1995-09-07    | 23-456-78901   |
| 10 | Raina      | Graf      | DE           | 1999-02-06    | 34-567-89012   |
| 11 | Felix      | Lee       | CA           | 1982-04-17    | 321-654-0987   |
| 12 | Adam       | Brown     | CA           | 1995-09-07    | 432-765-1098   |
| 13 | Lucas      | Jones     | CA           | 1999-02-06    | 543-876-2109   |
| 14 | Yvonne     | Dupont    | FR           | 1982-04-17    | 01-23-45-67-89 |
| 15 | Pascal     | Fournier  | FR           | 1995-09-07    | 23-45-67-89-01 |
| 16 | Ariel      | Simon     | FR           | 1999-02-06    | 34-56-78-90-12 |
+----+------------+-----------+--------------+---------------+----------------+

仮に、上記テーブルCustomerとデータがあるとします。

Use case #1 : ユーザーが所属しているグループに基づいて、アクセスする行のSubsetを制御

まず基本からスタート。
仮に、ある組織がある。
US米国チーム、JK英国チーム、DEドイツチームがあります。
USチームのHive利用者はUSの顧客データしかアクセスさせない。
UKチームのHive利用者はJKの顧客データしかアクセスさせない。
組織のLDAP/ADは下記構成:

+--------------+---------------+
| Group name   | Users         |
+--------------+---------------+
| us-employees | john,scott    |
| uk-employees | mary,adam     |
| de-employees | drew,alice    |
+--------------+---------------+

Policy 詳細

1. ‘Row Level Filter’ Tabを選ぶ

image.png

2. それぞれ部署のFilter条件を入れる。対象のHive Database、あるいはDatabase とTableまで指定

image.png

Query実行してみる

User john, us-employees groupのメンバー:

[john@localhost ~]$ beeline -u jdbc:hive2://localhost.localdomain:10000/cust
0: jdbc:hive2://localhost.localdomain:10000> select * from cust.customer;
+-----+-------------+------------+---------------+----------------+--------------+
| id  | name_first  | name_last  | addr_country  | date_of_birth  | phone_num    |
+-----+-------------+------------+---------------+----------------+--------------+
| 1   | Mackenzy    | Smith      | US            | 1993-12-18     | 123-456-7890 |
| 2   | Sherlyn     | Miller     | US            | 1975-03-22     | 234-567-8901 |
| 3   | Khiana      | Wilson     | US            | 1989-08-14     | 345-678-9012 |
| 4   | Jack        | Thompson   | US            | 1962-10-28     | 456-789-0123 |
+-----+-------------+------------+---------------+----------------+--------------+

予想通り、USのデータのみが出力された。

User drew, de-employees groupのメンバー:

[drew@localhost ~]$ beeline -u jdbc:hive2://localhost.localdomain:10000/cust
0: jdbc:hive2://localhost.localdomain:10000> select * from cust.customer;
+-----+-------------+------------+---------------+----------------+--------------+
| id  | name_first  | name_last  | addr_country  | date_of_birth  | phone_num    |
+-----+-------------+------------+---------------+----------------+--------------+
| 8   | Derick      | Schneider  | DE            | 1982-04-17     | 12-345-67890 |
| 9   | Anna        | Richter    | DE            | 1995-09-07     | 23-456-78901 |
| 10  | Raina       | Graf       | DE            | 1999-02-06     | 34-567-89012 |
+-----+-------------+------------+---------------+----------------+--------------+

予想通り、DEのデータのみが出力された。

Use case #2 : ユーザーが所属しているグループに基づいて、別のTableの条件を見てアクセスする行のアクセスを制御


    addr_country in (select e.country from emp.employee e

                      where e.userid = current_user())

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0