Skip to content

Commit 42e45a6

Browse files
author
Matthew Fisher
committed
fix(controller): allow only admins cluster access
Before, anyone was able to add clusters into Deis, which is a management nightmare. Administrators of Deis should be the only ones capable of adding new clusters to Deis. fixes #696
1 parent 17d36e1 commit 42e45a6

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

controller/api/fixtures/tests.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,23 @@
1616
"email": "autotest@opdemand.com",
1717
"date_joined": "2013-05-10T16:08:09.357Z"
1818
}
19+
},
20+
{
21+
"pk": 8,
22+
"model": "auth.user",
23+
"fields": {
24+
"username": "autotest2",
25+
"first_name": "Otto",
26+
"last_name": "Test",
27+
"is_active": true,
28+
"is_superuser": false,
29+
"is_staff": false,
30+
"last_login": "2013-05-10T16:08:09.357Z",
31+
"groups": [],
32+
"user_permissions": [],
33+
"password": "pbkdf2_sha256$10000$5Uoq7dl61vnN$gQhDpc2q2Rkn16VdPC+pNNEQcKpy+LGe29Zkad+2/m4=",
34+
"email": "autotest2@opdemand.com",
35+
"date_joined": "2013-05-10T16:08:09.357Z"
36+
}
1937
}
2038
]

controller/api/tests/test_cluster.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def setUp(self):
2525

2626
def test_cluster(self):
2727
"""
28-
Test that a user can create, read, update and delete a cluster
28+
Test that an administrator can create, read, update and delete a cluster
2929
"""
3030
url = '/api/clusters'
3131
options = {'key': 'val'}
@@ -56,3 +56,15 @@ def test_cluster(self):
5656
self.assertEqual(json.loads(response.data['options']), new_options)
5757
response = self.client.delete(url)
5858
self.assertEqual(response.status_code, 204)
59+
60+
def test_cluster_perms_denied(self):
61+
"""
62+
Test that a user cannot make changes to a cluster
63+
"""
64+
url = '/api/clusters'
65+
options = {'key': 'val'}
66+
self.client.login(username='autotest2', password='password')
67+
body = {'id': 'autotest2', 'domain': 'autotest.local', 'type': 'mock',
68+
'hosts': 'host1,host2', 'auth': 'base64string', 'options': options}
69+
response = self.client.post(url, json.dumps(body), content_type='application/json')
70+
self.assertEqual(response.status_code, 403)

controller/api/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class ClusterViewSet(viewsets.ModelViewSet):
188188

189189
model = models.Cluster
190190
serializer_class = serializers.ClusterSerializer
191-
permission_classes = (permissions.IsAuthenticated, IsAdminOrSafeMethod)
191+
permission_classes = (permissions.IsAuthenticated, IsAdmin)
192192
lookup_field = 'id'
193193

194194
def pre_save(self, obj):

0 commit comments

Comments
 (0)