step3.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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'];
  47. var securityUsers = [];
  48. if (!securityUsers || securityUsers.length < 1) { // Page could be refreshed in middle
  49. securityUsers = this.getSecurityUsers();
  50. }
  51. var isHbaseInstalled = App.Service.find().findProperty('serviceName', 'HBASE');
  52. var generalConfigs = configs.filterProperty('serviceName', 'GENERAL');
  53. var hdfsConfigs = configs.filterProperty('serviceName', 'HDFS');
  54. var realm = generalConfigs.findProperty('name', 'kerberos_domain').value;
  55. var smokeUserId = securityUsers.findProperty('name', 'smokeuser').value;
  56. var hdfsUserId = securityUsers.findProperty('name', 'hdfs_user').value;
  57. var hbaseUserId = securityUsers.findProperty('name', 'hbase_user').value;
  58. var mapredUserId = securityUsers.findProperty('name', 'mapred_user').value;
  59. var yarnUserId = securityUsers.findProperty('name', 'yarn_user').value;
  60. var hiveUserId = securityUsers.findProperty('name', 'hive_user').value;
  61. var zkUserId = securityUsers.findProperty('name', 'zk_user').value;
  62. var oozieUserId = securityUsers.findProperty('name', 'oozie_user').value;
  63. var nagiosUserId = securityUsers.findProperty('name', 'nagios_user').value;
  64. var hadoopGroupId = securityUsers.findProperty('name', 'user_group').value;
  65. var smokeUser = smokeUserId + '@' + realm;
  66. var hdfsUser = hdfsUserId + '@' + realm;
  67. var hbaseUser = hbaseUserId + '@' + realm;
  68. var smokeUserKeytabPath = generalConfigs.findProperty('name', 'smokeuser_keytab').value;
  69. var hdfsUserKeytabPath = generalConfigs.findProperty('name', 'hdfs_user_keytab').value;
  70. var hbaseUserKeytabPath = generalConfigs.findProperty('name', 'hbase_user_keytab').value;
  71. var hadoopHttpPrincipal = hdfsConfigs.findProperty('name', 'hadoop_http_principal_name');
  72. var hadoopHttpKeytabPath = hdfsConfigs.findProperty('name', 'hadoop_http_keytab').value;
  73. var componentToOwnerMap = {
  74. 'NAMENODE': hdfsUserId,
  75. 'SECONDARY_NAMENODE': hdfsUserId,
  76. 'DATANODE': hdfsUserId,
  77. 'TASKTRACKER': mapredUserId,
  78. 'JOBTRACKER': mapredUserId,
  79. 'HISTORYSERVER': mapredUserId,
  80. 'RESOURCEMANAGER':yarnUserId,
  81. 'NODEMANAGER':yarnUserId,
  82. 'ZOOKEEPER_SERVER': zkUserId,
  83. 'HIVE_SERVER': hiveUserId,
  84. 'OOZIE_SERVER': oozieUserId,
  85. 'NAGIOS_SERVER': nagiosUserId,
  86. 'HBASE_MASTER': hbaseUserId,
  87. 'HBASE_REGIONSERVER': hbaseUserId
  88. };
  89. var addedPrincipalsHost = {}; //Keys = host_principal, Value = 'true'
  90. hosts.forEach(function (host) {
  91. result.push({
  92. host: host.get('hostName'),
  93. component: Em.I18n.t('admin.addSecurity.user.smokeUser'),
  94. principal: smokeUser,
  95. keytabFile: stringUtils.getFileFromPath(smokeUserKeytabPath),
  96. keytab: stringUtils.getPath(smokeUserKeytabPath),
  97. owner: smokeUserId,
  98. group: hadoopGroupId,
  99. acl: '440'
  100. });
  101. result.push({
  102. host: host.get('hostName'),
  103. component: Em.I18n.t('admin.addSecurity.user.hdfsUser'),
  104. principal: hdfsUser,
  105. keytabFile: stringUtils.getFileFromPath(hdfsUserKeytabPath),
  106. keytab: stringUtils.getPath(hdfsUserKeytabPath),
  107. owner: hdfsUserId,
  108. group: hadoopGroupId,
  109. acl: '440'
  110. });
  111. if (isHbaseInstalled) {
  112. result.push({
  113. host: host.get('hostName'),
  114. component: Em.I18n.t('admin.addSecurity.user.hbaseUser'),
  115. principal: hbaseUser,
  116. keytabFile: stringUtils.getFileFromPath(hbaseUserKeytabPath),
  117. keytab: stringUtils.getPath(hbaseUserKeytabPath),
  118. owner: hbaseUserId,
  119. group: hadoopGroupId,
  120. acl: '440'
  121. });
  122. }
  123. if(host.get('hostComponents').someProperty('componentName', 'NAMENODE') ||
  124. host.get('hostComponents').someProperty('componentName', 'SECONDARY_NAMENODE')){
  125. result.push({
  126. host: host.get('hostName'),
  127. component: Em.I18n.t('admin.addSecurity.hdfs.user.httpUser'),
  128. principal: hadoopHttpPrincipal.value.replace('_HOST', host.get('hostName').toLowerCase()) + hadoopHttpPrincipal.unit,
  129. keytabFile: stringUtils.getFileFromPath(hadoopHttpKeytabPath),
  130. keytab: stringUtils.getPath(hadoopHttpKeytabPath),
  131. owner: 'root',
  132. group: hadoopGroupId,
  133. acl: '440'
  134. });
  135. }
  136. if (host.get('hostComponents').someProperty('componentName', 'WEBHCAT_SERVER')) {
  137. var webHcatConfigs = configs.filterProperty('serviceName', 'WEBHCAT');
  138. var webHCatHttpPrincipal = webHcatConfigs.findProperty('name', 'webHCat_http_principal_name');
  139. var webHCatHttpKeytabPath = webHcatConfigs.findProperty('name', 'webhcat_http_keytab').value;
  140. result.push({
  141. host: host.get('hostName'),
  142. component: Em.I18n.t('admin.addSecurity.webhcat.user.httpUser'),
  143. principal: webHCatHttpPrincipal.value.replace('_HOST', host.get('hostName').toLowerCase()) + webHCatHttpPrincipal.unit,
  144. keytabFile: stringUtils.getFileFromPath(webHCatHttpKeytabPath),
  145. keytab: stringUtils.getPath(webHCatHttpKeytabPath),
  146. owner: 'root',
  147. group: hadoopGroupId,
  148. acl: '440'
  149. });
  150. }
  151. if (host.get('hostComponents').someProperty('componentName', 'OOZIE_SERVER')) {
  152. var oozieConfigs = configs.filterProperty('serviceName', 'OOZIE');
  153. var oozieHttpPrincipal = oozieConfigs.findProperty('name', 'oozie_http_principal_name');
  154. var oozieHttpKeytabPath = oozieConfigs.findProperty('name', 'oozie_http_keytab').value;
  155. result.push({
  156. host: host.get('hostName'),
  157. component: Em.I18n.t('admin.addSecurity.oozie.user.httpUser'),
  158. principal: oozieHttpPrincipal.value.replace('_HOST', host.get('hostName').toLowerCase()) + oozieHttpPrincipal.unit,
  159. keytabFile: stringUtils.getFileFromPath(oozieHttpKeytabPath),
  160. keytab: stringUtils.getPath(oozieHttpKeytabPath),
  161. owner: 'root',
  162. group: hadoopGroupId,
  163. acl: '440'
  164. });
  165. }
  166. host.get('hostComponents').forEach(function(hostComponent){
  167. if(componentsToDisplay.contains(hostComponent.get('componentName'))){
  168. var serviceConfigs = configs.filterProperty('serviceName', hostComponent.get('service.serviceName'));
  169. var principal, keytab;
  170. serviceConfigs.forEach(function (config) {
  171. if (config.component && config.component === hostComponent.get('componentName')) {
  172. if (config.name.endsWith('_principal_name')) {
  173. principal = config.value.replace('_HOST', host.get('hostName').toLowerCase()) + config.unit;
  174. } else if (config.name.endsWith('_keytab') || config.name.endsWith('_keytab_path')) {
  175. keytab = config.value;
  176. }
  177. } else if (config.components && config.components.contains(hostComponent.get('componentName'))) {
  178. if (config.name.endsWith('_principal_name')) {
  179. principal = config.value.replace('_HOST', host.get('hostName').toLowerCase()) + config.unit;
  180. } else if (config.name.endsWith('_keytab') || config.name.endsWith('_keytab_path')) {
  181. keytab = config.value;
  182. }
  183. }
  184. });
  185. var displayName = this.changeDisplayName(hostComponent.get('displayName'));
  186. var key = host.get('hostName') + "--" + principal;
  187. if (!addedPrincipalsHost[key]) {
  188. var owner = componentToOwnerMap[hostComponent.get('componentName')];
  189. if(!owner){
  190. owner = '';
  191. }
  192. result.push({
  193. host: host.get('hostName'),
  194. component: displayName,
  195. principal: principal,
  196. keytabFile: stringUtils.getFileFromPath(keytab),
  197. keytab: stringUtils.getPath(keytab),
  198. owner: owner,
  199. group: hadoopGroupId,
  200. acl: '400'
  201. });
  202. addedPrincipalsHost[key] = true;
  203. }
  204. }
  205. },this);
  206. },this);
  207. this.set('hostComponents', result);
  208. },
  209. getSecurityUsers: function() {
  210. var securityUsers = [];
  211. if (App.testMode) {
  212. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  213. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  214. securityUsers.pushObject({id: 'puppet var', name: 'yarn_user', value: 'yarn'});
  215. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  216. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  217. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  218. securityUsers.pushObject({id: 'puppet var', name: 'zk_user', value: 'zookeeper'});
  219. securityUsers.pushObject({id: 'puppet var', name: 'oozie_user', value: 'oozie'});
  220. securityUsers.pushObject({id: 'puppet var', name: 'nagios_user', value: 'nagios'});
  221. securityUsers.pushObject({id: 'puppet var', name: 'user_group', value: 'hadoop'});
  222. } else {
  223. App.router.get('mainAdminSecurityController').setSecurityStatus();
  224. securityUsers = App.router.get('mainAdminSecurityController').get('serviceUsers');
  225. }
  226. return securityUsers;
  227. },
  228. changeDisplayName: function (name) {
  229. if (name === 'HiveServer2') {
  230. return 'Hive Metastore and HiveServer2';
  231. } else {
  232. return name;
  233. }
  234. }
  235. });