step3.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var stringUtils = require('utils/string_utils');
  20. App.MainAdminSecurityAddStep3Controller = Em.Controller.extend({
  21. name: 'mainAdminSecurityAddStep3Controller',
  22. hostComponents: [],
  23. doDownloadCsv: function(){
  24. if ($.browser.msie && $.browser.version < 10) {
  25. this.openInfoInNewTab();
  26. } else {
  27. var blob = new Blob([stringUtils.arrayToCSV(this.get('hostComponents'))], {type: "text/csv;charset=utf-8;"});
  28. saveAs(blob, "host-principal-keytab-list.csv");
  29. }
  30. },
  31. openInfoInNewTab: function(){
  32. var newWindow = window.open('');
  33. var newDocument = newWindow.document;
  34. newDocument.write(stringUtils.arrayToCSV(this.get('hostComponents')));
  35. newWindow.focus();
  36. },
  37. loadStep: function(){
  38. var configs = this.get('content.serviceConfigProperties');
  39. var hosts = App.Host.find();
  40. var result = [];
  41. var componentsToDisplay = ['NAMENODE', 'SECONDARY_NAMENODE', 'DATANODE', 'JOBTRACKER', 'ZOOKEEPER_SERVER', 'HIVE_SERVER', 'TASKTRACKER',
  42. 'OOZIE_SERVER', 'NAGIOS_SERVER', 'HBASE_MASTER', 'HBASE_REGIONSERVER'];
  43. var securityUsers = [];
  44. if (!securityUsers || securityUsers.length < 1) { // Page could be refreshed in middle
  45. if (App.testMode) {
  46. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  47. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  48. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  49. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  50. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  51. securityUsers.pushObject({id: 'puppet var', name: 'zk_user', value: 'zookeeper'});
  52. securityUsers.pushObject({id: 'puppet var', name: 'oozie_user', value: 'oozie'});
  53. securityUsers.pushObject({id: 'puppet var', name: 'nagios_user', value: 'nagios'});
  54. securityUsers.pushObject({id: 'puppet var', name: 'user_group', value: 'hadoop'});
  55. } else {
  56. App.router.get('mainAdminSecurityController').setSecurityStatus();
  57. securityUsers = App.router.get('mainAdminSecurityController').get('serviceUsers');
  58. }
  59. }
  60. var isHbaseInstalled = App.Service.find().findProperty('serviceName', 'HBASE');
  61. var generalConfigs = configs.filterProperty('serviceName', 'GENERAL');
  62. var realm = generalConfigs.findProperty('name', 'kerberos_domain').value;
  63. var smokeUserId = securityUsers.findProperty('name', 'smokeuser').value;
  64. var hdfsUserId = securityUsers.findProperty('name', 'hdfs_user').value;
  65. var hbaseUserId = securityUsers.findProperty('name', 'hbase_user').value;
  66. var mapredUserId = securityUsers.findProperty('name', 'mapred_user').value;
  67. var hiveUserId = securityUsers.findProperty('name', 'hive_user').value;
  68. var zkUserId = securityUsers.findProperty('name', 'zk_user').value;
  69. var oozieUserId = securityUsers.findProperty('name', 'oozie_user').value;
  70. var nagiosUserId = securityUsers.findProperty('name', 'nagios_user').value;
  71. var hadoopGroupId = securityUsers.findProperty('name', 'user_group').value;
  72. var smokeUser = smokeUserId + '@' + realm;
  73. var hdfsUser = hdfsUserId + '@' + realm;
  74. var hbaseUser = hbaseUserId + '@' + realm;
  75. var smokeUserKeytabPath = generalConfigs.findProperty('name', 'smokeuser_keytab').value;
  76. var hdfsUserKeytabPath = generalConfigs.findProperty('name', 'keytab_path').value + "/hdfs.headless.keytab";
  77. var hbaseUserKeytabPath = generalConfigs.findProperty('name', 'keytab_path').value + "/hbase.headless.keytab";
  78. var httpPrincipal = generalConfigs.findProperty('name', 'hadoop_http_principal_name');
  79. var httpKeytabPath = generalConfigs.findProperty('name', 'hadoop_http_keytab').value;
  80. var componentToOwnerMap = {
  81. 'NAMENODE': hdfsUserId,
  82. 'SECONDARY_NAMENODE': hdfsUserId,
  83. 'DATANODE': hdfsUserId,
  84. 'TASKTRACKER': mapredUserId,
  85. 'JOBTRACKER': mapredUserId,
  86. 'ZOOKEEPER_SERVER': zkUserId,
  87. 'HIVE_SERVER': hiveUserId,
  88. 'OOZIE_SERVER': oozieUserId,
  89. 'NAGIOS_SERVER': nagiosUserId,
  90. 'HBASE_MASTER': hbaseUserId,
  91. 'HBASE_REGIONSERVER': hbaseUserId
  92. };
  93. var addedPrincipalsHost = {}; //Keys = host_principal, Value = 'true'
  94. hosts.forEach(function(host){
  95. result.push({
  96. host: host.get('hostName'),
  97. component: Em.I18n.t('admin.addSecurity.user.smokeUser'),
  98. principal: smokeUser,
  99. keytab: smokeUserKeytabPath,
  100. owner: smokeUserId,
  101. group: hadoopGroupId,
  102. acl: '440'
  103. });
  104. result.push({
  105. host: host.get('hostName'),
  106. component: Em.I18n.t('admin.addSecurity.user.hdfsUser'),
  107. principal: hdfsUser,
  108. keytab: hdfsUserKeytabPath,
  109. owner: hdfsUserId,
  110. group: hadoopGroupId,
  111. acl: '440'
  112. });
  113. if (isHbaseInstalled) {
  114. result.push({
  115. host: host.get('hostName'),
  116. component: Em.I18n.t('admin.addSecurity.user.hbaseUser'),
  117. principal: hbaseUser,
  118. keytab: hbaseUserKeytabPath,
  119. owner: hbaseUserId,
  120. group: hadoopGroupId,
  121. acl: '440'
  122. });
  123. }
  124. if(host.get('hostComponents').someProperty('componentName', 'NAMENODE') ||
  125. host.get('hostComponents').someProperty('componentName', 'SECONDARY_NAMENODE') ||
  126. host.get('hostComponents').someProperty('componentName', 'WEBHCAT_SERVER') ||
  127. host.get('hostComponents').someProperty('componentName', 'OOZIE_SERVER')){
  128. result.push({
  129. host: host.get('hostName'),
  130. component: Em.I18n.t('admin.addSecurity.user.httpUser'),
  131. principal: httpPrincipal.value.replace('_HOST', host.get('hostName')) + httpPrincipal.unit,
  132. keytab: httpKeytabPath,
  133. owner: 'root',
  134. group: hadoopGroupId,
  135. acl: '440'
  136. });
  137. }
  138. host.get('hostComponents').forEach(function(hostComponent){
  139. if(componentsToDisplay.contains(hostComponent.get('componentName'))){
  140. var serviceConfigs = configs.filterProperty('serviceName', hostComponent.get('service.serviceName'));
  141. var principal, keytab;
  142. serviceConfigs.forEach(function(config){
  143. if (config.component && config.component === hostComponent.get('componentName')) {
  144. if (config.name.endsWith('_principal_name')) {
  145. principal = config.value.replace('_HOST', host.get('hostName')) + config.unit;
  146. } else if (config.name.endsWith('_keytab') || config.name.endsWith('_keytab_path')) {
  147. keytab = config.value;
  148. }
  149. } else if (config.components && config.components.contains(hostComponent.get('componentName'))) {
  150. if (config.name.endsWith('_principal_name')) {
  151. principal = config.value.replace('_HOST', host.get('hostName')) + config.unit;
  152. } else if (config.name.endsWith('_keytab') || config.name.endsWith('_keytab_path')) {
  153. keytab = config.value;
  154. }
  155. }
  156. });
  157. var key = host.get('hostName') + "--" + principal;
  158. if (!addedPrincipalsHost[key]) {
  159. var owner = componentToOwnerMap[hostComponent.get('componentName')];
  160. if(!owner){
  161. owner = '';
  162. }
  163. result.push({
  164. host: host.get('hostName'),
  165. component: hostComponent.get('displayName'),
  166. principal: principal,
  167. keytab: keytab,
  168. owner: owner,
  169. group: hadoopGroupId,
  170. acl: '400'
  171. });
  172. addedPrincipalsHost[key] = true;
  173. }
  174. }
  175. });
  176. });
  177. this.set('hostComponents', result);
  178. }
  179. });