forked from thepaul/cassandra-dtest
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathauth_test.py
524 lines (398 loc) · 24.6 KB
/
auth_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
import time
from cql import ProgrammingError
from cql.cassandra.ttypes import AuthenticationException
from dtest import Tester, debug
from tools import *
class TestAuth(Tester):
def __init__(self, *args, **kwargs):
self.ignore_log_patterns = [
# This one occurs if we do a non-rolling upgrade, the node
# it's trying to send the migration to hasn't started yet,
# and when it does, it gets replayed and everything is fine.
r'Can\'t send migration request: node.*is down',
]
Tester.__init__(self, *args, **kwargs)
@require('https://issues.apache.org/jira/browse/CASSANDRA-7011')
def system_auth_ks_is_alterable_test(self):
self.prepare(nodes=3)
debug("nodes started")
schema_query = """SELECT strategy_options
FROM system.schema_keyspaces
WHERE keyspace_name = 'system_auth'"""
cursor = self.get_cursor(0, user='cassandra', password='cassandra')
cursor.execute(schema_query)
row = cursor.fetchone()
self.assertEqual('{"replication_factor":"1"}', row[0])
cursor.execute("""
ALTER KEYSPACE system_auth
WITH replication = {'class':'SimpleStrategy', 'replication_factor':3};
""")
# make sure schema change is persistent
debug("Stopping cluster..")
self.cluster.stop()
debug("Restarting cluster..")
self.cluster.start()
time.sleep(15)
for i in range(3):
debug('Checking node: {i}'.format(i=i))
cursor = self.get_cursor(i, user='cassandra', password='cassandra')
cursor.execute(schema_query)
row = cursor.fetchone()
self.assertEqual('{"replication_factor":"3"}', row[0])
def login_test(self):
# also tests default user creation (cassandra/cassandra)
self.prepare()
self.get_cursor(user='cassandra', password='cassandra')
with self.assertRaises(AuthenticationException):
self.get_cursor(user='cassandra', password='badpassword')
with self.assertRaises(AuthenticationException):
self.get_cursor(user='doesntexist', password='doesntmatter')
def only_superuser_can_create_users_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER jackob WITH PASSWORD '12345' NOSUPERUSER")
jackob = self.get_cursor(user='jackob', password='12345')
with self.assertRaises(ProgrammingError) as cm:
jackob.execute("CREATE USER james WITH PASSWORD '54321' NOSUPERUSER")
self.assertEqual('Bad Request: Only superusers are allowed to perform CREATE USER queries',
cm.exception.message)
def password_authenticator_create_user_requires_password_test(self):
self.prepare()
cursor = self.get_cursor(user='cassandra', password='cassandra')
with self.assertRaises(ProgrammingError) as cm:
cursor.execute("CREATE USER jackob NOSUPERUSER")
self.assertEqual('Bad Request: PasswordAuthenticator requires PASSWORD option',
cm.exception.message)
def cant_create_existing_user_test(self):
self.prepare()
cursor = self.get_cursor(user='cassandra', password='cassandra')
cursor.execute("CREATE USER '[email protected]' WITH PASSWORD '12345' NOSUPERUSER")
with self.assertRaises(ProgrammingError) as cm:
cursor.execute("CREATE USER '[email protected]' WITH PASSWORD '12345' NOSUPERUSER")
self.assertEqual('Bad Request: User [email protected] already exists',
cm.exception.message)
def list_users_test(self):
self.prepare()
cursor = self.get_cursor(user='cassandra', password='cassandra')
cursor.execute("CREATE USER alex WITH PASSWORD '12345' NOSUPERUSER")
cursor.execute("CREATE USER bob WITH PASSWORD '12345' SUPERUSER")
cursor.execute("CREATE USER cathy WITH PASSWORD '12345' NOSUPERUSER")
cursor.execute("CREATE USER dave WITH PASSWORD '12345' SUPERUSER")
cursor.execute("LIST USERS")
rows = cursor.fetchall()
self.assertEqual(5, len(rows))
# {username: isSuperuser} dict.
users = dict([(r[0], r[1]) for r in rows])
self.assertTrue(users['cassandra'])
self.assertFalse(users['alex'])
self.assertTrue(users['bob'])
self.assertFalse(users['cathy'])
self.assertTrue(users['dave'])
def user_cant_drop_themselves_test(self):
self.prepare()
cursor = self.get_cursor(user='cassandra', password='cassandra')
self.assertUnauthorized("Users aren't allowed to DROP themselves",
cursor, "DROP USER cassandra")
def only_superusers_can_drop_users_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345' NOSUPERUSER")
cassandra.execute("CREATE USER dave WITH PASSWORD '12345' NOSUPERUSER")
cassandra.execute("LIST USERS")
self.assertEqual(3, cassandra.rowcount)
cathy = self.get_cursor(user='cathy', password='12345')
self.assertUnauthorized('Only superusers are allowed to perform DROP USER queries',
cathy, 'DROP USER dave')
cassandra.execute("LIST USERS")
self.assertEqual(3, cassandra.rowcount)
cassandra.execute('DROP USER dave')
cassandra.execute("LIST USERS")
self.assertEqual(2, cassandra.rowcount)
def dropping_nonexistent_user_throws_exception_test(self):
self.prepare()
cursor = self.get_cursor(user='cassandra', password='cassandra')
self.assertUnauthorized("User nonexistent doesn't exist",
cursor, 'DROP USER nonexistent')
def regular_users_can_alter_their_passwords_only_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cassandra.execute("CREATE USER bob WITH PASSWORD '12345'")
cathy = self.get_cursor(user='cathy', password='12345')
cathy.execute("ALTER USER cathy WITH PASSWORD '54321'")
cathy = self.get_cursor(user='cathy', password='54321')
self.assertUnauthorized("You aren't allowed to alter this user",
cathy, "ALTER USER bob WITH PASSWORD 'cantchangeit'")
def users_cant_alter_their_superuser_status_test(self):
self.prepare()
cursor = self.get_cursor(user='cassandra', password='cassandra')
self.assertUnauthorized("You aren't allowed to alter your own superuser status",
cursor, "ALTER USER cassandra NOSUPERUSER")
def only_superuser_alters_superuser_status_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cathy = self.get_cursor(user='cathy', password='12345')
self.assertUnauthorized("Only superusers are allowed to alter superuser status",
cathy, "ALTER USER cassandra NOSUPERUSER")
cassandra.execute("ALTER USER cathy SUPERUSER")
def altering_nonexistent_user_throws_exception_test(self):
self.prepare()
cursor = self.get_cursor(user='cassandra', password='cassandra')
self.assertUnauthorized("User nonexistent doesn't exist",
cursor, "ALTER USER nonexistent WITH PASSWORD 'doesn''tmatter'")
def create_ks_auth_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cathy = self.get_cursor(user='cathy', password='12345')
self.assertUnauthorized("User cathy has no CREATE permission on <all keyspaces> or any of its parents",
cathy,
"CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
cassandra.execute("GRANT CREATE ON ALL KEYSPACES TO cathy")
cathy.execute("""CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}""")
def create_cf_auth_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cassandra.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
cathy = self.get_cursor(user='cathy', password='12345')
self.assertUnauthorized("User cathy has no CREATE permission on <keyspace ks> or any of its parents",
cathy, "CREATE TABLE ks.cf (id int primary key)")
cassandra.execute("GRANT CREATE ON KEYSPACE ks TO cathy")
cathy.execute("CREATE TABLE ks.cf (id int primary key)")
def alter_ks_auth_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cassandra.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
cathy = self.get_cursor(user='cathy', password='12345')
self.assertUnauthorized("User cathy has no ALTER permission on <keyspace ks> or any of its parents",
cathy,
"ALTER KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':2}")
cassandra.execute("GRANT ALTER ON KEYSPACE ks TO cathy")
cathy.execute("ALTER KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':2}")
def alter_cf_auth_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cassandra.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
cassandra.execute("CREATE TABLE ks.cf (id int primary key)")
cathy = self.get_cursor(user='cathy', password='12345')
self.assertUnauthorized("User cathy has no ALTER permission on <table ks.cf> or any of its parents",
cathy, "ALTER TABLE ks.cf ADD val int")
cassandra.execute("GRANT ALTER ON ks.cf TO cathy")
cathy.execute("ALTER TABLE ks.cf ADD val int")
cassandra.execute("REVOKE ALTER ON ks.cf FROM cathy")
self.assertUnauthorized("User cathy has no ALTER permission on <table ks.cf> or any of its parents",
cathy, "CREATE INDEX ON ks.cf(val)")
cassandra.execute("GRANT ALTER ON ks.cf TO cathy")
cathy.execute("CREATE INDEX ON ks.cf(val)")
cassandra.execute("REVOKE ALTER ON ks.cf FROM cathy")
cathy.execute("USE ks")
self.assertUnauthorized("User cathy has no ALTER permission on <table ks.cf> or any of its parents",
cathy, "DROP INDEX cf_val_idx")
cassandra.execute("GRANT ALTER ON ks.cf TO cathy")
cathy.execute("DROP INDEX cf_val_idx")
def drop_ks_auth_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cassandra.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
cathy = self.get_cursor(user='cathy', password='12345')
self.assertUnauthorized("User cathy has no DROP permission on <keyspace ks> or any of its parents",
cathy, "DROP KEYSPACE ks")
cassandra.execute("GRANT DROP ON KEYSPACE ks TO cathy")
cathy.execute("DROP KEYSPACE ks")
def drop_cf_auth_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cassandra.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
cassandra.execute("CREATE TABLE ks.cf (id int primary key)")
cathy = self.get_cursor(user='cathy', password='12345')
self.assertUnauthorized("User cathy has no DROP permission on <table ks.cf> or any of its parents",
cathy, "DROP TABLE ks.cf")
cassandra.execute("GRANT DROP ON ks.cf TO cathy")
cathy.execute("DROP TABLE ks.cf")
def modify_and_select_auth_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cassandra.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
cassandra.execute("CREATE TABLE ks.cf (id int primary key, val int)")
cathy = self.get_cursor(user='cathy', password='12345')
self.assertUnauthorized("User cathy has no SELECT permission on <table ks.cf> or any of its parents",
cathy, "SELECT * FROM ks.cf")
cassandra.execute("GRANT SELECT ON ks.cf TO cathy")
cathy.execute("SELECT * FROM ks.cf")
self.assertEquals(0, cathy.rowcount)
self.assertUnauthorized("User cathy has no MODIFY permission on <table ks.cf> or any of its parents",
cathy, "INSERT INTO ks.cf (id, val) VALUES (0, 0)")
self.assertUnauthorized("User cathy has no MODIFY permission on <table ks.cf> or any of its parents",
cathy, "UPDATE ks.cf SET val = 1 WHERE id = 1")
self.assertUnauthorized("User cathy has no MODIFY permission on <table ks.cf> or any of its parents",
cathy, "DELETE FROM ks.cf WHERE id = 1")
self.assertUnauthorized("User cathy has no MODIFY permission on <table ks.cf> or any of its parents",
cathy, "TRUNCATE ks.cf")
cassandra.execute("GRANT MODIFY ON ks.cf TO cathy")
cathy.execute("INSERT INTO ks.cf (id, val) VALUES (0, 0)")
cathy.execute("UPDATE ks.cf SET val = 1 WHERE id = 1")
cathy.execute("SELECT * FROM ks.cf")
self.assertEquals(2, cathy.rowcount)
cathy.execute("DELETE FROM ks.cf WHERE id = 1")
cathy.execute("SELECT * FROM ks.cf")
self.assertEquals(1, cathy.rowcount)
cathy.execute("TRUNCATE ks.cf")
self.assertEquals(0, cathy.rowcount)
def grant_revoke_auth_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cassandra.execute("CREATE USER bob WITH PASSWORD '12345'")
cathy = self.get_cursor(user='cathy', password='12345')
# missing both SELECT and AUTHORIZE
self.assertUnauthorized("User cathy has no AUTHORIZE permission on <all keyspaces> or any of its parents",
cathy, "GRANT SELECT ON ALL KEYSPACES TO bob")
cassandra.execute("GRANT AUTHORIZE ON ALL KEYSPACES TO cathy")
# still missing SELECT
self.assertUnauthorized("User cathy has no SELECT permission on <all keyspaces> or any of its parents",
cathy, "GRANT SELECT ON ALL KEYSPACES TO bob")
cassandra.execute("GRANT SELECT ON ALL KEYSPACES TO cathy")
# should succeed now with both SELECT and AUTHORIZE
cathy.execute("GRANT SELECT ON ALL KEYSPACES TO bob")
def grant_revoke_validation_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cassandra.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
self.assertUnauthorized("<keyspace nonexistent> doesn't exist",
cassandra, "GRANT ALL ON KEYSPACE nonexistent TO cathy")
self.assertUnauthorized("User nonexistent doesn't exist",
cassandra, "GRANT ALL ON KEYSPACE ks TO nonexistent")
self.assertUnauthorized("<keyspace nonexistent> doesn't exist",
cassandra, "REVOKE ALL ON KEYSPACE nonexistent FROM cathy")
self.assertUnauthorized("User nonexistent doesn't exist",
cassandra, "REVOKE ALL ON KEYSPACE ks FROM nonexistent")
def grant_revoke_cleanup_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cassandra.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
cassandra.execute("CREATE TABLE ks.cf (id int primary key, val int)")
cassandra.execute("GRANT ALL ON ks.cf TO cathy")
cathy = self.get_cursor(user='cathy', password='12345')
cathy.execute("INSERT INTO ks.cf (id, val) VALUES (0, 0)")
cathy.execute("SELECT * FROM ks.cf")
self.assertEquals(1, cathy.rowcount)
# drop and recreate the user, make sure permissions are gone
cassandra.execute("DROP USER cathy")
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
self.assertUnauthorized("User cathy has no MODIFY permission on <table ks.cf> or any of its parents",
cathy, "INSERT INTO ks.cf (id, val) VALUES (0, 0)")
self.assertUnauthorized("User cathy has no SELECT permission on <table ks.cf> or any of its parents",
cathy, "SELECT * FROM ks.cf")
# grant all the permissions back
cassandra.execute("GRANT ALL ON ks.cf TO cathy")
cathy.execute("INSERT INTO ks.cf (id, val) VALUES (0, 0)")
cathy.execute("SELECT * FROM ks.cf")
self.assertEqual(1, cathy.rowcount)
# drop and recreate the keyspace, make sure permissions are gone
cassandra.execute("DROP KEYSPACE ks")
cassandra.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
cassandra.execute("CREATE TABLE ks.cf (id int primary key, val int)")
self.assertUnauthorized("User cathy has no MODIFY permission on <table ks.cf> or any of its parents",
cathy, "INSERT INTO ks.cf (id, val) VALUES (0, 0)")
self.assertUnauthorized("User cathy has no SELECT permission on <table ks.cf> or any of its parents",
cathy, "SELECT * FROM ks.cf")
def permissions_caching_test(self):
self.prepare(permissions_expiry=2000)
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cassandra.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
cassandra.execute("CREATE TABLE ks.cf (id int primary key, val int)")
cathy = self.get_cursor(user='cathy', password='12345')
# another user to make sure the cache is at user level
cathy2 = self.get_cursor(user='cathy', password='12345')
cathys = [cathy, cathy2]
self.assertUnauthorized("User cathy has no SELECT permission on <table ks.cf> or any of its parents",
cathy, "SELECT * FROM ks.cf")
# grant SELECT to cathy
cassandra.execute("GRANT SELECT ON ks.cf TO cathy")
# should still fail after 1 second.
time.sleep(1.0)
for c in cathys:
self.assertUnauthorized("User cathy has no SELECT permission on <table ks.cf> or any of its parents",
c, "SELECT * FROM ks.cf")
# wait until the cache definitely expires and retry - should succeed now
time.sleep(1.5)
for c in cathys:
c.execute("SELECT * FROM ks.cf")
self.assertEqual(0, c.rowcount)
def list_permissions_test(self):
self.prepare()
cassandra = self.get_cursor(user='cassandra', password='cassandra')
cassandra.execute("CREATE USER cathy WITH PASSWORD '12345'")
cassandra.execute("CREATE USER bob WITH PASSWORD '12345'")
cassandra.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
cassandra.execute("CREATE TABLE ks.cf (id int primary key, val int)")
cassandra.execute("CREATE TABLE ks.cf2 (id int primary key, val int)")
cassandra.execute("GRANT CREATE ON ALL KEYSPACES TO cathy")
cassandra.execute("GRANT ALTER ON KEYSPACE ks TO bob")
cassandra.execute("GRANT MODIFY ON ks.cf TO cathy")
cassandra.execute("GRANT DROP ON ks.cf TO bob")
cassandra.execute("GRANT MODIFY ON ks.cf2 TO bob")
cassandra.execute("GRANT SELECT ON ks.cf2 TO cathy")
self.assertPermissionsListed([('cathy', '<all keyspaces>', 'CREATE'),
('cathy', '<table ks.cf>', 'MODIFY'),
('cathy', '<table ks.cf2>', 'SELECT'),
('bob', '<keyspace ks>', 'ALTER'),
('bob', '<table ks.cf>', 'DROP'),
('bob', '<table ks.cf2>', 'MODIFY')],
cassandra, "LIST ALL PERMISSIONS")
self.assertPermissionsListed([('cathy', '<all keyspaces>', 'CREATE'),
('cathy', '<table ks.cf>', 'MODIFY'),
('cathy', '<table ks.cf2>', 'SELECT')],
cassandra, "LIST ALL PERMISSIONS OF cathy")
self.assertPermissionsListed([('cathy', '<table ks.cf>', 'MODIFY'),
('bob', '<table ks.cf>', 'DROP')],
cassandra, "LIST ALL PERMISSIONS ON ks.cf NORECURSIVE")
self.assertPermissionsListed([('cathy', '<table ks.cf2>', 'SELECT')],
cassandra, "LIST SELECT ON ks.cf2")
self.assertPermissionsListed([('cathy', '<all keyspaces>', 'CREATE'),
('cathy', '<table ks.cf>', 'MODIFY')],
cassandra, "LIST ALL ON ks.cf OF cathy")
bob = self.get_cursor(user='bob', password='12345')
self.assertPermissionsListed([('bob', '<keyspace ks>', 'ALTER'),
('bob', '<table ks.cf>', 'DROP'),
('bob', '<table ks.cf2>', 'MODIFY')],
bob, "LIST ALL PERMISSIONS OF bob")
self.assertUnauthorized("You are not authorized to view everyone's permissions",
bob, "LIST ALL PERMISSIONS")
self.assertUnauthorized("You are not authorized to view cathy's permissions",
bob, "LIST ALL PERMISSIONS OF cathy")
def prepare(self, nodes=1, permissions_expiry=0):
config = {'authenticator' : 'org.apache.cassandra.auth.PasswordAuthenticator',
'authorizer' : 'org.apache.cassandra.auth.CassandraAuthorizer',
'permissions_validity_in_ms' : permissions_expiry}
self.cluster.set_configuration_options(values=config)
self.cluster.populate(nodes).start()
# default user setup is delayed by 10 seconds to reduce log spam
if nodes == 1:
self.cluster.nodelist()[0].watch_log_for('Created default superuser')
else:
# can' just watch for log - the line will appear in just one of the nodes' logs
# only one test uses more than 1 node, though, so some sleep is fine.
time.sleep(15)
def get_cursor(self, node_idx=0, user=None, password=None):
node = self.cluster.nodelist()[node_idx]
conn = self.cql_connection(node, version="3.0.1", user=user, password=password)
return conn.cursor()
def assertPermissionsListed(self, expected, cursor, query):
cursor.execute(query)
perms = [(str(r[0]), str(r[1]), str(r[2])) for r in cursor.fetchall()]
self.assertEqual(sorted(expected), sorted(perms))
def assertUnauthorized(self, message, cursor, query):
with self.assertRaises(ProgrammingError) as cm:
cursor.execute(query)
self.assertEqual("Bad Request: " + message, cm.exception.message)