security.js 11 KB

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