step3.js 16 KB

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