Home > Articles

  • Print
  • + Share This
This chapter is from the book

Managing HDFS Permissions and Users

HDFS as a file system is somewhat similar to the POSIX file system in terms of the file permissions it requires. However, HDFS doesn’t have the concept of users and groups as in the other file systems. It’s important to understand the nature of the HDFS super user and how to manage the granting of permissions to users. You also need to learn how to set up users so they’re ready to read data and write to the HDFS file system.

In the following sections, I explain these topics:

  • HDFS file permissions

  • Creating HDFS users

HDFS File Permissions

In a Linux system, you create OS users and make them members of an existing operating system group. In Hadoop, you associate a directory with an owner and a group. You need not actually “create” either the users or the groups. Rather, you use the concept of users and groups to set file and directory permissions. The following sections show how file and directory permissions work in HDFS.

HDFS Permission Checking

The HDFS configuration parameter dfs.permissions.enabled in the hdfs-site.xml file determines whether permission checking is enabled in HDFS:

<property>
<name>dfs.permissions.enabled</name>
<value>true</value>
</property>

The default value of the parameter is true, meaning permission checking is enabled. If you set this parameter to false, you turn HDFS permission checking off. Obviously, you can do this in a development environment to overcome frequent permission-related error messages, but in a production cluster, you need to keep it at its default setting.

HDFS File and Directory Permissions

HDFS uses a symbolic notation (r, w) to denote the read and write permissions, just as a Linux operating system does.

  • When a client accesses a directory, if the client is the same as the directory’s owner, Hadoop tests the owner’s permissions.

  • If the group matches the directory’s group, then Hadoop tests the user’s group permissions.

  • If neither the owner nor the group names match, Hadoop tests the “other” permission of the directory.

  • If none of the permissions checks succeed, the client’s request is denied.

Although there’s an execute (x) permission for a file, it’s ignored for files, and as far as directories go, the execute permission implies that you can access the subdirectories of that directory. Unlike in the underlying Linux operating system, Hadoop has nothing like the UIDs (User IDs) or GIDs (Group IDs) to identify users and groups. HDFS simply stores users and groups of a directory or file as strings.

A user can write to an HDFS directory only if that user has the correct permissions. In this example, the Linux root user tries to copy a file to a user’s HDFS directory and fails due to lack of permissions.

[root@hadoop01]# hdfs dfs -put test.txt /user/alapati/test2222/
put: Permission denied: user=root, access=WRITE, inode="/user/alapati/
test2222":hdfs:supergroup:drwxr-xr-x
[root@hadoop01]#

Permission Denied Errors in HDFS

You may receive the permission denied error when you’re issuing an HDFS command from the command line, as in the previous example, or even when you’re trying to browse the HDFS file system through the NameNode web page. For example, you may receive the following error when you try to browse files through the web UI.

Permission denied:user=alapati,access=READ_EXECUTE,inode="/user":hadoop:hdfs:drwx.------

In this case, you need to change the access privileges on the HDFS directory /user, after logging in as the user hdfs, from the command line:

$ hdfs dfs –chmod –R 755 /user

Running administrative commands as the root user or any other non-privileged (from the perspective of Hadoop) user will result in errors. If you run the Hadoop file system checking command fsck as the root user, you’ll get the following error:

$ su root
$ hdfs fsck /
...
FSCK ended at Sun May 29 14:46:27 CDT 2016 in 39473 milliseconds
Permission denied:user=root,access=READ_EXECUTE,inode="/lost+found/user":hdfs:supergroup:drwxr--r--

Fsck on path '/' FAILED
#

The FAILED result you get from running the fsck command here doesn’t mean the file system is corrupt! It simply means that you failed to execute the fsck command. A similar thing happens when you run the dfsadmin –report command as any user other than the HDFS super user, hdfs:

$ hdfs dfsadmin –report
-------------------------------------------------
report: Access denied for user root. Superuser privilege is required
#

In both the cases described here, the right thing to do is to either log in as the user hdfs and execute the commands, or if you have the sudo privileges to the hdfs user account, run the commands as follows:

$ sudo –u hdfs hdfs fsck /
$ sudo –u hdfs hdfs dfsadmin –report

HDFS Users and Super Users

Typically, database administrators create users in their databases, with each user having specific privileges and/or roles that enable them to perform various actions in the database. In the context of Hadoop, creating a user is kind of a misnomer, as HDFS really doesn’t have anything that lets you create user identities as you would on Linux systems. It also doesn’t enable you to create any groups.

In the default mode of authentication, called simple authentication, Hadoop relies on the underlying operating system to determine client identities. If you set up a Kerberized system (a system that has been set up to authenticate connections through Kerberos), then Kerberos will determine the client identities. Chapter 15 shows how to set up Kerberos for user authentication.

Note that you don’t need to create an operating system account on the underlying Linux system for your HDFS users to be able to access and use HDFS. It’s a good practice to create OS accounts for all Hadoop users who’ll be using the local file system on the gateway servers for their Hadoop-related work.

