|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 2 | +# contributor license agreements. See the NOTICE file distributed with |
| 3 | +# this work for additional information regarding copyright ownership. |
| 4 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 5 | +# (the "License"); you may not use this file except in compliance with |
| 6 | +# the License. You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | + |
| 17 | +1. Introduction |
| 18 | + Authorization APIs introduced in this module make it simpler for applications to use Apache Ranger to authorize |
| 19 | + access to their resources. This document includes few examples of authorization requests and corresponding |
| 20 | + responses. Libraries in Java and Python will be made available for easier integration in applications using |
| 21 | + these languages. Support for other languages will be added later as needed. |
| 22 | + |
| 23 | +2. Terminology |
| 24 | + 2.1. User |
| 25 | + An actor who performs actions on resources. Each user is identified by an unique name. A user can belong |
| 26 | + to multiple groups and can have multiple roles. A user can also have multiple attributes, like department |
| 27 | + name, work location. Apache Ranger policies can be setup to grant access to resources based on any of the |
| 28 | + following: user name, groups the user belongs to, roles the user is assigned to and user attributes. |
| 29 | + |
| 30 | + 2.2. Resource |
| 31 | + Any object on which actions can be performed. Few examples of resources and actions performed on them: |
| 32 | + - file: create, delete, write, read |
| 33 | + - table: create, alter, drop, insert, select, delete |
| 34 | + - topic: create, alter, delete, produce, consume |
| 35 | + |
| 36 | + Resources are identified by their name, in format: "resource-type:resource-value". Few examples of resource |
| 37 | + names: |
| 38 | + - path:/warehouse/hive/mktg/visitors |
| 39 | + - table:db1.tbl1 |
| 40 | + - object:s3a://mybucket/p1/p2/data.parquet |
| 41 | + |
| 42 | + Resources can have attributes, like owner, createTime. Access to resources can be granted based on resource |
| 43 | + attributes, like: owner of a resource should be allowed all actions. |
| 44 | + |
| 45 | + Resources can have sub-resources, like columns of a table. This is useful in optimizing authorization for |
| 46 | + access to a resource and several of its sub-resources in a single request. |
| 47 | + |
| 48 | + 2.3. Action |
| 49 | + An action performed on a resource. Examples of actions include: query, list, read, write, delete. In the |
| 50 | + context of authorization, the action given in the request is used only to record in audit log and does not |
| 51 | + affect the authorization decision. The authorization decision is based on the permissions requested for the |
| 52 | + resource. |
| 53 | + |
| 54 | + 2.4. Permission |
| 55 | + A privilege necessary to perform an action on a resources. Apache Ranger policies are used to grant or deny |
| 56 | + permissions to users. An action might require one or more permissions. Examples of permissions include: |
| 57 | + select, insert, read, write, delete. |
| 58 | + |
| 59 | + 2.5. Context |
| 60 | + Additional information about the request that can be used to make authorization decisions. Examples of |
| 61 | + context information include: access time, client IP address, cluster name, cluster type. |
| 62 | + |
| 63 | + 2.6. Decision |
| 64 | + The result of the authorization request. The decision can be either "ALLOWED" or "DENIED". The decision is |
| 65 | + based on the policies defined in Apache Ranger and the user, resource, permissions and context information |
| 66 | + provided in the request. |
| 67 | + |
| 68 | + 2.7. Row Filter |
| 69 | + For resources that support rows, like tables, Apache Ranger policies can be setup to filter rows that a user |
| 70 | + can access. Response from authorization request for such resources can include a row filter that should be |
| 71 | + applied by the caller, to ensure that the user only accesses rows they are allowed to. For example, a row |
| 72 | + filter can be defined to restrict access to rows in a table based on the department the user belongs to. |
| 73 | + |
| 74 | + 2.8. Data Mask |
| 75 | + For resources that support data masking, like columns of a table, Apache Ranger policies can be setup to |
| 76 | + mask (or transformation) values of columns having sensitive data. Response from authorization request for |
| 77 | + such resources can include a data mask that should be applied by the caller, to ensure that the user only |
| 78 | + has accesses to masked value of sensitive data. For example, a data mask can be defined on a column having |
| 79 | + phone number, credit card number or social security number. |
| 80 | + |
| 81 | +3. Examples |
| 82 | + This section includes few examples of authorization requests and corresponding responses. The examples include |
| 83 | + authorizing access to a single resource, authorizing access to a resource and sub-resources, authorizing access |
| 84 | + to multiple resources in a single request, row-filter and data-mask information in the response. |
| 85 | + |
| 86 | + 3.1 Authorize access to a single resource - a path |
| 87 | + request: |
| 88 | + { |
| 89 | + "requestId": "9198b532-a386-4464-9770-d61a8e8bc206", |
| 90 | + "user": { "name": "gary.adams", "groups": [ "fte", "mktg" ], "roles": [ "analyst" ] } |
| 91 | + "access": { "resource": "path:/warehouse/hive/mktg/visitors", "action": "LIST", "permissions": [ "list" ], "attributes": { "OWNER": "nancy.boxer" } } |
| 92 | + "context": { "accessTime": 1755543894, "clientIpAddress": "12.051.242", "forwardedIpAddresses": [], "additionalInfo": { "clientType": "CLI", "clusterName": "cl1", "clusterType": "onprem" } } |
| 93 | + } |
| 94 | + |
| 95 | + result: |
| 96 | + { |
| 97 | + "requestId": "9198b532-a386-4464-9770-d61a8e8bc206", |
| 98 | + "decision": "ALLOWED", |
| 99 | + "permissions": { |
| 100 | + "list": { "access": { "result": "ALLOWED", "policy": { "id": 1, "version": 1 } } |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + 3.2 Authorize access to a single resource and its sub-resources - a table and 3 columns |
| 106 | + request: |
| 107 | + { |
| 108 | + "requestId": "0a4134c1-44af-42e1-8a27-f15f18e60850", |
| 109 | + "user": { "name": "gary.adams", "groups": [ "fte", "mktg" ], "roles": [ "analyst" ] } |
| 110 | + "access": { "resource": "table:db1.tbl1", "subResources: [ "column:col1", "column:col2", "column:col3" ], "action": "QUERY", "permissions": [ "select" ], "attributes": { "OWNER": "nancy.boxer" } } |
| 111 | + "context": { "accessTime": 1755543894, "clientIpAddress": "12.051.242", "forwardedIpAddresses": [], "additionalInfo": { "clientType": "CLI", "clusterName": "cl1", "clusterType": "onprem" } } |
| 112 | + } |
| 113 | + |
| 114 | + result: |
| 115 | + { |
| 116 | + "requestId": "0a4134c1-44af-42e1-8a27-f15f18e60850", |
| 117 | + "decision": "ALLOWED", |
| 118 | + "permissions": { |
| 119 | + "select": { |
| 120 | + "rowFilter": { "filterExpression": "dept = 'mktg'", "policy": { "id": 11, "version": 3 } } |
| 121 | + "subResources": { |
| 122 | + "column:col1": { "access": { "decision": "ALLOWED", "policy": { "id": 5, "version": 1 } }, |
| 123 | + "dataMask": { "maskType": "MASK_SHOW_LAST_4", "maskedValue": "mask_show_last_n({col}, 4, 'x', 'x', 'x', -1, '1')", "policy": { "id": 26, "version": 2 } } }, |
| 124 | + "column:col2": { "access": { "decision": "ALLOWED", "policy": { "id": 2, "version": 1 } }, |
| 125 | + "dataMask": { "maskType": "MASK_HASH", "maskedValue": "mask_hash({col})", "policy": { "id": 27, "version": 4 } } }, |
| 126 | + "column:col3": { "access": { "decision": "ALLOWED", "policy": { "id": 3, "version": 1 } }, |
| 127 | + "dataMask": { "maskType": "MASK_HASH", "maskedValue": "mask_hash({col})", "policy": { "id": 27, "version": 4 } } } |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + 3.3: Authorize access to multiple resources - select on 2 tables and create on a table |
| 134 | + request: |
| 135 | + { |
| 136 | + "requestId": "4aa68265-34f1-4115-b026-d88dff292669", |
| 137 | + "user": { "name": "gary.adams", "groups": [ "fte", "mktg" ], "roles": [ "analyst" ] } |
| 138 | + "accesses": [ |
| 139 | + { "resource": "table:db1.tbl1", "action": "QUERY", "permissions": [ "select" ], "attributes": { "OWNER": "nancy.boxer" } }, |
| 140 | + { "resource": "table:db1.tbl2", "action": "QUERY", "permissions": [ "select" ], "attributes": { "OWNER": "nancy.boxer" } }, |
| 141 | + { "resource": "table:db1.vw1", "action": "CREATE", "permissions": [ "create" ] } |
| 142 | + ], |
| 143 | + "context": { "accessTime": 1755543894, "clientIpAddress": "12.051.242", "forwardedIpAddresses": [], "additionalInfo": { "clientType": "CLI", "clusterName": "cl1", "clusterType": "onprem" } } |
| 144 | + } |
| 145 | + |
| 146 | + result: |
| 147 | + { |
| 148 | + "requestId": "4aa68265-34f1-4115-b026-d88dff292669", |
| 149 | + "decision": "DENIED", |
| 150 | + "accesses": [ |
| 151 | + { |
| 152 | + "decision": "ALLOWED", |
| 153 | + "permissions": { |
| 154 | + "select": { |
| 155 | + "access": { "decision": "ALLOWED", "policy": { "id": 1, "version": 1 } }, |
| 156 | + "rowFilter": { "filterExpression": "dept = 'mktg'", "policy": { "id": 11, "version": 3 } } |
| 157 | + } |
| 158 | + } |
| 159 | + }, |
| 160 | + { |
| 161 | + "decision": "DENIED", |
| 162 | + "permissions": { |
| 163 | + "select": { |
| 164 | + "access": { "decision": "DENIED", "policy": { "id": 21, "version": 1 } } |
| 165 | + } |
| 166 | + } |
| 167 | + }, |
| 168 | + { |
| 169 | + "decision": "ALLOWED", |
| 170 | + "permissions": { |
| 171 | + "create": { |
| 172 | + "access": { "decision": "ALLOWED", "policy": { "id": 23, "version": 3 } } |
| 173 | + } |
| 174 | + } |
| 175 | + } |
| 176 | + ] |
| 177 | + } |
0 commit comments