step3.js 15 KB

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