Creating HDFS (and Hadoop) Users

In order to enable new users to use your Hadoop cluster, follow these general steps.

  1. Create an OS account on the Linux system from which you want to let a user execute Hadoop jobs. Before creating the user, you may have to create the group as well:

    $ group add analysts
    $ useradd –g analysts alapati
    $ passwd alapati
    

    Here, analysts is an OS group I’ve created for a set of users. The passwd command lets me set a password for the user.

  2. Make sure that you’ve set the permissions on the Hadoop temp directory you’ve specified in the core-site.xml file, so all Hadoop users can access it:

    <property>
      <name>hadoop.tmp.dir</name>
      <value>/tmp/hadoop-$(user.name)</value>
    </property>
    
  3. If the file permissions on the HDFS temp directory aren’t 777, make them so:

    $ hdfs –dfs –chmod –R 777 //tmp/hadoop-alapati
  4. In order to “create” a new HDFS user, you need to create a directory under the /user directory. This directory will serve as the HDFS “home” directory for the user.

    $ hdfs dfs -mkdir /user/alapati
  5. By default, when you create a directory or a file, the owner is the user that creates the directory (or file) and the group is the group of that user, as shown here.

    # sudo -u hdfs
    # hdfs dfs -ls /user
    Found 135 items
    drwxr-xr-x   - hdfs      supergroup      0 2016-05-28 08:18 /user/alapati
    ....
    

    In this case, I used the hdfs account to create the directory, so the owner is hdfs and the group is supergroup. Change the ownership of the directory, since you don’t want to use the default owner/group (hdfs/supergroup) for this directory.

    $ su hdfs
    $ hdfs dfs –chown –R alapati:analysts
    $ hdfs dfs –ls /user/
    $ drwxr-xr-x   - alapati   analysts      0 2016-04-27 12:40 /user/alapati
    
  6. You can check the new directory structure for the user with the following command:

    $ hdfs dfs –ls /user/alapati

    User alapati can now store the output of his MapReduce and other jobs under that user’s home directory in HDFS.

  7. Refresh the user and group mappings to let the NameNode know about the new user:

    $ hdfs dfsadmin -refreshUserToGroupMappings
  8. Set a space quota for the new directory you’ve created:

    $ hdfs dfsadmin -setSpaceQuota 30g /user/alapati

The new user can now log into the gateway servers and execute his or her Hadoop jobs and store data in HDFS.

User Identities

Hadoop supports two modes of operation—simple and Kerberos—to determine user identities. The simple mode of operation is the default. You specify the mode of operation with the hadoop.security.authentication property in the hdfs-site.xml file.

When operating in a non-Kerberos (or non-Kerberized) cluster, the host operating system determines the client identities. In a Kerberized cluster, user identities are based on the user’s Kerberos credentials, as explained in Chapter 15. Users determine their current Kerberos principal through the kinit utility, and the Kerberos principal is then mapped to an HDFS username.

The HDFS Super User

Since Hadoop doesn’t have the concept of a user identity, there’s no fixed super user for Hadoop. The system super user for Hadoop is simply the operating system user that starts the NameNode. The HDFS super user doesn’t have to be the root user of the NameNode host. If you wish, you can allocate a set of users to a separate super user group.

You can make a set of users members of a super user group by setting the dfs.permissions.supergroup configuration parameter in the hdfs-site.xml file, as shown here.

<property>
  <name>dfs.permissions.superusergroup</name>
  <value>supergroup</value>
</property>

In this example, supergroup is the name of the group of super users in the cluster. The following example shows that the user hdfs belongs to the group supergroup:

# hdfs dfs -ls /
Found 7 items
drwxr-xr-x   - hdfs   hdfs               0 2014-06-25 16:39 /data
drwxr-xr-x   - hdfs   supergroup         0 2015-05-05 15:46 /system
drwxrwxrwt   - hdfs   hdfs               0 2015-05-09 09:33 /tmp
drwxr-xr-x   - hdfs   supergroup         0 2015-05-05 13:20 /user
...
#

A lot of the administrative HDFS commands need to be run as the “hdfs” OS user, which is the default HDFS super user. If you run these commands as any other user, including the root user in a Linux system, you’ll get the following error:

Access denied for user root. Superuser privilege is required.

The root user in Linux is indeed a super user but only for the local file system. It’s user hdfs who’s king when it comes to the HDFS file system. You can perform administration-related HDFS commands only as the hdfs user or by sudoing to that user. You can use the Linux sudo command to use the privileged administrative commands, as shown in the following example.

$ sudo –u hdfs hdfs dfs –rm /user/test/test.txt

In this example, the OS user was granted sudo privileges to the HDFS account and thus is able to run HDFS file commands as the HDFS super user hdfs.

  • + Share This
  • 🔖 Save To Your Account