step3.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. try {
  28. var blob = new Blob([stringUtils.arrayToCSV(this.get('hostComponents'))], {type: "text/csv;charset=utf-8;"});
  29. saveAs(blob, "host-principal-keytab-list.csv");
  30. } catch(e) {
  31. this.openInfoInNewTab();
  32. }
  33. }
  34. },
  35. openInfoInNewTab: function () {
  36. var newWindow = window.open('');
  37. var newDocument = newWindow.document;
  38. newDocument.write(stringUtils.arrayToCSV(this.get('hostComponents')));
  39. newWindow.focus();
  40. },
  41. loadStep: function(){
  42. var configs = this.get('content.serviceConfigProperties');
  43. var hosts = App.Host.find();
  44. var result = [];
  45. var componentsToDisplay = ['NAMENODE', 'SECONDARY_NAMENODE', 'DATANODE', 'JOBTRACKER', 'ZOOKEEPER_SERVER', 'HIVE_SERVER', 'TASKTRACKER',
  46. 'OOZIE_SERVER', 'NAGIOS_SERVER', 'HBASE_MASTER', 'HBASE_REGIONSERVER','HISTORYSERVER','RESOURCEMANAGER','NODEMANAGER','JOURNALNODE'];
  47. var securityUsers = [];
  48. if (!securityUsers || securityUsers.length < 1) { // Page could be refreshed in middle
  49. securityUsers = this.getSecurityUsers();
  50. }
  51. var isHbaseInstalled = App.Service.find().findProperty('serviceName', 'HBASE');
  52. var generalConfigs = configs.filterProperty('serviceName', 'GENERAL');
  53. var hdfsConfigs = configs.filterProperty('serviceName', 'HDFS');
  54. var realm = generalConfigs.findProperty('name', 'kerberos_domain').value;
  55. var smokeUserId = securityUsers.findProperty('name', 'smokeuser').value;
  56. var hdfsUserId = securityUsers.findProperty('name', 'hdfs_user').value;
  57. var hbaseUserId = securityUsers.findProperty('name', 'hbase_user').value;
  58. var mapredUserId = securityUsers.findProperty('name', 'mapred_user').value;
  59. var yarnUserId = securityUsers.findProperty('name', 'yarn_user').value;
  60. var hiveUserId = securityUsers.findProperty('name', 'hive_user').value;
  61. var zkUserId = securityUsers.findProperty('name', 'zk_user').value;
  62. var oozieUserId = securityUsers.findProperty('name', 'oozie_user').value;
  63. var nagiosUserId = securityUsers.findProperty('name', 'nagios_user').value;
  64. var hadoopGroupId = securityUsers.findProperty('name', 'user_group').value;
  65. var smokeUser = smokeUserId + '@' + realm;
  66. var hdfsUser = hdfsUserId + '@' + realm;
  67. var hbaseUser = hbaseUserId + '@' + realm;
  68. var smokeUserKeytabPath = generalConfigs.findProperty('name', 'smokeuser_keytab').value;
  69. var hdfsUserKeytabPath = generalConfigs.findProperty('name', 'hdfs_user_keytab').value;
  70. var hbaseUserKeytabPath = generalConfigs.findProperty('name', 'hbase_user_keytab').value;
  71. var hadoopHttpPrincipal = hdfsConfigs.findProperty('name', 'hadoop_http_principal_name');
  72. var hadoopHttpKeytabPath = hdfsConfigs.findProperty('name', 'hadoop_http_keytab').value;
  73. var componentToOwnerMap = {
  74. 'NAMENODE': hdfsUserId,
  75. 'SECONDARY_NAMENODE': hdfsUserId,
  76. 'DATANODE': hdfsUserId,
  77. 'JOURNALNODE': hdfsUserId,
  78. 'TASKTRACKER': mapredUserId,
  79. 'JOBTRACKER': mapredUserId,
  80. 'HISTORYSERVER': mapredUserId,
  81. 'RESOURCEMANAGER':yarnUserId,
  82. 'NODEMANAGER':yarnUserId,
  83. 'ZOOKEEPER_SERVER': zkUserId,
  84. 'HIVE_SERVER': hiveUserId,
  85. 'OOZIE_SERVER': oozieUserId,
  86. 'NAGIOS_SERVER': nagiosUserId,
  87. 'HBASE_MASTER': hbaseUserId,
  88. 'HBASE_REGIONSERVER': hbaseUserId
  89. };
  90. var addedPrincipalsHost = {}; //Keys = host_principal, Value = 'true'
  91. hosts.forEach(function (host) {
  92. result.push({
  93. host: host.get('hostName'),
  94. component: Em.I18n.t('admin.addSecurity.user.smokeUser'),
  95. principal: smokeUser,
  96. keytabFile: stringUtils.getFileFromPath(smokeUserKeytabPath),
  97. keytab: stringUtils.getPath(smokeUserKeytabPath),
  98. owner: smokeUserId,
  99. group: hadoopGroupId,
  100. acl: '440'
  101. });
  102. result.push({
  103. host: host.get('hostName'),
  104. component: Em.I18n.t('admin.addSecurity.user.hdfsUser'),
  105. principal: hdfsUser,
  106. keytabFile: stringUtils.getFileFromPath(hdfsUserKeytabPath),
  107. keytab: stringUtils.getPath(hdfsUserKeytabPath),
  108. owner: hdfsUserId,
  109. group: hadoopGroupId,
  110. acl: '440'
  111. });
  112. if (isHbaseInstalled) {
  113. result.push({
  114. host: host.get('hostName'),
  115. component: Em.I18n.t('admin.addSecurity.user.hbaseUser'),
  116. principal: hbaseUser,
  117. keytabFile: stringUtils.getFileFromPath(hbaseUserKeytabPath),
  118. keytab: stringUtils.getPath(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') || host.get('hostComponents').someProperty('componentName', 'JOURNALNODE')){
  126. result.push({
  127. host: host.get('hostName'),
  128. component: Em.I18n.t('admin.addSecurity.hdfs.user.httpUser'),
  129. principal: hadoopHttpPrincipal.value.replace('_HOST', host.get('hostName').toLowerCase()) + hadoopHttpPrincipal.unit,
  130. keytabFile: stringUtils.getFileFromPath(hadoopHttpKeytabPath),
  131. keytab: stringUtils.getPath(hadoopHttpKeytabPath),
  132. owner: 'root',
  133. group: hadoopGroupId,
  134. acl: '440'
  135. });
  136. }
  137. if (host.get('hostComponents').someProperty('componentName', 'WEBHCAT_SERVER')) {
  138. var webHcatConfigs = configs.filterProperty('serviceName', 'WEBHCAT');
  139. var webHCatHttpPrincipal = webHcatConfigs.findProperty('name', 'webHCat_http_principal_name');
  140. var webHCatHttpKeytabPath = webHcatConfigs.findProperty('name', 'webhcat_http_keytab').value;
  141. result.push({
  142. host: host.get('hostName'),
  143. component: Em.I18n.t('admin.addSecurity.webhcat.user.httpUser'),
  144. principal: webHCatHttpPrincipal.value.replace('_HOST', host.get('hostName').toLowerCase()) + webHCatHttpPrincipal.unit,
  145. keytabFile: stringUtils.getFileFromPath(webHCatHttpKeytabPath),
  146. keytab: stringUtils.getPath(webHCatHttpKeytabPath),
  147. owner: 'root',
  148. group: hadoopGroupId,
  149. acl: '440'
  150. });
  151. }
  152. if (host.get('hostComponents').someProperty('componentName', 'OOZIE_SERVER')) {
  153. var oozieConfigs = configs.filterProperty('serviceName', 'OOZIE');
  154. var oozieHttpPrincipal = oozieConfigs.findProperty('name', 'oozie_http_principal_name');
  155. var oozieHttpKeytabPath = oozieConfigs.findProperty('name', 'oozie_http_keytab').value;
  156. result.push({
  157. host: host.get('hostName'),
  158. component: Em.I18n.t('admin.addSecurity.oozie.user.httpUser'),
  159. principal: oozieHttpPrincipal.value.replace('_HOST', host.get('hostName').toLowerCase()) + oozieHttpPrincipal.unit,
  160. keytabFile: stringUtils.getFileFromPath(oozieHttpKeytabPath),
  161. keytab: stringUtils.getPath(oozieHttpKeytabPath),
  162. owner: 'root',
  163. group: hadoopGroupId,
  164. acl: '440'
  165. });
  166. }
  167. this.setComponentConfig(result,host,'HISTORYSERVER','MAPREDUCE2','jobhistory_http_principal_name','jobhistory_http_keytab',Em.I18n.t('admin.addSecurity.historyServer.user.httpUser'),hadoopGroupId);
  168. this.setComponentConfig(result,host,'RESOURCEMANAGER','YARN','resourcemanager_http_principal_name','resourcemanager_http_keytab',Em.I18n.t('admin.addSecurity.rm.user.httpUser'),hadoopGroupId);
  169. this.setComponentConfig(result,host,'NODEMANAGER','YARN','nodemanager_http_principal_name','nodemanager_http_keytab',Em.I18n.t('admin.addSecurity.nm.user.httpUser'),hadoopGroupId);
  170. host.get('hostComponents').forEach(function(hostComponent){
  171. if(componentsToDisplay.contains(hostComponent.get('componentName'))){
  172. var serviceConfigs = configs.filterProperty('serviceName', hostComponent.get('service.serviceName'));
  173. var principal, keytab;
  174. serviceConfigs.forEach(function (config) {
  175. if (config.component && config.component === hostComponent.get('componentName')) {
  176. if (config.name.endsWith('_principal_name')) {
  177. principal = config.value.replace('_HOST', host.get('hostName').toLowerCase()) + config.unit;
  178. } else if (config.name.endsWith('_keytab') || config.name.endsWith('_keytab_path')) {
  179. keytab = config.value;
  180. }
  181. } else if (config.components && config.components.contains(hostComponent.get('componentName'))) {
  182. if (config.name.endsWith('_principal_name')) {
  183. principal = config.value.replace('_HOST', host.get('hostName').toLowerCase()) + config.unit;
  184. } else if (config.name.endsWith('_keytab') || config.name.endsWith('_keytab_path')) {
  185. keytab = config.value;
  186. }
  187. }
  188. });
  189. var displayName = this.changeDisplayName(hostComponent.get('displayName'));
  190. var key = host.get('hostName') + "--" + principal;
  191. if (!addedPrincipalsHost[key]) {
  192. var owner = componentToOwnerMap[hostComponent.get('componentName')];
  193. if(!owner){
  194. owner = '';
  195. }
  196. result.push({
  197. host: host.get('hostName'),
  198. component: displayName,
  199. principal: principal,
  200. keytabFile: stringUtils.getFileFromPath(keytab),
  201. keytab: stringUtils.getPath(keytab),
  202. owner: owner,
  203. group: hadoopGroupId,
  204. acl: '400'
  205. });
  206. addedPrincipalsHost[key] = true;
  207. }
  208. }
  209. },this);
  210. },this);
  211. this.set('hostComponents', result);
  212. },
  213. getSecurityUsers: function() {
  214. var securityUsers = [];
  215. if (App.testMode) {
  216. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  217. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  218. securityUsers.pushObject({id: 'puppet var', name: 'yarn_user', value: 'yarn'});
  219. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  220. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  221. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  222. securityUsers.pushObject({id: 'puppet var', name: 'zk_user', value: 'zookeeper'});
  223. securityUsers.pushObject({id: 'puppet var', name: 'oozie_user', value: 'oozie'});
  224. securityUsers.pushObject({id: 'puppet var', name: 'nagios_user', value: 'nagios'});
  225. securityUsers.pushObject({id: 'puppet var', name: 'user_group', value: 'hadoop'});
  226. } else {
  227. App.router.get('mainAdminSecurityController').setSecurityStatus();
  228. securityUsers = App.router.get('mainAdminSecurityController').get('serviceUsers');
  229. }
  230. return securityUsers;
  231. },
  232. setComponentConfig: function(hostComponents,host,componentName,serviceName,principal,keytab,displayName,groupId) {
  233. if (host.get('hostComponents').someProperty('componentName', componentName)) {
  234. var result = {};
  235. var configs = this.get('content.serviceConfigProperties');
  236. var serviceConfigs = configs.filterProperty('serviceName', serviceName);
  237. var servicePrincipal = serviceConfigs.findProperty('name', principal);
  238. var serviceKeytabPath = serviceConfigs.findProperty('name', keytab).value;
  239. result.host = host.get('hostName');
  240. result.component = displayName;
  241. result.principal = servicePrincipal.value.replace('_HOST', host.get('hostName').toLowerCase()) + servicePrincipal.unit;
  242. result.keytabfile = stringUtils.getFileFromPath(serviceKeytabPath);
  243. result.keytab = stringUtils.getPath(serviceKeytabPath);
  244. result.owner = 'root';
  245. result.group = groupId;
  246. result.acl = '440';
  247. hostComponents.push(result);
  248. }
  249. },
  250. changeDisplayName: function (name) {
  251. if (name === 'HiveServer2') {
  252. return 'Hive Metastore and HiveServer2';
  253. } else {
  254. return name;
  255. }
  256. }
  257. });