原创-Yarn CapacityScheduler权限配置

先看完整的capacity-scheduler.xml配置

<configuration>
  <property>
    <name>yarn.scheduler.capacity.resource-calculator</name>
    <value>org.apache.hadoop.yarn.util.resource.DominantResourceCalculator</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.global-queue-max-application</name>
    <value>10000</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.root.queues</name>
    <value>legend,default</value>
  </property>
  <property> 
    <name>yarn.scheduler.capacity.root.acl_administer_queue</name>  
    <value>legend_super_user</value> 
  </property>  
  <property> 
    <name>yarn.scheduler.capacity.root.acl_submit_applications</name>  
    <value>legend_super_user</value> 
  </property>

  <property>
    <name>yarn.scheduler.capacity.root.default.capacity</name>
    <value>100</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.root.default.accessible-node-labels</name>
    <value> </value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.root.default.default-node-label-expression</name>
    <value> </value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.root.accessible-node-labels</name>
    <value>*</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.root.accessible-node-labels.bdspLabel.capacity</name>
    <value>100</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.root.legend.accessible-node-labels</name>
    <value>bdspLabel</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.root.legend.default-node-label-expression</name>
    <value>bdspLabel</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.root.legend.accessible-node-labels.bdspLabel.capacity</name>
    <value>100</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.root.legend.accessible-node-labels.bdspLabel.maximum-capacity</name>
    <value>100</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.root.legend.acl_submit_applications</name>
    <value>legend_user</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.root.legend.acl_administer_queue</name>
    <value>legend_user</value>
  </property>
   

 
  <property>
   <name>yarn.scheduler.capacity.queue-mappings</name>
   <value>u:legend_user:legend</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.legend.state</name>
    <value>RUNNING</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.legend.maximum-am-resource-percent</name>
    <value>0.1</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.legend.maximum-applications</name>
    <value>100000</value>
  </property>
</configuration>

该配置添加了NodeLabel限制,特别注意参数:yarn.scheduler.capacity.global-queue-max-application,如该参数不设置,必须设置能够访问默认NodeLabel的百分比,如设置yarn.scheduler.capacity.root.legend.capacity,这是因为提交队列时,LeafQueue类的validateSubmitApplication方法会Check submission limits for queues

 public void validateSubmitApplication(ApplicationId applicationId,
                                          String userName, String queue) throws AccessControlException {
        try {
            writeLock.lock();

            // Check if the queue is accepting jobs
            if (getState() != QueueState.RUNNING) {
                String msg = "Queue " + getQueuePath()
                        + " is STOPPED. Cannot accept submission of application: "
                        + applicationId;
                LOG.info(msg);
                throw new AccessControlException(msg);
            }

            // Check submission limits for queues
            if (getNumApplications() >= getMaxApplications()) {
                String msg =
                        "Queue " + getQueuePath() + " already has " + getNumApplications()
                                + " applications,"
                                + " cannot accept submission of application: " + applicationId
                                + " getMaxApplications() is: " + getMaxApplications();
                LOG.info(msg);
                throw new AccessControlException(msg);
            }

            // Check submission limits for the user on this queue
            User user = usersManager.getUserAndAddIfAbsent(userName);
            if (user.getTotalApplications() >= getMaxApplicationsPerUser()) {
                String msg = "Queue " + getQueuePath() + " already has " + user
                        .getTotalApplications() + " applications from user " + userName
                        + " cannot accept submission of application: " + applicationId;
                LOG.info(msg);
                throw new AccessControlException(msg);
            }
        } finally {
            writeLock.unlock();
        }

        try {
            getParent().validateSubmitApplication(applicationId, userName, queue);
        } catch (AccessControlException ace) {
            LOG.info("Failed to submit application to parent-queue: " +
                    getParent().getQueuePath(), ace);
            throw ace;
        }
    }

注意说明

限制用户提交队列权限属性是yarn.scheduler.capacity.root.legend.acl_submit_applications
管理队列权限数据是yarn.scheduler.capacity.root.legend.acl_administer_queue

 <property>
    <name>yarn.scheduler.capacity.root.legend.acl_submit_applications</name>
    <value>legend_user</value>
  </property>
  <property>
    <name>yarn.scheduler.capacity.root.legend.acl_administer_queue</name>
    <value>legend_user</value>
  </property>

YARN的权限是先校验该队列用户是否有相关权限,如没有则查找该队列的父队列是否拥有权限,一层一层往上查找,所以需配置root队列用户权限,默认是*,不限制权限

<property> 
    <name>yarn.scheduler.capacity.root.acl_administer_queue</name>  
    <value>legend_super_user</value> 
  </property>  
  <property> 
    <name>yarn.scheduler.capacity.root.acl_submit_applications</name>  
    <value>legend_super_user</value> 
  </property>

