security.js 13 KB

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