step3.js 15 KB

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