笔者在按照以上配置后,踩了一个坑,发现权限控制不生效,所有用户都可以提交权限,通过分析查看源码流程,调用ClientRMService类的submitApplication方法进行提交任务到队列,部分代码

 try {
      // call RMAppManager to submit application directly
      rmAppManager.submitApplication(submissionContext,
          System.currentTimeMillis(), user);

      LOG.info("Application with id " + applicationId.getId() + 
          " submitted by user " + user);
      RMAuditLogger.logSuccess(user, AuditConstants.SUBMIT_APP_REQUEST,
          "ClientRMService", applicationId, callerContext);
    } catch (YarnException e) {
      LOG.info("Exception in submitting " + applicationId, e);
      RMAuditLogger.logFailure(user, AuditConstants.SUBMIT_APP_REQUEST,
          e.getMessage(), "ClientRMService",
          "Exception in submitting application", applicationId, callerContext);
      throw e;
    }

接着调用mAppManager.submitApplication方法进行提交,即RMAppManager类的submitApplication方法

 @SuppressWarnings("unchecked")
    protected void submitApplication(
            ApplicationSubmissionContext submissionContext, long submitTime,
            String user) throws YarnException {
        LOG.info("===RMAppManager submitApplication====");
        ApplicationId applicationId = submissionContext.getApplicationId();

        // Passing start time as -1. It will be eventually set in RMAppImpl
        // constructor.
        RMAppImpl application = createAndPopulateNewRMApp(
                submissionContext, submitTime, user, false, -1);

        LOG.info("===RMAppManager submitApplication====");
        try {
            if (UserGroupInformation.isSecurityEnabled()) {
                this.rmContext.getDelegationTokenRenewer()
                        .addApplicationAsync(applicationId,
                                BuilderUtils.parseCredentials(submissionContext),
                                submissionContext.getCancelTokensWhenComplete(),
                                application.getUser(),
                                BuilderUtils.parseTokensConf(submissionContext));
            } else {
                // Dispatcher is not yet started at this time, so these START events
                // enqueued should be guaranteed to be first processed when dispatcher
                // gets started.
                this.rmContext.getDispatcher().getEventHandler()
                        .handle(new RMAppEvent(applicationId, RMAppEventType.START));
            }
        } catch (Exception e) {
            LOG.warn("Unable to parse credentials for " + applicationId, e);
            // Sending APP_REJECTED is fine, since we assume that the
            // RMApp is in NEW state and thus we haven't yet informed the
            // scheduler about the existence of the application
            this.rmContext.getDispatcher().getEventHandler()
                    .handle(new RMAppEvent(applicationId,
                            RMAppEventType.APP_REJECTED, e.getMessage()));
            throw RPCUtil.getRemoteException(e);
        }
    }

会在createAndPopulateNewRMApp方法中进行队列相关权限的检查,部分代码

 // Since FairScheduler queue mapping is done inside scheduler,
        // if FairScheduler is used and the queue doesn't exist, we should not
        // fail here because queue will be created inside FS. Ideally, FS queue
        // mapping should be done outside scheduler too like CS.
        // For now, exclude FS for the acl check.

        LOG.info("===RMAppManager createAndPopulateNewRMApp====");
        LOG.info("--!isRecovery--" + !isRecovery);
        LOG.info("--YarnConfiguration.isAclEnabled(conf)--" + YarnConfiguration.isAclEnabled(conf));

        if (!isRecovery && YarnConfiguration.isAclEnabled(conf)
                && scheduler instanceof CapacityScheduler) {
            String queueName = submissionContext.getQueue();
            String appName = submissionContext.getApplicationName();
            CSQueue csqueue = ((CapacityScheduler) scheduler).getQueue(queueName);

            if (csqueue == null && placementContext != null) {
                //could be an auto created queue through queue mapping. Validate
                // parent queue exists and has valid acls
                String parentQueueName = placementContext.getParentQueue();
                csqueue = ((CapacityScheduler) scheduler).getQueue(parentQueueName);
            }

            LOG.info("=====RMAppImpl createAndPopulateNewRMApp===");
            LOG.info(csqueue != null);
            if (csqueue != null) {
                LOG.info(csqueue.getQueueName());
            }
            LOG.info("=====RMAppImpl createAndPopulateNewRMApp===");

            if (csqueue != null
                    && !authorizer.checkPermission(
                    new AccessRequest(csqueue.getPrivilegedEntity(), userUgi,
                            SchedulerUtils.toAccessType(QueueACL.SUBMIT_APPLICATIONS),
                            applicationId.toString(), appName, Server.getRemoteAddress(),
                            null))
                    && !authorizer.checkPermission(
                    new AccessRequest(csqueue.getPrivilegedEntity(), userUgi,
                            SchedulerUtils.toAccessType(QueueACL.ADMINISTER_QUEUE),
                            applicationId.toString(), appName, Server.getRemoteAddress(),
                            null))) {
                throw RPCUtil.getRemoteException(new AccessControlException(
                        "User " + user + " does not have permission to submit "
                                + applicationId + " to queue " + submissionContext.getQueue()));
            }
        }

其中会进行是否开启了Yarn的权限参数配置校验:YarnConfiguration.isAclEnabled(conf),默认为false不进行权限的检查,如要开启Yarn权限校验,需配置yarn-site.xml中设置yarn.acl.enable参数为true

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,014评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,796评论 3 386
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,484评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,830评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,946评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,114评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,182评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,927评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,369评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,678评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,832评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,533评论 4 335
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,166评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,885评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,128评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,659评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,738评论 2 351