step3.js 15 KB

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