security.js 14 KB

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