Skip to content

Commit 2a851e1

Browse files
committed
HBASE-26208 Supports revoke namespace specified permission
1 parent 085325c commit 2a851e1

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

hbase-shell/src/main/ruby/hbase/security.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,21 @@ def revoke(user, table_name = nil, family = nil, qualifier = nil)
100100
namespace_name = table_name[1...table_name.length]
101101
raise(ArgumentError, "Can't find a namespace: #{namespace_name}") unless namespace_exists?(namespace_name)
102102

103-
tablebytes = table_name.to_java_bytes
104-
org.apache.hadoop.hbase.security.access.AccessControlClient.revoke(
105-
@connection, namespace_name, user
106-
)
103+
if (!family.nil?)
104+
permission = family[1...family.length-1]
105+
perm = org.apache.hadoop.hbase.security.access.Permission.new(
106+
permission.to_java_bytes
107+
)
108+
puts "revoke #{permission} permission"
109+
org.apache.hadoop.hbase.security.access.AccessControlClient.revoke(
110+
@connection, namespace_name, user, perm.getActions
111+
)
112+
else
113+
tablebytes = table_name.to_java_bytes
114+
org.apache.hadoop.hbase.security.access.AccessControlClient.revoke(
115+
@connection, namespace_name, user
116+
)
117+
end
107118
else
108119
# Table should exist
109120
raise(ArgumentError, "Can't find a table: #{table_name}") unless exists?(table_name)

hbase-shell/src/main/ruby/shell/commands/revoke.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def help
3333
3434
hbase> revoke 'bobsmith'
3535
hbase> revoke '@admins'
36-
hbase> revoke 'bobsmith', '@ns1'
36+
hbase> revoke 'bobsmith', '@ns1', 'RWXCA'
3737
hbase> revoke 'bobsmith', 't1', 'f1', 'col1'
3838
hbase> revoke 'bobsmith', 'ns1:t1', 'f1', 'col1'
3939
EOF

hbase-shell/src/test/ruby/hbase/security_admin_test.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,34 @@ def teardown
5252
assert_equal(0, security_admin.user_permission(@test_name).length)
5353
end
5454

55+
define_test "Revoke namespace should rid access rights appropriately" do
56+
ns = 'test_ns_grant_revoke'
57+
command(:drop_namespace, ns)
58+
command(:create_namespace, ns)
59+
test_ns_grant_revoke_user = org.apache.hadoop.hbase.security.User.createUserForTesting(
60+
$TEST_CLUSTER.getConfiguration, "test_ns_grant_revoke", []).getName()
61+
security_admin.grant(test_grant_revoke_user,"WRC", ns)
62+
security_admin.user_permission(ns) do |user, permission|
63+
assert_match(eval("/WRITE/"), permission.to_s)
64+
assert_match(eval("/READ/"), permission.to_s)
65+
assert_match(eval("/CREATE/"), permission.to_s)
66+
end
67+
68+
security_admin.revoke(test_grant_revoke_user, ns, "C")
69+
found_permission = false
70+
security_admin.user_permission(ns) do |user, permission|
71+
if user == "test_ns_grant_revoke"
72+
assert_match(eval("/READ/"), permission.to_s)
73+
assert_match(eval("/WRITE/"), permission.to_s)
74+
assert_no_match(eval("/EXEC/"), permission.to_s)
75+
assert_no_match(eval("/CREATE/"), permission.to_s)
76+
assert_no_match(eval("/ADMIN/"), permission.to_s)
77+
found_permission = true
78+
end
79+
end
80+
assert(found_permission, "Permission for user test_ns_grant_revoke was not found.")
81+
end
82+
5583
define_test "Grant should set access rights appropriately" do
5684
drop_test_table(@test_name)
5785
create_test_table(@test_name)

0 commit comments

Comments
 (0)