step3.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. hosts: [],
  24. isLoaded: false,
  25. componentToUserMap: {
  26. 'NAMENODE': 'hdfs_user',
  27. 'SECONDARY_NAMENODE': 'hdfs_user',
  28. 'DATANODE': 'hdfs_user',
  29. 'JOURNALNODE': 'hdfs_user',
  30. 'TASKTRACKER': 'mapred_user',
  31. 'JOBTRACKER': 'mapred_user',
  32. 'HISTORYSERVER': 'mapred_user',
  33. 'RESOURCEMANAGER': 'yarn_user',
  34. 'NODEMANAGER': 'yarn_user',
  35. 'ZOOKEEPER_SERVER': 'zk_user',
  36. 'HIVE_SERVER': 'hive_user',
  37. 'OOZIE_SERVER': 'oozie_user',
  38. 'NAGIOS_SERVER': 'nagios_user',
  39. 'HBASE_MASTER': 'hbase_user',
  40. 'HBASE_REGIONSERVER': 'hbase_user',
  41. 'SUPERVISOR': 'storm_user',
  42. 'NIMBUS': 'storm_user',
  43. 'STORM_UI_SERVER': 'storm_user',
  44. 'FALCON_SERVER': 'falcon_user'
  45. },
  46. componentToConfigMap: [
  47. {
  48. componentName: 'NAMENODE',
  49. principal: 'hadoop_http_principal_name',
  50. keytab: 'hadoop_http_keytab',
  51. displayName: Em.I18n.t('admin.addSecurity.hdfs.user.httpUser')
  52. },
  53. {
  54. componentName: 'SECONDARY_NAMENODE',
  55. principal: 'hadoop_http_principal_name',
  56. keytab: 'hadoop_http_keytab',
  57. displayName: Em.I18n.t('admin.addSecurity.hdfs.user.httpUser')
  58. },
  59. {
  60. componentName: 'JOURNALNODE',
  61. principal: 'hadoop_http_principal_name',
  62. keytab: 'hadoop_http_keytab',
  63. displayName: Em.I18n.t('admin.addSecurity.hdfs.user.httpUser')
  64. },
  65. {
  66. componentName: 'WEBHCAT_SERVER',
  67. principal: 'webHCat_http_principal_name',
  68. keytab: 'webhcat_http_keytab',
  69. displayName: Em.I18n.t('admin.addSecurity.webhcat.user.httpUser')
  70. },
  71. {
  72. componentName: 'OOZIE_SERVER',
  73. principal: 'oozie_http_principal_name',
  74. keytab: 'oozie_http_keytab',
  75. displayName: Em.I18n.t('admin.addSecurity.oozie.user.httpUser')
  76. },
  77. {
  78. componentName: 'FALCON_SERVER',
  79. principal: 'falcon_http_principal_name',
  80. keytab: 'falcon_http_keytab',
  81. displayName: Em.I18n.t('admin.addSecurity.falcon.user.httpUser')
  82. },
  83. {
  84. componentName: 'HISTORYSERVER',
  85. principal: 'jobhistory_http_principal_name',
  86. keytab: 'jobhistory_http_keytab',
  87. displayName: Em.I18n.t('admin.addSecurity.historyServer.user.httpUser'),
  88. isHadoop2Stack: true
  89. },
  90. {
  91. componentName: 'RESOURCEMANAGER',
  92. principal: 'resourcemanager_http_principal_name',
  93. keytab: 'resourcemanager_http_keytab',
  94. displayName: Em.I18n.t('admin.addSecurity.rm.user.httpUser'),
  95. isHadoop2Stack: true
  96. },
  97. {
  98. componentName: 'NODEMANAGER',
  99. principal: 'nodemanager_http_principal_name',
  100. keytab: 'nodemanager_http_keytab',
  101. displayName: Em.I18n.t('admin.addSecurity.nm.user.httpUser'),
  102. isHadoop2Stack: true
  103. }
  104. ],
  105. mandatoryConfigs: [
  106. {
  107. userConfig: 'smokeuser',
  108. keytab: 'smokeuser_keytab',
  109. displayName: Em.I18n.t('admin.addSecurity.user.smokeUser')
  110. },
  111. {
  112. userConfig: 'hdfs_user',
  113. keytab: 'hdfs_user_keytab',
  114. displayName: Em.I18n.t('admin.addSecurity.user.hdfsUser')
  115. },
  116. {
  117. userConfig: 'hbase_user',
  118. keytab: 'hbase_user_keytab',
  119. displayName: Em.I18n.t('admin.addSecurity.user.hbaseUser'),
  120. checkService: 'HBASE'
  121. }
  122. ],
  123. /**
  124. * mock users that used in testMode
  125. */
  126. testModeUsers: [
  127. { name: 'hdfs_user', value: 'hdfs'},
  128. { name: 'mapred_user', value: 'mapred'},
  129. { name: 'yarn_user', value: 'yarn'},
  130. { name: 'hbase_user', value: 'hbase'},
  131. { name: 'hive_user', value: 'hive'},
  132. { name: 'falcon_user', value: 'falcon'},
  133. { name: 'smokeuser', value: 'ambari-qa'},
  134. { name: 'zk_user', value: 'zookeeper'},
  135. { name: 'oozie_user', value: 'oozie'},
  136. { name: 'nagios_user', value: 'nagios'},
  137. { name: 'user_group', value: 'hadoop'}
  138. ],
  139. /**
  140. * download CSV file
  141. */
  142. doDownloadCsv: function () {
  143. if ($.browser.msie && $.browser.version < 10) {
  144. this.openInfoInNewTab();
  145. } else {
  146. try {
  147. var blob = new Blob([stringUtils.arrayToCSV(this.get('hostComponents'))], {type: "text/csv;charset=utf-8;"});
  148. saveAs(blob, "host-principal-keytab-list.csv");
  149. } catch (e) {
  150. this.openInfoInNewTab();
  151. }
  152. }
  153. },
  154. /**
  155. * open content of CSV file in new window
  156. */
  157. openInfoInNewTab: function () {
  158. var newWindow = window.open('');
  159. var newDocument = newWindow.document;
  160. newDocument.write(stringUtils.arrayToCSV(this.get('hostComponents')));
  161. newWindow.focus();
  162. },
  163. /**
  164. * load hosts from server
  165. */
  166. loadHosts: function () {
  167. App.ajax.send({
  168. name: 'hosts.security.wizard',
  169. sender: this,
  170. data: {},
  171. error: 'loadHostsErrorCallback',
  172. success: 'loadHostsSuccessCallback'
  173. })
  174. },
  175. loadHostsSuccessCallback: function (data, opt, params) {
  176. var hosts = [];
  177. data.items.forEach(function (item) {
  178. var hostComponents = [];
  179. item.host_components.forEach(function (hostComponent) {
  180. hostComponents.push(Em.Object.create({
  181. componentName: hostComponent.HostRoles.component_name,
  182. service: Em.Object.create({
  183. serviceName: hostComponent.HostRoles.service_name
  184. }),
  185. displayName: App.format.role(hostComponent.HostRoles.component_name)
  186. }));
  187. });
  188. hosts.push(Em.Object.create({
  189. hostName: item.Hosts.host_name,
  190. hostComponents: hostComponents
  191. }));
  192. });
  193. this.set('isLoaded', true);
  194. this.set('hosts', hosts);
  195. this.loadStep();
  196. },
  197. loadHostsErrorCallback: function () {
  198. this.set('isLoaded', true);
  199. this.set('hosts', []);
  200. this.loadStep();
  201. },
  202. /**
  203. * load step info
  204. */
  205. loadStep: function () {
  206. var hosts = this.get('hosts');
  207. var result = [];
  208. var securityUsers = this.getSecurityUsers();
  209. var hadoopGroupId = securityUsers.findProperty('name', 'user_group').value;
  210. var addedPrincipalsHost = {}; //Keys = host_principal, Value = 'true'
  211. hosts.forEach(function (host) {
  212. this.setMandatoryConfigs(result, securityUsers, host.get('hostName'), hadoopGroupId);
  213. this.setComponentsConfig(result, host, hadoopGroupId);
  214. this.setHostComponentsSecureValue(result, host, addedPrincipalsHost, securityUsers, hadoopGroupId);
  215. }, this);
  216. this.set('hostComponents', result);
  217. },
  218. /**
  219. * build map of connections between component and user
  220. * @param securityUsers
  221. */
  222. buildComponentToOwnerMap: function (securityUsers) {
  223. var componentToUserMap = this.get('componentToUserMap');
  224. var componentToOwnerMap = {};
  225. for (var component in componentToUserMap) {
  226. componentToOwnerMap[component] = securityUsers.findProperty('name', componentToUserMap[component]).value;
  227. }
  228. return componentToOwnerMap;
  229. },
  230. /**
  231. * set security settings(principal and keytab) to component depending on whether host has such component
  232. * @param result
  233. * @param host
  234. * @param hadoopGroupId
  235. */
  236. setComponentsConfig: function (result, host, hadoopGroupId) {
  237. var hostComponents = host.get('hostComponents');
  238. this.get('componentToConfigMap').forEach(function (component) {
  239. //add specific components that supported only in Hadoop2 stack
  240. if (component.isHadoop2Stack && !App.get('isHadoop2Stack')) return;
  241. if (hostComponents.someProperty('componentName', component.componentName)) {
  242. var configs = this.get('content.serviceConfigProperties');
  243. var serviceName = App.StackServiceComponent.find(component.componentName).get('serviceName');
  244. var serviceConfigs = configs.filterProperty('serviceName', serviceName);
  245. var servicePrincipal = serviceConfigs.findProperty('name', component.principal);
  246. var serviceKeytabPath = serviceConfigs.findProperty('name', component.keytab).value;
  247. result.push({
  248. host: host.get('hostName'),
  249. component: component.displayName,
  250. principal: this.getPrincipal(servicePrincipal, host.get('hostName')),
  251. keytabfile: stringUtils.getFileFromPath(serviceKeytabPath),
  252. keytab: stringUtils.getPath(serviceKeytabPath),
  253. owner: 'root',
  254. group: hadoopGroupId,
  255. acl: '440'
  256. });
  257. }
  258. }, this);
  259. },
  260. /**
  261. * set security settings(principal and keytab) to component
  262. * if checkService is passed then verify that service to his existence in order to set configs to such service
  263. * @param result
  264. * @param securityUsers
  265. * @param hostName
  266. * @param hadoopGroupId
  267. */
  268. setMandatoryConfigs: function (result, securityUsers, hostName, hadoopGroupId) {
  269. var generalConfigs = this.get('content.serviceConfigProperties').filterProperty('serviceName', 'GENERAL');
  270. var realm = generalConfigs.findProperty('name', 'kerberos_domain').value;
  271. var installedServices = App.Service.find().mapProperty('serviceName');
  272. this.get('mandatoryConfigs').forEach(function (config) {
  273. if (config.checkService && !installedServices.contains(config.checkService)) return;
  274. var userId = securityUsers.findProperty('name', config.userConfig).value;
  275. var userKeytabPath = generalConfigs.findProperty('name', config.keytab).value;
  276. result.push({
  277. host: hostName,
  278. component: config.displayName,
  279. principal: userId + '@' + realm,
  280. keytabFile: stringUtils.getFileFromPath(userKeytabPath),
  281. keytab: stringUtils.getPath(userKeytabPath),
  282. owner: userId,
  283. group: hadoopGroupId,
  284. acl: '440'
  285. });
  286. }, this);
  287. },
  288. /**
  289. * set secure properties(keytab and principal) for components, which should be displayed
  290. * @param result
  291. * @param host
  292. * @param addedPrincipalsHost
  293. * @param securityUsers
  294. * @param hadoopGroupId
  295. */
  296. setHostComponentsSecureValue: function (result, host, addedPrincipalsHost, securityUsers, hadoopGroupId) {
  297. var componentsToDisplay = ['NAMENODE', 'SECONDARY_NAMENODE', 'DATANODE', 'JOBTRACKER', 'ZOOKEEPER_SERVER', 'HIVE_SERVER', 'TASKTRACKER',
  298. 'OOZIE_SERVER', 'NAGIOS_SERVER', 'HBASE_MASTER', 'HBASE_REGIONSERVER', 'HISTORYSERVER', 'RESOURCEMANAGER', 'NODEMANAGER', 'JOURNALNODE',
  299. 'SUPERVISOR', 'NIMBUS', 'STORM_UI_SERVER', 'FALCON_SERVER'];
  300. var configs = this.get('content.serviceConfigProperties');
  301. var componentToOwnerMap = this.buildComponentToOwnerMap(securityUsers);
  302. var hostName = host.get('hostName');
  303. host.get('hostComponents').forEach(function (hostComponent) {
  304. if (componentsToDisplay.contains(hostComponent.get('componentName'))) {
  305. var serviceConfigs = configs.filterProperty('serviceName', hostComponent.get('service.serviceName'));
  306. var secureProperties = this.getSecureProperties(serviceConfigs, hostComponent.get('componentName'), hostName);
  307. var displayName = this.changeDisplayName(hostComponent.get('displayName'));
  308. var key = hostName + "--" + secureProperties.principal;
  309. if (Em.isNone(addedPrincipalsHost[key])) {
  310. var owner = componentToOwnerMap[hostComponent.get('componentName')] || '';
  311. result.push({
  312. host: hostName,
  313. component: displayName,
  314. principal: secureProperties.principal,
  315. keytabFile: stringUtils.getFileFromPath(secureProperties.keytab),
  316. keytab: stringUtils.getPath(secureProperties.keytab),
  317. owner: owner,
  318. group: hadoopGroupId,
  319. acl: '400'
  320. });
  321. addedPrincipalsHost[key] = true;
  322. }
  323. }
  324. }, this);
  325. },
  326. /**
  327. * get properties (keytab and principle) of secure config that match component
  328. * @param serviceConfigs
  329. * @param componentName
  330. * @param hostName
  331. * @return {Object}
  332. */
  333. getSecureProperties: function (serviceConfigs, componentName, hostName) {
  334. var secureProperties = {};
  335. serviceConfigs.forEach(function (config) {
  336. if ((config.component && config.component === componentName) ||
  337. (config.components && config.components.contains(componentName))) {
  338. if (config.name.endsWith('_principal_name')) {
  339. secureProperties.principal = this.getPrincipal(config, hostName);
  340. } else if (config.name.endsWith('_keytab') || config.name.endsWith('_keytab_path')) {
  341. secureProperties.keytab = config.value;
  342. }
  343. }
  344. }, this);
  345. return secureProperties;
  346. },
  347. /**
  348. * get formatted principal value
  349. * @param config
  350. * @param hostName
  351. * @return {String}
  352. */
  353. getPrincipal: function (config, hostName) {
  354. return config.value.replace('_HOST', hostName.toLowerCase()) + config.unit;
  355. },
  356. /**
  357. * get users from security configs
  358. * @return {Array}
  359. */
  360. getSecurityUsers: function () {
  361. var securityUsers = [];
  362. if (App.testMode) {
  363. this.get('testModeUsers').forEach(function (user) {
  364. securityUsers.push({
  365. id: 'puppet var',
  366. name: user.name,
  367. value: user.value
  368. });
  369. });
  370. } else {
  371. securityUsers = App.db.getSecureUserInfo();
  372. }
  373. return securityUsers;
  374. },
  375. /**
  376. * format display names of specific components
  377. * @param name
  378. * @return {*}
  379. */
  380. changeDisplayName: function (name) {
  381. if (name === 'HiveServer2') {
  382. return 'Hive Metastore and HiveServer2';
  383. } else {
  384. return name;
  385. }
  386. }
  387. });