Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-26887

Make sure dirPath has the correct permissions

    XMLWordPrintableJSON

Details

    Description

      In the QueryResultsCache function of class QueryResultsCache, there is the following code segment

        private QueryResultsCache(HiveConf configuration) throws IOException {
          ......
          FileSystem fs = cacheDirPath.getFileSystem(conf);
          FsPermission fsPermission = new FsPermission("700");
          fs.mkdirs(cacheDirPath, fsPermission);
          ......
      }
      

      It can be seen that the function will use the mkdirs to create cacheDirPath, and the parameters passed in include the path variable cacheDirPath and a permission 700. But we haven't confirmed whether the permission is correctly assigned to the file.

      The above question is raised because there are two mkdir functions of hadoop,

      mkdirs(Path f, FsPermission permission)
      

      and

      mkdirs(FileSystem fs, Path dir, FsPermission permission)
      

      and the first one is used here. The permissions of this function will be affected by the underlying umask. Although 700 here will hardly be affected by umask, but I think from a rigorous point of view, we should have one more permission check and permission grant here.

      And I find same issue in other three methods here.
      In class Context

      private Path getScratchDir(String scheme, String authority,
            boolean mkdir, String scratchDir) {
                ......
                FileSystem fs = dirPath.getFileSystem(conf);
                dirPath = new Path(fs.makeQualified(dirPath).toString());
                FsPermission fsPermission = new FsPermission(scratchDirPermission);
      
                if (!fs.mkdirs(dirPath, fsPermission)) {
                  throw new RuntimeException("Cannot make directory: "
                      + dirPath.toString());
                ......
        }
      

      In class SessionState

        static void createPath(HiveConf conf, Path path, String permission, boolean isLocal,
            boolean isCleanUp) throws IOException {
          FsPermission fsPermission = new FsPermission(permission);
          FileSystem fs;
          ......
          if (!fs.mkdirs(path, fsPermission)) {
            throw new IOException("Failed to create directory " + path + " on fs " + fs.getUri());
          }
          ......
        }
      

      and in class TezSessionState

      private Path createTezDir(String sessionId, String suffix) throws IOException {
          ......
          Path tezDir = new Path(hdfsScratchDir, TEZ_DIR);
          FileSystem fs = tezDir.getFileSystem(conf);
          FsPermission fsPermission = new FsPermission(HiveConf.getVar(conf, HiveConf.ConfVars.SCRATCHDIRPERMISSION));
          fs.mkdirs(tezDir, fsPermission);
          ......
        }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              skysider Zhang Dongsheng
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h 20m
                  2h 20m