security.js 13 KB

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