Skip to content

Commit f1e441e

Browse files
jtgrabowskizhaoyang1991
authored and
Jacek Lewandowski
committed
STAR-564 Check only MODIFY on base when updating table with MV (#17)
If a user has only MODIFY permission on a table and there is a materialized view built on the same table an insert will fail with the following error: Unauthorized: Error from server: code=2100 [Unauthorized] Only base MODIFY permission is required to update base with MV. Co-authored-by: Zhao Yang <[email protected]> (cherry picked from commit 55dad39)
1 parent 84ea158 commit f1e441e

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

auth_test.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,16 @@ def test_materialized_views_auth(self):
541541
* Create a new user, 'cathy', with no permissions
542542
* Create a ks, table
543543
* Connect as cathy
544+
*
544545
* Try CREATE MV without ALTER permission on base table, assert throws Unauthorized
545546
* Grant cathy ALTER permissions, then CREATE MV successfully
547+
*
548+
* Try to MODIFY base without WRITE permission on base, assert throws Unauthorized
549+
* Grant cathy WRITE permissions on base, and modify base successfully
550+
*
546551
* Try to SELECT from the mv, assert throws Unauthorized
547-
* Grant cathy SELECT permissions, and read from the MV successfully
552+
* Grant cathy SELECT permissions on base, and read from the MV successfully
553+
*
548554
* Revoke cathy's ALTER permissions, assert DROP MV throws Unauthorized
549555
* Restore cathy's ALTER permissions, DROP MV successfully
550556
"""
@@ -565,12 +571,36 @@ def test_materialized_views_auth(self):
565571
cassandra.execute("GRANT ALTER ON ks.cf TO cathy")
566572
cathy.execute(create_mv)
567573

568-
# TRY SELECT MV without SELECT permission on base table
569-
assert_unauthorized(cathy, "SELECT * FROM ks.mv1", "User cathy has no SELECT permission on <table ks.cf> or any of its parents")
574+
# Try MODIFY base without WRITE permission on base
575+
assert_unauthorized(cathy, "INSERT INTO ks.cf(id, value) VALUES(1, '1')", "User cathy has no MODIFY permission on <table ks.cf> or any of its parents")
570576

571-
# Grant SELECT permission and CREATE MV
572-
cassandra.execute("GRANT SELECT ON ks.cf TO cathy")
573-
cathy.execute("SELECT * FROM ks.mv1")
577+
if self.cluster.version() >= LooseVersion('4.0'):
578+
# From 4.0 onward, only base MODIFY permission is required to update base with MV
579+
# Grant WRITE permission on Base
580+
cassandra.execute("GRANT MODIFY ON ks.cf TO cathy")
581+
cathy.execute("INSERT INTO ks.cf(id, value) VALUES(1, '1')")
582+
583+
# TRY SELECT MV without SELECT permission on base table
584+
assert_unauthorized(cathy, "SELECT * FROM ks.cf", "User cathy has no SELECT permission on <table ks.cf> or any of its parents")
585+
assert_unauthorized(cathy, "SELECT * FROM ks.mv1", "User cathy has no SELECT permission on <table ks.cf> or any of its parents")
586+
587+
# Grant SELECT permission
588+
cassandra.execute("GRANT SELECT ON ks.cf TO cathy")
589+
assert_one(cathy, "SELECT * FROM ks.cf", [1, '1'])
590+
assert_one(cathy, "SELECT * FROM ks.mv1", ['1', 1])
591+
else:
592+
# Before 4.0, MODIFY on MV is required to insert to base
593+
# Grant WRITE permission on Base
594+
cassandra.execute("GRANT MODIFY ON ks.cf TO cathy")
595+
assert_unauthorized(cathy, "INSERT INTO ks.cf(id, value) VALUES(1, '1')", "User cathy has no SELECT permission on <table ks.cf> or any of its parents")
596+
cassandra.execute("GRANT SELECT ON ks.cf TO cathy")
597+
assert_unauthorized(cathy, "INSERT INTO ks.cf(id, value) VALUES(1, '1')", "User cathy has no MODIFY permission on <table ks.mv1> or any of its parents")
598+
599+
# Grant WRITE permission on MV
600+
cassandra.execute("GRANT MODIFY ON ks.mv1 TO cathy")
601+
cathy.execute("INSERT INTO ks.cf(id, value) VALUES(1, '1')")
602+
assert_one(cathy, "SELECT * FROM ks.cf", [1, '1'])
603+
assert_one(cathy, "SELECT * FROM ks.mv1", ['1', 1])
574604

575605
# Revoke ALTER permission and try DROP MV
576606
cassandra.execute("REVOKE ALTER ON ks.cf FROM cathy")

0 commit comments

Comments
 (0)