Skip to content

Commit 754e9bc

Browse files
committed
Add canI checks to editors
Check if the user can update or create resources in our editor pages before trying to make the change. We remove the actions that take you to these pages if you don't have authority, but someone could send you a direct link or your authority might have changed since you loaded the previous page.
1 parent 14fe437 commit 754e9bc

14 files changed

+529
-379
lines changed

app/scripts/controllers/addConfigVolume.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ angular.module('openshiftConsole')
1515
$scope,
1616
$window,
1717
APIService,
18+
AuthorizationService,
1819
BreadcrumbsService,
1920
DataService,
2021
Navigate,
@@ -95,6 +96,12 @@ angular.module('openshiftConsole')
9596
.then(_.spread(function(project, context) {
9697
$scope.project = project;
9798

99+
if (!AuthorizationService.canI(resourceGroupVersion, 'update', $routeParams.project)) {
100+
Navigate.toErrorPage('You do not have authority to update ' +
101+
humanizeKind($routeParams.kind) + ' ' + $routeParams.name + '.', 'access_denied');
102+
return;
103+
}
104+
98105
var orderByDisplayName = $filter('orderByDisplayName');
99106
var getErrorDetails = $filter('getErrorDetails');
100107
var generateName = $filter('generateName');
@@ -125,17 +132,18 @@ angular.module('openshiftConsole')
125132
DataService.list("configmaps", context, null, { errorNotification: false }).then(function(configMapData) {
126133
$scope.configMaps = orderByDisplayName(configMapData.by("metadata.name"));
127134
}, function(e) {
128-
if (e.status === 403) {
135+
if (e.code === 403) {
129136
$scope.configMaps = [];
130137
return;
131138
}
132139

133140
displayError('Could not load config maps', getErrorDetails(e));
134141
});
142+
135143
DataService.list("secrets", context, null, { errorNotification: false }).then(function(secretData) {
136144
$scope.secrets = orderByDisplayName(secretData.by("metadata.name"));
137145
}, function(e) {
138-
if (e.status === 403) {
146+
if (e.code === 403) {
139147
$scope.secrets = [];
140148
return;
141149
}

app/scripts/controllers/attachPVC.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@
88
* Controller of the openshiftConsole
99
*/
1010
angular.module('openshiftConsole')
11-
.controller('AttachPVCController', function($filter,
12-
$routeParams,
13-
$scope,
14-
$window,
15-
APIService,
16-
BreadcrumbsService,
17-
DataService,
18-
Navigate,
19-
ProjectsService,
20-
StorageService) {
11+
.controller('AttachPVCController',
12+
function($filter,
13+
$routeParams,
14+
$scope,
15+
$window,
16+
APIService,
17+
AuthorizationService,
18+
BreadcrumbsService,
19+
DataService,
20+
Navigate,
21+
ProjectsService,
22+
StorageService) {
2123
if (!$routeParams.kind || !$routeParams.name) {
2224
Navigate.toErrorPage("Kind or name parameter missing.");
2325
return;
@@ -73,6 +75,12 @@ angular.module('openshiftConsole')
7375
// Update project breadcrumb with display name.
7476
$scope.breadcrumbs[0].title = $filter('displayName')(project);
7577

78+
if (!AuthorizationService.canI(resourceGroupVersion, 'update', $routeParams.project)) {
79+
Navigate.toErrorPage('You do not have authority to update ' +
80+
$filter('humanizeKind')($routeParams.kind) + ' ' + $routeParams.name + '.', 'access_denied');
81+
return;
82+
}
83+
7684
var orderByDisplayName = $filter('orderByDisplayName');
7785
var getErrorDetails = $filter('getErrorDetails');
7886
var generateName = $filter('generateName');

app/scripts/controllers/createConfigMap.js

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ angular.module('openshiftConsole')
1313
$routeParams,
1414
$scope,
1515
$window,
16+
AuthorizationService,
1617
DataService,
1718
Navigate,
1819
ProjectsService) {
@@ -41,6 +42,11 @@ angular.module('openshiftConsole')
4142
// Update project breadcrumb with display name.
4243
$scope.breadcrumbs[0].title = $filter('displayName')(project);
4344

45+
if (!AuthorizationService.canI('configmaps', 'create', $routeParams.project)) {
46+
Navigate.toErrorPage('You do not have authority to create config maps in project ' + $routeParams.project + '.', 'access_denied');
47+
return;
48+
}
49+
4450
$scope.configMap = {
4551
apiVersion: 'v1',
4652
kind: 'ConfigMap',

app/scripts/controllers/createPersistentVolumeClaim.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@
88
* Controller of the openshiftConsole
99
*/
1010
angular.module('openshiftConsole')
11-
.controller('CreatePersistentVolumeClaimController', function ($filter, $routeParams, $scope, $window, ApplicationGenerator, DataService, Navigate, ProjectsService,keyValueEditorUtils) {
11+
.controller('CreatePersistentVolumeClaimController',
12+
function($filter,
13+
$routeParams,
14+
$scope,
15+
$window,
16+
ApplicationGenerator,
17+
AuthorizationService,
18+
DataService,
19+
Navigate,
20+
ProjectsService,
21+
keyValueEditorUtils) {
1222
$scope.alerts = {};
1323
$scope.projectName = $routeParams.project;
1424
$scope.accessModes="ReadWriteOnce";
@@ -35,6 +45,11 @@ angular.module('openshiftConsole')
3545
// Update project breadcrumb with display name.
3646
$scope.breadcrumbs[0].title = $filter('displayName')(project);
3747

48+
if (!AuthorizationService.canI('persistentvolumeclaims', 'create', $routeParams.project)) {
49+
Navigate.toErrorPage('You do not have authority to create persistent volume claims in project ' + $routeParams.project + '.', 'access_denied');
50+
return;
51+
}
52+
3853
$scope.createPersistentVolumeClaim = function() {
3954
if ($scope.createPersistentVolumeClaimForm.$valid) {
4055
$scope.disableInputs = true;

app/scripts/controllers/createRoute.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@
88
* Controller of the openshiftConsole
99
*/
1010
angular.module('openshiftConsole')
11-
.controller('CreateRouteController', function ($filter, $routeParams, $scope, $window, ApplicationGenerator, DataService, Navigate, ProjectsService) {
11+
.controller('CreateRouteController',
12+
function($filter,
13+
$routeParams,
14+
$scope,
15+
$window,
16+
ApplicationGenerator,
17+
AuthorizationService,
18+
DataService,
19+
Navigate,
20+
ProjectsService) {
1221
$scope.alerts = {};
1322
$scope.renderOptions = {
1423
hideFilterWidget: true
@@ -42,6 +51,11 @@ angular.module('openshiftConsole')
4251
// Update project breadcrumb with display name.
4352
$scope.breadcrumbs[0].title = $filter('displayName')(project);
4453

54+
if (!AuthorizationService.canI('routes', 'create', $routeParams.project)) {
55+
Navigate.toErrorPage('You do not have authority to create routes in project ' + $routeParams.project + '.', 'access_denied');
56+
return;
57+
}
58+
4559
var labels = {},
4660
orderByDisplayName = $filter('orderByDisplayName');
4761

app/scripts/controllers/createSecret.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@
88
* Controller of the openshiftConsole
99
*/
1010
angular.module('openshiftConsole')
11-
.controller('CreateSecretController', function ($filter, $location, $routeParams, $scope, $window, AlertMessageService, ApplicationGenerator, DataService, Navigate, ProjectsService) {
11+
.controller('CreateSecretController',
12+
function($filter,
13+
$location,
14+
$routeParams,
15+
$scope,
16+
$window,
17+
AlertMessageService,
18+
ApplicationGenerator,
19+
AuthorizationService,
20+
DataService,
21+
Navigate,
22+
ProjectsService) {
1223
$scope.alerts = {};
1324
$scope.projectName = $routeParams.project;
1425

@@ -42,6 +53,11 @@ angular.module('openshiftConsole')
4253
$scope.context = context;
4354
$scope.breadcrumbs[0].title = $filter('displayName')(project);
4455

56+
if (!AuthorizationService.canI('secrets', 'create', $routeParams.project)) {
57+
Navigate.toErrorPage('You do not have authority to create secrets in project ' + $routeParams.project + '.', 'access_denied');
58+
return;
59+
}
60+
4561
$scope.postCreateAction = function(newSecret, creationAlerts) {
4662
_.each(creationAlerts, function(alert) {
4763
AlertMessageService.addAlert(alert);

app/scripts/controllers/edit/autoscaler.js

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ angular.module('openshiftConsole')
1414
$routeParams,
1515
$window,
1616
APIService,
17+
AuthorizationService,
1718
BreadcrumbsService,
1819
DataService,
1920
HPAService,
@@ -79,6 +80,12 @@ angular.module('openshiftConsole')
7980
// Update project breadcrumb with display name.
8081
$scope.project = project;
8182

83+
var verb = $routeParams.kind === 'HorizontalPodAutoscaler' ? 'update' : 'create';
84+
if (!AuthorizationService.canI({ resource: 'horizontalpodautoscalers', group: 'extensions' }, verb, $routeParams.project)) {
85+
Navigate.toErrorPage('You do not have authority to ' + verb + ' horizontal pod autoscalers in project ' + $routeParams.project + '.', 'access_denied');
86+
return;
87+
}
88+
8289
var createHPA = function() {
8390
$scope.disableInputs = true;
8491
var hpa = {

app/scripts/controllers/edit/buildConfig.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,20 @@
77
* Controller of the openshiftConsole
88
*/
99
angular.module('openshiftConsole')
10-
.controller('EditBuildConfigController', function ($scope, $routeParams, DataService, SecretsService, ProjectsService, $filter, ApplicationGenerator, Navigate, $location, AlertMessageService, SOURCE_URL_PATTERN, keyValueEditorUtils) {
10+
.controller('EditBuildConfigController',
11+
function($scope,
12+
$filter,
13+
$location,
14+
$routeParams,
15+
AlertMessageService,
16+
ApplicationGenerator,
17+
AuthorizationService,
18+
DataService,
19+
Navigate,
20+
ProjectsService,
21+
SOURCE_URL_PATTERN,
22+
SecretsService,
23+
keyValueEditorUtils) {
1124

1225
$scope.projectName = $routeParams.project;
1326
$scope.buildConfig = null;
@@ -120,6 +133,12 @@ angular.module('openshiftConsole')
120133
// Update project breadcrumb with display name.
121134
$scope.breadcrumbs[0].title = $filter('displayName')(project);
122135

136+
if (!AuthorizationService.canI('buildconfigs', 'update', $routeParams.project)) {
137+
Navigate.toErrorPage('You do not have authority to update build config ' +
138+
$routeParams.buildconfig + '.', 'access_denied');
139+
return;
140+
}
141+
123142
DataService.get("buildconfigs", $routeParams.buildconfig, context).then(
124143
// success
125144
function(buildConfig) {

app/scripts/controllers/edit/deploymentConfig.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@
77
* Controller of the openshiftConsole
88
*/
99
angular.module('openshiftConsole')
10-
.controller('EditDeploymentConfigController', function ($scope, $routeParams, $uibModal, DataService, BreadcrumbsService, SecretsService, ProjectsService, $filter, Navigate, $location, AlertMessageService, SOURCE_URL_PATTERN, keyValueEditorUtils) {
10+
.controller('EditDeploymentConfigController',
11+
function($scope,
12+
$filter,
13+
$location,
14+
$routeParams,
15+
$uibModal,
16+
AlertMessageService,
17+
AuthorizationService,
18+
BreadcrumbsService,
19+
DataService,
20+
Navigate,
21+
ProjectsService,
22+
SecretsService,
23+
SOURCE_URL_PATTERN,
24+
keyValueEditorUtils) {
1125
$scope.projectName = $routeParams.project;
1226
$scope.deploymentConfig = null;
1327
$scope.alerts = {};
@@ -55,6 +69,13 @@ angular.module('openshiftConsole')
5569
.then(_.spread(function(project, context) {
5670
$scope.project = project;
5771
$scope.context = context;
72+
73+
if (!AuthorizationService.canI('deploymentconfigs', 'update', $routeParams.project)) {
74+
Navigate.toErrorPage('You do not have authority to update deployment config ' +
75+
$routeParams.deploymentconfig + '.', 'access_denied');
76+
return;
77+
}
78+
5879
DataService.get("deploymentconfigs", $routeParams.deploymentconfig, context).then(
5980
// success
6081
function(deploymentConfig) {

app/scripts/controllers/edit/healthChecks.js

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ angular.module('openshiftConsole')
1414
$routeParams,
1515
$scope,
1616
AlertMessageService,
17+
AuthorizationService,
1718
BreadcrumbsService,
1819
APIService,
1920
DataService,
@@ -72,6 +73,12 @@ angular.module('openshiftConsole')
7273
resource: APIService.kindToResource($routeParams.kind),
7374
group: $routeParams.group
7475
};
76+
77+
if (!AuthorizationService.canI(resourceGroupVersion, 'update', $routeParams.project)) {
78+
Navigate.toErrorPage('You do not have authority to update ' + displayName + '.', 'access_denied');
79+
return;
80+
}
81+
7582
DataService.get(resourceGroupVersion, $scope.name, context).then(
7683
function(result) {
7784
// Modify a copy of the resource.

app/scripts/controllers/edit/route.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
* Controller of the openshiftConsole
99
*/
1010
angular.module('openshiftConsole')
11-
.controller('EditRouteController', function ($filter,
12-
$location,
13-
$routeParams,
14-
$scope,
15-
AlertMessageService,
16-
DataService,
17-
Navigate,
18-
ProjectsService,
19-
RoutesService) {
11+
.controller('EditRouteController',
12+
function($filter,
13+
$location,
14+
$routeParams,
15+
$scope,
16+
AlertMessageService,
17+
AuthorizationService,
18+
DataService,
19+
Navigate,
20+
ProjectsService,
21+
RoutesService) {
2022
$scope.alerts = {};
2123
$scope.renderOptions = {
2224
hideFilterWidget: true
@@ -46,6 +48,11 @@ angular.module('openshiftConsole')
4648
// Update project breadcrumb with display name.
4749
$scope.breadcrumbs[0].title = $filter('displayName')(project);
4850

51+
if (!AuthorizationService.canI('routes', 'update', $routeParams.project)) {
52+
Navigate.toErrorPage('You do not have authority to update route ' + $routeParams.routeName + '.', 'access_denied');
53+
return;
54+
}
55+
4956
var orderByDisplayName = $filter('orderByDisplayName');
5057

5158
var route;

app/scripts/controllers/edit/yaml.js

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ angular.module('openshiftConsole')
1515
$window,
1616
AlertMessageService,
1717
APIService,
18+
AuthorizationService,
1819
BreadcrumbsService,
1920
DataService,
2021
Navigate,
@@ -70,6 +71,12 @@ angular.module('openshiftConsole')
7071
group: $routeParams.group
7172
};
7273

74+
if (!AuthorizationService.canI(resourceGroupVersion, 'update', $routeParams.project)) {
75+
Navigate.toErrorPage('You do not have authority to update ' +
76+
humanizeKind($routeParams.kind) + ' ' + $routeParams.name + '.', 'access_denied');
77+
return;
78+
}
79+
7380
DataService.get(resourceGroupVersion, $scope.name, context).then(
7481
function(result) {
7582
// Modify a copy of the resource.

0 commit comments

Comments
 (0)