@Override
    public String prepareBulkLoad(final byte[] family, final String srcPath, boolean copyFile,
      String customStaging) throws IOException {
      Path p = new Path(srcPath);

      // store customStaging for failedBulkLoad
      String currentStaging = stagingDir;
      if (StringUtils.isNotEmpty(customStaging)) {
        currentStaging = customStaging;
      }

      Path stageP = new Path(currentStaging, new Path(Bytes.toString(family), p.getName()));

      // In case of Replication for bulk load files, hfiles are already copied in staging directory
      if (p.equals(stageP)) {
        LOG.debug(
          p.getName() + " is already available in staging directory. Skipping copy or rename.");
        return stageP.toString();
      }

      if (srcFs == null) {
        srcFs = FileSystem.newInstance(p.toUri(), conf);
      }

      if (!isFile(p)) {
        throw new IOException("Path does not reference a file: " + p);
      }

      // Check to see if the source and target filesystems are the same
      if (!FSUtils.isSameHdfs(conf, srcFs, fs)) {
        LOG.debug("Bulk-load file " + srcPath + " is on different filesystem than "
          + "the destination filesystem. Copying file over to destination staging dir.");
        FileUtil.copy(srcFs, p, fs, stageP, false, conf);
      } else if (copyFile) {
        LOG.debug("Bulk-load file " + srcPath + " is copied to destination staging dir.");
        FileUtil.copy(srcFs, p, fs, stageP, false, conf);
      } else {
        LOG.debug("Moving " + p + " to " + stageP);
        FileStatus origFileStatus = fs.getFileStatus(p);
        origPermissions.put(srcPath, origFileStatus.getPermission());
        origSources.put(stageP.toString(), srcPath);
        if (!fs.rename(p, stageP)) {
          throw new IOException("Failed to move HFile: " + p + " to " + stageP);
        }
      }
      fs.setPermission(stageP, PERM_ALL_ACCESS);

      return stageP.toString();
    }
Bulk loads in secure mode. This service addresses two issues:
<ol>
<li>Moving files in a secure filesystem wherein the HBase Client and HBase Server are different
filesystem users.</li>
<li>Does moving in a secure manner. Assuming that the filesystem is POSIX compliant.</li>
</ol>
The algorithm is as follows:
<ol>
<li>Create an hbase owned staging directory which is world traversable (711):
{@code /hbase/staging}</li>
<li>A user writes out data to his secure output directory: {@code /user/foo/data}</li>
<li>A call is made to hbase to create a secret staging directory which globally rwx (777):
{@code /user/staging/averylongandrandomdirectoryname}</li>
<li>The user moves the data into the random staging directory, then calls bulkLoadHFiles()</li>
</ol>
Like delegation tokens the strength of the security lies in the length and randomness of the
secret directory.
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/SecureBulkLoadManager.java