step3.js 11 KB

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