security.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. App.MainAdminSecurityController = Em.Controller.extend({
  20. name: 'mainAdminSecurityController',
  21. isSubmitDisabled: false,
  22. securityEnabled: false,
  23. dataIsLoaded: false,
  24. serviceUsers: [],
  25. tag: {},
  26. getAddSecurityWizardStatus: function () {
  27. return App.db.getSecurityWizardStatus();
  28. },
  29. setAddSecurityWizardStatus: function (status) {
  30. App.db.setSecurityWizardStatus(status);
  31. },
  32. setDisableSecurityStatus: function (status) {
  33. App.db.setDisableSecurityStatus(status);
  34. },
  35. getDisableSecurityStatus: function (status) {
  36. return App.db.getDisableSecurityStatus();
  37. },
  38. notifySecurityOff: false,
  39. notifySecurityAdd: false,
  40. stepConfigs: [],
  41. desiredConfigs: [],
  42. securityUsers: [],
  43. serviceConfigTags: [],
  44. selectedService: null,
  45. isNotEditable: true,
  46. services: function () {
  47. var secureServices;
  48. var services = [];
  49. if (App.get('isHadoop2Stack')) {
  50. secureServices = $.extend(true, [], require('data/HDP2/secure_configs'));
  51. } else {
  52. secureServices = $.extend(true, [], require('data/secure_configs'));
  53. }
  54. var installedServices = App.Service.find().mapProperty('serviceName');
  55. //General (only non service tab) tab is always displayed
  56. services.push(secureServices.findProperty('serviceName', 'GENERAL'));
  57. installedServices.forEach(function (_service) {
  58. var secureService = secureServices.findProperty('serviceName', _service);
  59. if (secureService) {
  60. services.push(secureService);
  61. }
  62. }, this);
  63. return services;
  64. }.property(),
  65. /**
  66. * default values of configs, which contains user names
  67. */
  68. defaultUserNameMap: {
  69. 'hdfs_user': 'hdfs',
  70. 'yarn_user': 'yarn',
  71. 'mapred_user': 'mapred',
  72. 'hbase_user': 'hbase',
  73. 'hive_user': 'hive',
  74. 'proxyuser_group': 'users',
  75. 'smokeuser': 'ambari-qa',
  76. 'zk_user': 'zookeeper',
  77. 'oozie_user': 'oozie',
  78. 'nagios_user': 'nagios',
  79. 'user_group': 'hadoop',
  80. 'storm_user': 'storm',
  81. 'falcon_user': 'falcon'
  82. },
  83. loadStep: function () {
  84. var step2Controller = App.router.get('mainAdminSecurityAddStep2Controller');
  85. var services = this.get('services');
  86. this.get('stepConfigs').clear();
  87. this.get('securityUsers').clear();
  88. this.get('serviceConfigTags').clear();
  89. this.loadSecurityUsers();
  90. //loadSecurityUsers - desired configs fetched from server
  91. step2Controller.addUserPrincipals(services, this.get('securityUsers'));
  92. step2Controller.addMasterHostToGlobals(services);
  93. step2Controller.addSlaveHostToGlobals(services);
  94. this.renderServiceConfigs(services);
  95. step2Controller.changeCategoryOnHa(services, this.get('stepConfigs'));
  96. services.forEach(function (_secureService) {
  97. this.setServiceTagNames(_secureService, this.get('desiredConfigs'));
  98. }, this);
  99. var serverConfigs = App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags'));
  100. this.setConfigValuesFromServer(this.get('stepConfigs'), serverConfigs);
  101. this.set('installedServices', App.Service.find().mapProperty('serviceName'));
  102. },
  103. /**
  104. * get actual values of configurations from server
  105. * @param stepConfigs
  106. * @param serverConfigs
  107. */
  108. setConfigValuesFromServer: function (stepConfigs, serverConfigs) {
  109. var allConfigs = {};
  110. serverConfigs.mapProperty('properties').forEach(function (_properties) {
  111. allConfigs = $.extend(allConfigs, _properties);
  112. }, this);
  113. // for all services`
  114. stepConfigs.forEach(function (_content) {
  115. //for all components
  116. _content.get('configs').forEach(function (_config) {
  117. var componentVal = allConfigs[_config.get('name')];
  118. //if we have config for specified component
  119. if (componentVal) {
  120. //set it
  121. _config.set('value', componentVal);
  122. }
  123. }, this);
  124. }, this);
  125. },
  126. /**
  127. * set tag names according to installed services and desired configs
  128. * @param secureService
  129. * @param configs
  130. * @return {Object}
  131. */
  132. setServiceTagNames: function (secureService, configs) {
  133. //var serviceConfigTags = this.get('serviceConfigTags');
  134. for (var index in configs) {
  135. if (secureService.sites && secureService.sites.contains(index)) {
  136. var serviceConfigObj = {
  137. siteName: index,
  138. tagName: configs[index].tag,
  139. newTagName: null,
  140. configs: {}
  141. };
  142. this.get('serviceConfigTags').pushObject(serviceConfigObj);
  143. }
  144. }
  145. return serviceConfigObj;
  146. },
  147. loadSecurityUsers: function () {
  148. var securityUsers = this.get('serviceUsers');
  149. if (!securityUsers || securityUsers.length < 1) { // Page could be refreshed in middle
  150. if (App.testMode) {
  151. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  152. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  153. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  154. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  155. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  156. } else {
  157. this.setSecurityStatus();
  158. securityUsers = this.get('serviceUsers');
  159. }
  160. }
  161. this.set('securityUsers', securityUsers);
  162. },
  163. /**
  164. * Load child components to service config object
  165. * @param _componentConfig
  166. * @param componentConfig
  167. */
  168. loadComponentConfigs: function (_componentConfig, componentConfig) {
  169. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  170. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  171. componentConfig.configs.pushObject(serviceConfigProperty);
  172. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  173. serviceConfigProperty.validate();
  174. }, this);
  175. },
  176. /**
  177. * Render configs for active services
  178. * @param serviceConfigs
  179. */
  180. renderServiceConfigs: function (serviceConfigs) {
  181. serviceConfigs.forEach(function (_serviceConfig) {
  182. var serviceConfig = App.ServiceConfig.create({
  183. filename: _serviceConfig.filename,
  184. serviceName: _serviceConfig.serviceName,
  185. displayName: _serviceConfig.displayName,
  186. configCategories: _serviceConfig.configCategories,
  187. showConfig: true,
  188. configs: []
  189. });
  190. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  191. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  192. this.get('stepConfigs').pushObject(serviceConfig);
  193. }, this);
  194. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  195. },
  196. notifySecurityOffPopup: function () {
  197. var self = this;
  198. if (!this.get('isSubmitDisabled')) {
  199. App.ModalPopup.show({
  200. header: Em.I18n.t('popup.confirmation.commonHeader'),
  201. primary: Em.I18n.t('ok'),
  202. onPrimary: function () {
  203. App.db.setSecurityDeployCommands(undefined);
  204. self.setDisableSecurityStatus("RUNNING");
  205. App.router.transitionTo('disableSecurity');
  206. this.hide();
  207. },
  208. bodyClass: Ember.View.extend({
  209. isMapReduceInstalled: App.Service.find().mapProperty('serviceName').contains('MAPREDUCE'),
  210. templateName: require('templates/main/admin/security/notify_security_off_popup')
  211. })
  212. })
  213. }
  214. },
  215. getUpdatedSecurityStatus: function () {
  216. this.setSecurityStatus();
  217. return this.get('securityEnabled');
  218. },
  219. setSecurityStatus: function () {
  220. if (App.testMode) {
  221. this.set('securityEnabled', !App.testEnableSecurity);
  222. this.set('dataIsLoaded', true);
  223. } else {
  224. //get Security Status From Server
  225. App.ajax.send({
  226. name: 'admin.security_status',
  227. sender: this,
  228. success: 'getSecurityStatusFromServerSuccessCallback',
  229. error: 'errorCallback'
  230. });
  231. }
  232. },
  233. errorCallback: function () {
  234. this.set('dataIsLoaded', true);
  235. this.showSecurityErrorPopup();
  236. },
  237. getSecurityStatusFromServerSuccessCallback: function (data) {
  238. var configs = data.Clusters.desired_configs;
  239. this.set('desiredConfigs', configs);
  240. if ('global' in configs && 'hdfs-site' in configs) {
  241. this.set('tag.global', configs['global'].tag);
  242. this.set('tag.hdfs-site', configs['hdfs-site'].tag);
  243. this.getServiceConfigsFromServer();
  244. }
  245. else {
  246. this.showSecurityErrorPopup();
  247. }
  248. },
  249. getServiceConfigsFromServer: function () {
  250. var tags = [
  251. {
  252. siteName: "global",
  253. tagName: this.get('tag.global')
  254. },
  255. {
  256. siteName: "hdfs-site",
  257. tagName: this.get('tag.hdfs-site')
  258. }
  259. ];
  260. var data = App.router.get('configurationController').getConfigsByTags(tags);
  261. var configs = data.findProperty('tag', this.get('tag.global')).properties;
  262. if (configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true)) {
  263. this.set('securityEnabled', true);
  264. }
  265. else {
  266. this.set('securityEnabled', false);
  267. var hdfsConfigs = data.findProperty('tag', this.get('tag.hdfs-site')).properties;
  268. this.setNnHaStatus(hdfsConfigs);
  269. }
  270. this.loadUsers(configs);
  271. this.set('dataIsLoaded', true);
  272. },
  273. setNnHaStatus: function (hdfsConfigs) {
  274. var nnHaStatus = hdfsConfigs && hdfsConfigs['dfs.nameservices'];
  275. var namenodesKey;
  276. if (nnHaStatus) {
  277. namenodesKey = 'dfs.ha.namenodes.' + hdfsConfigs['dfs.nameservices'];
  278. }
  279. if (nnHaStatus && hdfsConfigs[namenodesKey]) {
  280. App.db.setIsNameNodeHa('true');
  281. } else {
  282. App.db.setIsNameNodeHa('false');
  283. }
  284. },
  285. /**
  286. * load users names,
  287. * substitute missing values with default
  288. * @param configs {Object}
  289. */
  290. loadUsers: function (configs) {
  291. var defaultUserNameMap = this.get('defaultUserNameMap');
  292. var serviceUsers = this.get('serviceUsers');
  293. for (var configName in defaultUserNameMap) {
  294. serviceUsers.push({
  295. id: 'puppet var',
  296. name: configName,
  297. value: configs[configName] || defaultUserNameMap[configName]
  298. });
  299. }
  300. App.db.setSecureUserInfo(this.get('serviceUsers'));
  301. },
  302. showSecurityErrorPopup: function () {
  303. App.ModalPopup.show({
  304. header: Em.I18n.t('common.error'),
  305. secondary: false,
  306. bodyClass: Ember.View.extend({
  307. template: Ember.Handlebars.compile('<p>{{t admin.security.status.error}}</p>')
  308. })
  309. });
  310. }
  311. });