Home > Articles

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.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020