step3.js 11 KB

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