step3.js 15 KB

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