step3.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. 'SUPERVISOR', 'NIMBUS', 'STORM_UI_SERVER','FALCON_SERVER'];
  48. var securityUsers = [];
  49. if (!securityUsers || securityUsers.length < 1) { // Page could be refreshed in middle
  50. securityUsers = this.getSecurityUsers();
  51. }
  52. var isHbaseInstalled = App.Service.find().findProperty('serviceName', 'HBASE');
  53. var isStormInstalled = App.Service.find().findProperty('serviceName', 'STORM');
  54. var generalConfigs = configs.filterProperty('serviceName', 'GENERAL');
  55. var hdfsConfigs = configs.filterProperty('serviceName', 'HDFS');
  56. var realm = generalConfigs.findProperty('name', 'kerberos_domain').value;
  57. var smokeUserId = securityUsers.findProperty('name', 'smokeuser').value;
  58. var hdfsUserId = securityUsers.findProperty('name', 'hdfs_user').value;
  59. var hbaseUserId = securityUsers.findProperty('name', 'hbase_user').value;
  60. var mapredUserId = securityUsers.findProperty('name', 'mapred_user').value;
  61. var yarnUserId = securityUsers.findProperty('name', 'yarn_user').value;
  62. var hiveUserId = securityUsers.findProperty('name', 'hive_user').value;
  63. var zkUserId = securityUsers.findProperty('name', 'zk_user').value;
  64. var oozieUserId = securityUsers.findProperty('name', 'oozie_user').value;
  65. var nagiosUserId = securityUsers.findProperty('name', 'nagios_user').value;
  66. var hadoopGroupId = securityUsers.findProperty('name', 'user_group').value;
  67. var stormUserId = securityUsers.findProperty('name', 'storm_user').value;
  68. var falconUserId = securityUsers.findProperty('name', 'falcon_user').value;
  69. var smokeUser = smokeUserId + '@' + realm;
  70. var hdfsUser = hdfsUserId + '@' + realm;
  71. var hbaseUser = hbaseUserId + '@' + realm;
  72. var stormUser = stormUserId + '@' + realm;
  73. var smokeUserKeytabPath = generalConfigs.findProperty('name', 'smokeuser_keytab').value;
  74. var hdfsUserKeytabPath = generalConfigs.findProperty('name', 'hdfs_user_keytab').value;
  75. var hbaseUserKeytabPath = generalConfigs.findProperty('name', 'hbase_user_keytab').value;
  76. var stormUserKeytabPath = generalConfigs.findProperty('name', 'storm_keytab').value;
  77. var hadoopHttpPrincipal = hdfsConfigs.findProperty('name', 'hadoop_http_principal_name');
  78. var hadoopHttpKeytabPath = hdfsConfigs.findProperty('name', 'hadoop_http_keytab').value;
  79. var componentToOwnerMap = {
  80. 'NAMENODE': hdfsUserId,
  81. 'SECONDARY_NAMENODE': hdfsUserId,
  82. 'DATANODE': hdfsUserId,
  83. 'JOURNALNODE': hdfsUserId,
  84. 'TASKTRACKER': mapredUserId,
  85. 'JOBTRACKER': mapredUserId,
  86. 'HISTORYSERVER': mapredUserId,
  87. 'RESOURCEMANAGER':yarnUserId,
  88. 'NODEMANAGER':yarnUserId,
  89. 'ZOOKEEPER_SERVER': zkUserId,
  90. 'HIVE_SERVER': hiveUserId,
  91. 'OOZIE_SERVER': oozieUserId,
  92. 'NAGIOS_SERVER': nagiosUserId,
  93. 'HBASE_MASTER': hbaseUserId,
  94. 'HBASE_REGIONSERVER': hbaseUserId,
  95. 'SUPERVISOR': stormUserId,
  96. 'NIMBUS': stormUserId,
  97. 'STORM_UI_SERVER': stormUserId,
  98. 'FALCON_SERVER': falconUserId
  99. };
  100. var addedPrincipalsHost = {}; //Keys = host_principal, Value = 'true'
  101. hosts.forEach(function (host) {
  102. result.push({
  103. host: host.get('hostName'),
  104. component: Em.I18n.t('admin.addSecurity.user.smokeUser'),
  105. principal: smokeUser,
  106. keytabFile: stringUtils.getFileFromPath(smokeUserKeytabPath),
  107. keytab: stringUtils.getPath(smokeUserKeytabPath),
  108. owner: smokeUserId,
  109. group: hadoopGroupId,
  110. acl: '440'
  111. });
  112. result.push({
  113. host: host.get('hostName'),
  114. component: Em.I18n.t('admin.addSecurity.user.hdfsUser'),
  115. principal: hdfsUser,
  116. keytabFile: stringUtils.getFileFromPath(hdfsUserKeytabPath),
  117. keytab: stringUtils.getPath(hdfsUserKeytabPath),
  118. owner: hdfsUserId,
  119. group: hadoopGroupId,
  120. acl: '440'
  121. });
  122. if (isHbaseInstalled) {
  123. result.push({
  124. host: host.get('hostName'),
  125. component: Em.I18n.t('admin.addSecurity.user.hbaseUser'),
  126. principal: hbaseUser,
  127. keytabFile: stringUtils.getFileFromPath(hbaseUserKeytabPath),
  128. keytab: stringUtils.getPath(hbaseUserKeytabPath),
  129. owner: hbaseUserId,
  130. group: hadoopGroupId,
  131. acl: '440'
  132. });
  133. }
  134. if (isStormInstalled) {
  135. result.push({
  136. host: host.get('hostName'),
  137. component: Em.I18n.t('admin.addSecurity.user.stormUser'),
  138. principal: stormUser,
  139. keytabFile: stringUtils.getFileFromPath(stormUserKeytabPath),
  140. keytab: stringUtils.getPath(stormUserKeytabPath),
  141. owner: stormUserId,
  142. group: hadoopGroupId,
  143. acl: '440'
  144. });
  145. }
  146. this.setComponentConfig(result,host,'NAMENODE','HDFS','hadoop_http_principal_name','hadoop_http_keytab',Em.I18n.t('admin.addSecurity.hdfs.user.httpUser'),hadoopGroupId);
  147. this.setComponentConfig(result,host,'SECONDARY_NAMENODE','HDFS','hadoop_http_principal_name','hadoop_http_keytab',Em.I18n.t('admin.addSecurity.hdfs.user.httpUser'),hadoopGroupId);
  148. this.setComponentConfig(result,host,'JOURNALNODE','HDFS','hadoop_http_principal_name','hadoop_http_keytab',Em.I18n.t('admin.addSecurity.hdfs.user.httpUser'),hadoopGroupId);
  149. this.setComponentConfig(result,host,'WEBHCAT_SERVER','WEBHCAT','webHCat_http_principal_name','webhcat_http_keytab',Em.I18n.t('admin.addSecurity.webhcat.user.httpUser'),hadoopGroupId);
  150. this.setComponentConfig(result,host,'OOZIE_SERVER','OOZIE','oozie_http_principal_name','oozie_http_keytab',Em.I18n.t('admin.addSecurity.oozie.user.httpUser'),hadoopGroupId);
  151. this.setComponentConfig(result,host,'FALCON_SERVER','FALCON','falcon_http_principal_name','falcon_http_keytab',Em.I18n.t('admin.addSecurity.falcon.user.httpUser'),hadoopGroupId);
  152. //Derive Principal name and Keytabs only if its HDP-2 stack
  153. if (App.get('isHadoop2Stack')) {
  154. this.setComponentConfig(result,host,'HISTORYSERVER','MAPREDUCE2','jobhistory_http_principal_name','jobhistory_http_keytab',Em.I18n.t('admin.addSecurity.historyServer.user.httpUser'),hadoopGroupId);
  155. this.setComponentConfig(result,host,'RESOURCEMANAGER','YARN','resourcemanager_http_principal_name','resourcemanager_http_keytab',Em.I18n.t('admin.addSecurity.rm.user.httpUser'),hadoopGroupId);
  156. this.setComponentConfig(result,host,'NODEMANAGER','YARN','nodemanager_http_principal_name','nodemanager_http_keytab',Em.I18n.t('admin.addSecurity.nm.user.httpUser'),hadoopGroupId);
  157. }
  158. host.get('hostComponents').forEach(function(hostComponent){
  159. if(componentsToDisplay.contains(hostComponent.get('componentName'))){
  160. var serviceConfigs = configs.filterProperty('serviceName', hostComponent.get('service.serviceName'));
  161. var principal, keytab;
  162. serviceConfigs.forEach(function (config) {
  163. if (config.component && config.component === hostComponent.get('componentName')) {
  164. if (config.name.endsWith('_principal_name')) {
  165. principal = config.value.replace('_HOST', host.get('hostName').toLowerCase()) + config.unit;
  166. } else if (config.name.endsWith('_keytab') || config.name.endsWith('_keytab_path')) {
  167. keytab = config.value;
  168. }
  169. } else if (config.components && config.components.contains(hostComponent.get('componentName'))) {
  170. if (config.name.endsWith('_principal_name')) {
  171. principal = config.value.replace('_HOST', host.get('hostName').toLowerCase()) + config.unit;
  172. } else if (config.name.endsWith('_keytab') || config.name.endsWith('_keytab_path')) {
  173. keytab = config.value;
  174. }
  175. }
  176. });
  177. var displayName = this.changeDisplayName(hostComponent.get('displayName'));
  178. var key = host.get('hostName') + "--" + principal;
  179. if (!addedPrincipalsHost[key]) {
  180. var owner = componentToOwnerMap[hostComponent.get('componentName')];
  181. if(!owner){
  182. owner = '';
  183. }
  184. result.push({
  185. host: host.get('hostName'),
  186. component: displayName,
  187. principal: principal,
  188. keytabFile: stringUtils.getFileFromPath(keytab),
  189. keytab: stringUtils.getPath(keytab),
  190. owner: owner,
  191. group: hadoopGroupId,
  192. acl: '400'
  193. });
  194. addedPrincipalsHost[key] = true;
  195. }
  196. }
  197. },this);
  198. },this);
  199. this.set('hostComponents', result);
  200. },
  201. getSecurityUsers: function() {
  202. var securityUsers = [];
  203. if (App.testMode) {
  204. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  205. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  206. securityUsers.pushObject({id: 'puppet var', name: 'yarn_user', value: 'yarn'});
  207. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  208. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  209. securityUsers.pushObject({id: 'puppet var', name: 'falcon_user', value: 'falcon'});
  210. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  211. securityUsers.pushObject({id: 'puppet var', name: 'zk_user', value: 'zookeeper'});
  212. securityUsers.pushObject({id: 'puppet var', name: 'oozie_user', value: 'oozie'});
  213. securityUsers.pushObject({id: 'puppet var', name: 'nagios_user', value: 'nagios'});
  214. securityUsers.pushObject({id: 'puppet var', name: 'user_group', value: 'hadoop'});
  215. } else {
  216. securityUsers = App.db.getSecureUserInfo();
  217. }
  218. return securityUsers;
  219. },
  220. setComponentConfig: function(hostComponents,host,componentName,serviceName,principal,keytab,displayName,groupId) {
  221. if (host.get('hostComponents').someProperty('componentName', componentName)) {
  222. var result = {};
  223. var configs = this.get('content.serviceConfigProperties');
  224. var serviceConfigs = configs.filterProperty('serviceName', serviceName);
  225. var servicePrincipal = serviceConfigs.findProperty('name', principal);
  226. var serviceKeytabPath = serviceConfigs.findProperty('name', keytab).value;
  227. result.host = host.get('hostName');
  228. result.component = displayName;
  229. result.principal = servicePrincipal.value.replace('_HOST', host.get('hostName').toLowerCase()) + servicePrincipal.unit;
  230. result.keytabfile = stringUtils.getFileFromPath(serviceKeytabPath);
  231. result.keytab = stringUtils.getPath(serviceKeytabPath);
  232. result.owner = 'root';
  233. result.group = groupId;
  234. result.acl = '440';
  235. hostComponents.push(result);
  236. }
  237. },
  238. changeDisplayName: function (name) {
  239. if (name === 'HiveServer2') {
  240. return 'Hive Metastore and HiveServer2';
  241. } else {
  242. return name;
  243. }
  244. }
  245. });