container-executor.cfg文件及其各级父路径问题解决方案

在搭建Hadoop-2.6.0 CGroup时遇到container-executor.cfg文件权限问题,LinuxContainerExecutor要求该文件及其父路径属主为root。分析了源码中权限检查逻辑,并探讨了两种解决方案:修改所有者和重新编译Hadoop,最终建议通过cmake调整HADOOP_CONF_DIR以避免安全隐患。
摘要由CSDN通过智能技术生成

一、背景

      为了增加Hadoop CGroup来限制部分作业对CPU的占用,近日在搭建Hadoop-2.6.0的CGroup过程中,碰到了以下一个问题,提示如下(注:500为用户hadoop的id号):

File /opt/hadoop/hadoop-2.6.0/etc/hadoop/container -executor .cfg must be owned by root, but is owned by 500

      于是,就将container-executor.cfg文件的所有者修改为root,继而又出现了以下问题:

File /opt/hadoop/hadoop-2.6.0/etc/hadoop must be owned by root, but is owned by 500

      这是怎么回事呢?

二、分析

      原来,LinuxContainerExecutor通过container-executor来启动容器,但是出于安全的考虑,要求其所依赖的配置文件container-executor.cfg及其各级父路径所有者必须是root用户。源码中的判断如下:

/**
 * Ensure that the configuration file and all of the containing directories
 * are only writable by root. Otherwise, an attacker can change the
 * configuration and potentially cause damage.
 * returns 0 if permissions are ok
 */
int check_configuration_permissions(const char* file_name) {
  // copy the input so that we can modify it with dirname
  char* dir = strdup(file_name);
  char* buffer = dir;
  do {
    if (!is_only_root_writable(dir)) {
      free(buffer);
      return -1;
    }
    dir = dirname(dir);
  } while (strcmp(dir, "/") != 0);
  free(buffer);
  return 0;
}
  
/**
 * Is the file/directory only writable by root.
 * Returns 1 if true
 */
static int is_only_root_writable(const char *file) {
  struct stat file_stat;
  if (stat(file, &file_stat) != 0) {
    fprintf(ERRORFILE, "Can't stat file %s - %s\n", file, strerror(errno));
    return 0;
  }
  if (file_stat.st_uid != 0) {
    fprintf(ERRORFILE, "File %s must be owned by root, but is owned by %d\n",
            file, file_stat.st_uid);
    return 0;
  }
  if ((file_stat.st_mode & (S_IWGRP | S_IWOTH)) != 0) {
    fprintf(ERRORFILE,
        "File %s must not be world or group writable, but is %03o\n",
        file, file_stat.st_mode & (~S_IFMT));
    return 0;
  }
  return 1;
}


      在check_configuration_permissions函数中,对配置文件container-executor.cfg路径dir,在一个do循环内循环调用is_only_root_writable函数检测及所有者必须是root用户,否则不予启动容器。

      而Hadoop-2.6.0在编译时,是通过如下方式确定配置文件container-executor.cfg的位置的,首先,在hadoop-yarn-server-nodemanager的pom.xml中,设置了一个名为container-executor.conf.dir的properties,其值为yarn.basedir/etc/hadoop,实际上就是$HADOOP_HOME/etc/hadoop/,如下:

<
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值