security.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. step2Controller.set('content', Em.Object.create({services: []}));
  87. step2Controller.set('content.services', services);
  88. this.get('stepConfigs').clear();
  89. this.get('securityUsers').clear();
  90. this.get('serviceConfigTags').clear();
  91. this.loadSecurityUsers();
  92. //loadSecurityUsers - desired configs fetched from server
  93. step2Controller.addUserPrincipals(services, this.get('securityUsers'));
  94. step2Controller.addMasterHostToGlobals();
  95. step2Controller.addSlaveHostToGlobals();
  96. this.renderServiceConfigs(services);
  97. step2Controller.changeCategoryOnHa(services, this.get('stepConfigs'));
  98. services.forEach(function (_secureService) {
  99. this.setServiceTagNames(_secureService, this.get('desiredConfigs'));
  100. }, this);
  101. var serverConfigs = App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags'));
  102. this.setConfigValuesFromServer(this.get('stepConfigs'), serverConfigs);
  103. this.set('installedServices', App.Service.find().mapProperty('serviceName'));
  104. },
  105. /**
  106. * get actual values of configurations from server
  107. * @param stepConfigs
  108. * @param serverConfigs
  109. */
  110. setConfigValuesFromServer: function (stepConfigs, serverConfigs) {
  111. var allConfigs = {};
  112. serverConfigs.mapProperty('properties').forEach(function (_properties) {
  113. allConfigs = $.extend(allConfigs, _properties);
  114. }, this);
  115. // for all services`
  116. stepConfigs.forEach(function (_content) {
  117. //for all components
  118. _content.get('configs').forEach(function (_config) {
  119. var componentVal = allConfigs[_config.get('name')];
  120. //if we have config for specified component
  121. if (componentVal) {
  122. //set it
  123. _config.set('value', componentVal);
  124. }
  125. }, this);
  126. }, this);
  127. },
  128. /**
  129. * set tag names according to installed services and desired configs
  130. * @param secureService
  131. * @param configs
  132. * @return {Object}
  133. */
  134. setServiceTagNames: function (secureService, configs) {
  135. //var serviceConfigTags = this.get('serviceConfigTags');
  136. for (var index in configs) {
  137. if (secureService.sites && secureService.sites.contains(index)) {
  138. var serviceConfigObj = {
  139. siteName: index,
  140. tagName: configs[index].tag,
  141. newTagName: null,
  142. configs: {}
  143. };
  144. this.get('serviceConfigTags').pushObject(serviceConfigObj);
  145. }
  146. }
  147. return serviceConfigObj;
  148. },
  149. loadSecurityUsers: function () {
  150. var securityUsers = this.get('serviceUsers');
  151. if (!securityUsers || securityUsers.length < 1) { // Page could be refreshed in middle
  152. if (App.testMode) {
  153. securityUsers.pushObject({id: 'puppet var', name: 'hdfs_user', value: 'hdfs'});
  154. securityUsers.pushObject({id: 'puppet var', name: 'mapred_user', value: 'mapred'});
  155. securityUsers.pushObject({id: 'puppet var', name: 'hbase_user', value: 'hbase'});
  156. securityUsers.pushObject({id: 'puppet var', name: 'hive_user', value: 'hive'});
  157. securityUsers.pushObject({id: 'puppet var', name: 'smokeuser', value: 'ambari-qa'});
  158. } else {
  159. this.setSecurityStatus();
  160. securityUsers = this.get('serviceUsers');
  161. }
  162. }
  163. this.set('securityUsers', securityUsers);
  164. },
  165. /**
  166. * Load child components to service config object
  167. * @param _componentConfig
  168. * @param componentConfig
  169. */
  170. loadComponentConfigs: function (_componentConfig, componentConfig) {
  171. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  172. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  173. componentConfig.configs.pushObject(serviceConfigProperty);
  174. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  175. serviceConfigProperty.validate();
  176. }, this);
  177. },
  178. /**
  179. * Render configs for active services
  180. * @param serviceConfigs
  181. */
  182. renderServiceConfigs: function (serviceConfigs) {
  183. serviceConfigs.forEach(function (_serviceConfig) {
  184. var serviceConfig = App.ServiceConfig.create({
  185. filename: _serviceConfig.filename,
  186. serviceName: _serviceConfig.serviceName,
  187. displayName: _serviceConfig.displayName,
  188. configCategories: _serviceConfig.configCategories,
  189. showConfig: true,
  190. configs: []
  191. });
  192. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  193. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  194. this.get('stepConfigs').pushObject(serviceConfig);
  195. }, this);
  196. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  197. },
  198. notifySecurityOffPopup: function () {
  199. var self = this;
  200. if (!this.get('isSubmitDisabled')) {
  201. App.ModalPopup.show({
  202. header: Em.I18n.t('popup.confirmation.commonHeader'),
  203. primary: Em.I18n.t('ok'),
  204. onPrimary: function () {
  205. App.db.setSecurityDeployCommands(undefined);
  206. self.setDisableSecurityStatus("RUNNING");
  207. App.router.transitionTo('disableSecurity');
  208. this.hide();
  209. },
  210. bodyClass: Ember.View.extend({
  211. isMapReduceInstalled: App.Service.find().mapProperty('serviceName').contains('MAPREDUCE'),
  212. templateName: require('templates/main/admin/security/notify_security_off_popup')
  213. })
  214. })
  215. }
  216. },
  217. getUpdatedSecurityStatus: function () {
  218. this.setSecurityStatus();
  219. return this.get('securityEnabled');
  220. },
  221. setSecurityStatus: function () {
  222. if (App.testMode) {
  223. this.set('securityEnabled', !App.testEnableSecurity);
  224. this.set('dataIsLoaded', true);
  225. } else {
  226. //get Security Status From Server
  227. App.ajax.send({
  228. name: 'admin.security_status',
  229. sender: this,
  230. success: 'getSecurityStatusFromServerSuccessCallback',
  231. error: 'errorCallback'
  232. });
  233. }
  234. },
  235. errorCallback: function (jqXHR) {
  236. this.set('dataIsLoaded', true);
  237. // Show the error popup if the API call received a response from the server.
  238. // jqXHR.status will be empty when browser cancels the request. Refer to AMBARI-5921 for more info
  239. if (!!jqXHR.status) {
  240. this.showSecurityErrorPopup();
  241. }
  242. },
  243. getSecurityStatusFromServerSuccessCallback: function (data) {
  244. var configs = data.Clusters.desired_configs;
  245. this.set('desiredConfigs', configs);
  246. if ('global' in configs && 'hdfs-site' in configs) {
  247. this.set('tag.global', configs['global'].tag);
  248. this.set('tag.hdfs-site', configs['hdfs-site'].tag);
  249. this.getServiceConfigsFromServer();
  250. }
  251. else {
  252. this.showSecurityErrorPopup();
  253. }
  254. },
  255. getServiceConfigsFromServer: function () {
  256. var tags = [
  257. {
  258. siteName: "global",
  259. tagName: this.get('tag.global')
  260. },
  261. {
  262. siteName: "hdfs-site",
  263. tagName: this.get('tag.hdfs-site')
  264. }
  265. ];
  266. var data = App.router.get('configurationController').getConfigsByTags(tags);
  267. var configs = data.findProperty('tag', this.get('tag.global')).properties;
  268. if (configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true)) {
  269. this.set('securityEnabled', true);
  270. }
  271. else {
  272. this.set('securityEnabled', false);
  273. var hdfsConfigs = data.findProperty('tag', this.get('tag.hdfs-site')).properties;
  274. this.setNnHaStatus(hdfsConfigs);
  275. }
  276. this.loadUsers(configs);
  277. this.set('dataIsLoaded', true);
  278. },
  279. setNnHaStatus: function (hdfsConfigs) {
  280. var nnHaStatus = hdfsConfigs && hdfsConfigs['dfs.nameservices'];
  281. var namenodesKey;
  282. if (nnHaStatus) {
  283. namenodesKey = 'dfs.ha.namenodes.' + hdfsConfigs['dfs.nameservices'];
  284. }
  285. if (nnHaStatus && hdfsConfigs[namenodesKey]) {
  286. App.db.setIsNameNodeHa('true');
  287. } else {
  288. App.db.setIsNameNodeHa('false');
  289. }
  290. },
  291. /**
  292. * load users names,
  293. * substitute missing values with default
  294. * @param configs {Object}
  295. */
  296. loadUsers: function (configs) {
  297. var defaultUserNameMap = this.get('defaultUserNameMap');
  298. var serviceUsers = this.get('serviceUsers');
  299. for (var configName in defaultUserNameMap) {
  300. serviceUsers.push({
  301. id: 'puppet var',
  302. name: configName,
  303. value: configs[configName] || defaultUserNameMap[configName]
  304. });
  305. }
  306. App.db.setSecureUserInfo(this.get('serviceUsers'));
  307. },
  308. showSecurityErrorPopup: function () {
  309. App.ModalPopup.show({
  310. header: Em.I18n.t('common.error'),
  311. secondary: false,
  312. bodyClass: Ember.View.extend({
  313. template: Ember.Handlebars.compile('<p>{{t admin.security.status.error}}</p>')
  314. })
  315. });
  316. }
  317. });