step3.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. doDownloadCsv: function () {
  24. if ($.browser.msie && $.browser.version < 10) {
  25. this.openInfoInNewTab();
  26. } else {
  27. try {
  28. var blob = new Blob([stringUtils.arrayToCSV(this.get('hostComponents'))], {type: "text/csv;charset=utf-8;"});
  29. saveAs(blob, "host-principal-keytab-list.csv");
  30. } catch(e) {
  31. this.openInfoInNewTab();
  32. }
  33. }
  34. },
  35. openInfoInNewTab: function () {
  36. var newWindow = window.open('');
  37. var newDocument = newWindow.document;
  38. newDocument.write(stringUtils.arrayToCSV(this.get('hostComponents')));
  39. newWindow.focus();
  40. },
  41. loadStep: function(){
  42. var configs = this.get('content.serviceConfigProperties');
  43. var hosts = App.Host.find();
  44. var result = [];
  45. var componentsToDisplay = ['NAMENODE', 'SECONDARY_NAMENODE', 'DATANODE', 'JOBTRACKER', 'ZOOKEEPER_SERVER', 'HIVE_SERVER', 'TASKTRACKER',
  46. 'OOZIE_SERVER', 'NAGIOS_SERVER', 'HBASE_MASTER', 'HBASE_REGIONSERVER','HISTORYSERVER','RESOURCEMANAGER','NODEMANAGER','JOURNALNODE',
  47. 'SUPERVISOR', 'NIMBUS', 'STORM_UI_SERVER','FALCON_SERVER'];
  48. var securityUsers = [];
  49. if (!securityUsers || securityUsers.length < 1) { // Page could be refreshed in middle
  50. securityUsers = this.getSecurityUsers();
  51. }
  52. var isHbaseInstalled = App.Service.find().findProperty('serviceName', 'HBASE');
  53. var isStormInstalled = App.Service.find().findProperty('serviceName', 'STORM');
  54. var generalConfigs = configs.filterProperty('serviceName', 'GENERAL');
  55. var hdfsConfigs = configs.filterProperty('serviceName', 'HDFS');
  56. var realm = generalConfigs.findProperty('name', 'kerberos_domain').value;
  57. var smokeUserId = securityUsers.findProperty('name', 'smokeuser').value;
  58. var hdfsUserId = securityUsers.findProperty('name', 'hdfs_user').value;
  59. var hbaseUserId = securityUsers.findProperty('name', 'hbase_user').value;
  60. var mapredUserId = securityUsers.findProperty('name', 'mapred_user').value;
  61. var yarnUserId = securityUsers.findProperty('name', 'yarn_user').value;
  62. var hiveUserId = securityUsers.findProperty('name', 'hive_user').value;
  63. var zkUserId = securityUsers.findProperty('name', 'zk_user').value;
  64. var oozieUserId = securityUsers.findProperty('name', 'oozie_user').value;
  65. var nagiosUserId = securityUsers.findProperty('name', 'nagios_user').value;
  66. var hadoopGroupId = securityUsers.findProperty('name', 'user_group').value;
  67. var stormUserId = securityUsers.findProperty('name', 'storm_user').value;
  68. var falconUserId = securityUsers.findProperty('name', 'falcon_user').value;
  69. var smokeUser = smokeUserId + '@' + realm;
  70. var hdfsUser = hdfsUserId + '@' + realm;
  71. var hbaseUser = hbaseUserId + '@' + realm;
  72. var stormUser = stormUserId + '@' + realm;
  73. var smokeUserKeytabPath = generalConfigs.findProperty('name', 'smokeuser_keytab').value;
  74. var hdfsUserKeytabPath = generalConfigs.findProperty('name', 'hdfs_user_keytab').value;
  75. var hbaseUserKeytabPath = generalConfigs.findProperty('name', 'hbase_user_keytab').value;
  76. var hadoopHttpPrincipal = hdfsConfigs.findProperty('name', 'hadoop_http_principal_name');
  77. var hadoopHttpKeytabPath = hdfsConfigs.findProperty('name', 'hadoop_http_keytab').value;
  78. var componentToOwnerMap = {
  79. 'NAMENODE': hdfsUserId,
  80. 'SECONDARY_NAMENODE': hdfsUserId,
  81. 'DATANODE': hdfsUserId,
  82. 'JOURNALNODE': hdfsUserId,
  83. 'TASKTRACKER': mapredUserId,
  84. 'JOBTRACKER': mapredUserId,
  85. 'HISTORYSERVER': mapredUserId,
  86. 'RESOURCEMANAGER':yarnUserId,
  87. 'NODEMANAGER':yarnUserId,
  88. 'ZOOKEEPER_SERVER': zkUserId,
  89. 'HIVE_SERVER': hiveUserId,
  90. 'OOZIE_SERVER': oozieUserId,
  91. 'NAGIOS_SERVER': nagiosUserId,
  92. 'HBASE_MASTER': hbaseUserId,
  93. 'HBASE_REGIONSERVER': hbaseUserId,
  94. 'SUPERVISOR': stormUserId,
  95. 'NIMBUS': stormUserId,
  96. 'STORM_UI_SERVER': stormUserId,
  97. 'FALCON_SERVER': falconUserId
  98. };
  99. var addedPrincipalsHost = {}; //Keys = host_principal, Value = 'true'
  100. hosts.forEach(function (host) {
  101. result.push({
  102. host: host.get('hostName'),
  103. component: Em.I18n.t('admin.addSecurity.user.smokeUser'),
  104. principal: smokeUser,
  105. keytabFile: stringUtils.getFileFromPath(smokeUserKeytabPath),
  106. keytab: stringUtils.getPath(smokeUserKeytabPath),
  107. owner: smokeUserId,
  108. group: hadoopGroupId,
  109. acl: '440'
  110. });
  111. result.push({
  112. host: host.get('hostName'),
  113. component: Em.I18n.t('admin.addSecurity.user.hdfsUser'),
  114. principal: hdfsUser,
  115. keytabFile: stringUtils.getFileFromPath(hdfsUserKeytabPath),
  116. keytab: stringUtils.getPath(hdfsUserKeytabPath),
  117. owner: hdfsUserId,
  118. group: hadoopGroupId,
  119. acl: '440'
  120. });
  121. if (isHbaseInstalled) {
  122. result.push({
  123. host: host.get('hostName'),
  124. component: Em.I18n.t('admin.addSecurity.user.hbaseUser'),
  125. principal: hbaseUser,
  126. keytabFile: stringUtils.getFileFromPath(hbaseUserKeytabPath),
  127. keytab: stringUtils.getPath(hbaseUserKeytabPath),
  128. owner: hbaseUserId,
  129. group: hadoopGroupId,
  130. acl: '440'
  131. });
  132. }
  133. this.setComponentConfig(result,host,'NAMENODE','HDFS','hadoop_http_principal_name','hadoop_http_keytab',Em.I18n.t('admin.addSecurity.hdfs.user.httpUser'),hadoopGroupId);
  134. this.setComponentConfig(result,host,'SECONDARY_NAMENODE','HDFS','hadoop_http_principal_name','hadoop_http_keytab',Em.I18n.t('admin.addSecurity.hdfs.user.httpUser'),hadoopGroupId);
  135. this.setComponentConfig(result,host,'JOURNALNODE','HDFS','hadoop_http_principal_name','hadoop_http_keytab',Em.I18n.t('admin.addSecurity.hdfs.user.httpUser'),hadoopGroupId);
  136. this.setComponentConfig(result,host,'WEBHCAT_SERVER','WEBHCAT','webHCat_http_principal_name','webhcat_http_keytab',Em.I18n.t('admin.addSecurity.webhcat.user.httpUser'),hadoopGroupId);
  137. this.setComponentConfig(result,host,'OOZIE_SERVER','OOZIE','oozie_http_principal_name','oozie_http_keytab',Em.I18n.t('admin.addSecurity.oozie.user.httpUser'),hadoopGroupId);
  138. this.setComponentConfig(result,host,'FALCON_SERVER','FALCON','falcon_http_principal_name','falcon_http_keytab',Em.I18n.t('admin.addSecurity.falcon.user.httpUser'),hadoopGroupId);
  139. //Derive Principal name and Keytabs only if its HDP-2 stack
  140. if (App.get('isHadoop2Stack')) {
  141. this.setComponentConfig(result,host,'HISTORYSERVER','MAPREDUCE2','jobhistory_http_principal_name','jobhistory_http_keytab',Em.I18n.t('admin.addSecurity.historyServer.user.httpUser'),hadoopGroupId);
  142. this.setComponentConfig(result,host,'RESOURCEMANAGER','YARN','resourcemanager_http_principal_name','resourcemanager_http_keytab',Em.I18n.t('admin.addSecurity.rm.user.httpUser'),hadoopGroupId);
  143. this.setComponentConfig(result,host,'NODEMANAGER','YARN','nodemanager_http_principal_name','nodemanager_http_keytab',Em.I18n.t('admin.addSecurity.nm.user.httpUser'),hadoopGroupId);
  144. }
  145. host.get('hostComponents').forEach(function(hostComponent){
  146. if(componentsToDisplay.contains(hostComponent.get('componentName'))){
  147. var serviceConfigs = configs.filterProperty('serviceName', hostComponent.get('service.serviceName'));
  148. var principal, keytab;
  149. serviceConfigs.forEach(function (config) {
  150. if (config.component && config.component === hostComponent.get('componentName')) {
  151. if (config.name.endsWith('_principal_name')) {
  152. principal = config.value.replace('_HOST', host.get('hostName').toLowerCase()) + config.unit;
  153. } else if (config.name.endsWith('_keytab') || config.name.endsWith('_keytab_path')) {
  154. keytab = config.value;
  155. }
  156. } else if (config.components && config.components.contains(hostComponent.get('componentName'))) {
  157. if (config.name.endsWith('_principal_name')) {
  158. principal = config.value.replace('_HOST', host.get('hostName').toLowerCase()) + config.unit;
  159. } else if (config.name.endsWith('_keytab') || config.name.endsWith('_keytab_path')) {
  160. keytab = config.value;
  161. }
  162. }
  163. });
  164. var displayName = this.changeDisplayName(hostComponent.get('displayName'));
  165. var key = host.get('hostName') + "--" + principal;
  166. if (!addedPrincipalsHost[key]) {
  167. var owner = componentToOwnerMap[hostComponent.get('componentName')];
  168. if(!owner){
  169. owner = '';
  170. }
  171. result.push({
  172. host: host.get('hostName'),
  173. component: displayName,
  174. principal: principal,
  175. keytabFile: stringUtils.getFileFromPath(keytab),
  176. keytab: stringUtils.getPath(keytab),
  177. owner: owner,
  178. group: hadoopGroupId,
  179. acl: '400'
  180. });
  181. addedPrincipalsHost[key] = true;
  182. }
  183. }
  184. },this);
  185. },this);
  186. this.set('hostComponents', result);
  187. },
  188. getSecurityUsers: function() {
  189. var securityUsers = [];
  190. if (App.testMode) {
  191. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  192. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  193. securityUsers.pushObject({id: 'puppet var', name: 'yarn_user', value: 'yarn'});
  194. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  195. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  196. securityUsers.pushObject({id: 'puppet var', name: 'falcon_user', value: 'falcon'});
  197. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  198. securityUsers.pushObject({id: 'puppet var', name: 'zk_user', value: 'zookeeper'});
  199. securityUsers.pushObject({id: 'puppet var', name: 'oozie_user', value: 'oozie'});
  200. securityUsers.pushObject({id: 'puppet var', name: 'nagios_user', value: 'nagios'});
  201. securityUsers.pushObject({id: 'puppet var', name: 'user_group', value: 'hadoop'});
  202. } else {
  203. securityUsers = App.db.getSecureUserInfo();
  204. }
  205. return securityUsers;
  206. },
  207. setComponentConfig: function(hostComponents,host,componentName,serviceName,principal,keytab,displayName,groupId) {
  208. if (host.get('hostComponents').someProperty('componentName', componentName)) {
  209. var result = {};
  210. var configs = this.get('content.serviceConfigProperties');
  211. var serviceConfigs = configs.filterProperty('serviceName', serviceName);
  212. var servicePrincipal = serviceConfigs.findProperty('name', principal);
  213. var serviceKeytabPath = serviceConfigs.findProperty('name', keytab).value;
  214. result.host = host.get('hostName');
  215. result.component = displayName;
  216. result.principal = servicePrincipal.value.replace('_HOST', host.get('hostName').toLowerCase()) + servicePrincipal.unit;
  217. result.keytabfile = stringUtils.getFileFromPath(serviceKeytabPath);
  218. result.keytab = stringUtils.getPath(serviceKeytabPath);
  219. result.owner = 'root';
  220. result.group = groupId;
  221. result.acl = '440';
  222. hostComponents.push(result);
  223. }
  224. },
  225. changeDisplayName: function (name) {
  226. if (name === 'HiveServer2') {
  227. return 'Hive Metastore and HiveServer2';
  228. } else {
  229. return name;
  230. }
  231. }
  232. });