Created on 06-28-2016 11:57 AM - edited 08-18-2019 04:57 AM
I am trying to understand and practice Ranger configurations on the local HDP 2.4 sandbox.
The objective is that when the users(existing in some LDAP group) log-in and try to access HDFS, they should be able to access only their 'home directory' and others like tmp.I did the following :
[hdfs@sandbox root]$ hdfs dfs -ls /userhome Found 2 items drwxr-xr-x - hdfs hdfs 0 2016-06-27 14:24 /userhome/HBRDMV drwxr-xr-x - hdfs hdfs 0 2016-06-27 14:55 /userhome/ojoqcu
[ojoqcu@sandbox ~]$ hdfs dfs -ls /userhome/HBRDMV ls: Permission denied: user=ojoqcu, access=EXECUTE, inode="/userhome/HBRDMV":hdfs:hdfs:drwxr-x--- [ojoqcu@sandbox ~]$ hdfs dfs -mkdir /userhome/ojoqcu/code [ojoqcu@sandbox ~]$[ojoqcu@sandbox ~]$ hdfs dfs -ls /userhome/ojoqcu Found 1 item drwxr-xr-x - ojoqcu hdfs 0 2016-06-28 11:33 /userhome/ojoqcu/code [ojoqcu@sandbox ~]$ hdfs dfs -ls /userhome/ ls: Permission denied: user=ojoqcu, access=EXECUTE, inode="/userhome":hdfs:hdfs:drwxr-x---
Now, there may be aplenty users who will have their own directories under /userhome but only the single policy 'RestrictiveHDFS' would suffice, however, the 'Resource Path' doesn't provide a way to specify something like /userhome/{user} where {user} can be any of the from the 'Select User' list under 'User and Group Permissions'. How can I achieve this ?
Created 06-28-2016 02:49 PM
HDFS security is multi-tiered:
So, what you can do for user home directories is to set the POSIX permissions to 700 and make sure the ownership is <username>:hdfs. This will ensure that only the user has access to his/her home directory. You don't need to create a Ranger policy to allow the access for this. You can do the same for the /tmp directory (set permissions to 777).
There are some best practices for securing HDFS with Ranger.
Created 06-28-2016 12:20 PM
@Kaliyug wildcards are allowed in hdfs policy , so you can use as i mentioned in the following screenshot:
screen-shot-2016-06-28-at-53952-pm.png
but here i will suggest you to do following steps:
1. do this for all the users:
use user home in hdfs /user/<username> , and change owner to actual user : for ex:
chown HBRDMV:HBRDMV /user/HBRDMV
chmod 700 -R /user/HBRDMV
2. and for tmp you can create a policy with recursive yes , and add all the users there
Created 06-28-2016 12:29 PM
But my main question is how can I grant access to all the users to only their own /user/{directory} ? Wildcards certainly won't help here, how do I proceed ?
Created 06-28-2016 12:40 PM
you will have to create sep. policy for each resource /user/{directory} , for ex. /user/HBRDMV will have sep. policy for user HBRDMV .
Created 06-28-2016 01:25 PM
That's awful - if there are 100 users per service, those many policies per service need to be created. Is there something being missed or some better ways to do it ?
Created 06-28-2016 01:43 PM
so in this case better approach will be make owner of that user home directory to the user , generally same user is the owner of the user home dir.
for ex: chown HBRDMV:HBRDMV /user/HBRDMV
Created 06-28-2016 02:49 PM
HDFS security is multi-tiered:
So, what you can do for user home directories is to set the POSIX permissions to 700 and make sure the ownership is <username>:hdfs. This will ensure that only the user has access to his/her home directory. You don't need to create a Ranger policy to allow the access for this. You can do the same for the /tmp directory (set permissions to 777).
There are some best practices for securing HDFS with Ranger.
Created 06-28-2016 03:06 PM
I got the point of HDFS POSIX permissions, however, I couldn't understand 'HDFS ACLs implemented outside of Ranger' - does this mean one that ACL and Ranger are 'mutually exclusive' ? If yes, what is that ACL is doing which Ranger cannot ? Can you check this community thread which suggests that if you use Ranger, you need not work with ACL.
Created 06-28-2016 05:18 PM
HDFS has the ability to use ACLs (here's a link). If you don't have Ranger, then you can use ACLs to provide finer grained authorization than you can with POSIX permissions. However, if using Ranger, there is more flexibility and you have a single place to manage authorization for all of the components (not just HDFS). So, if you're using Ranger, you don't really need you use HDFS ACLs.
Created 07-26-2016 08:01 AM
ranger-home-directory-policy.png@Kaliyug Antagonist We've found another neat solution to this, using a resource path of the form: "/user/${id}"
Credit to Naveed Hussain, who found it after we moaned a lot about the alternatives.
Screenshot attached.