Skip to content

Commit 06104a9

Browse files
committed
HBASE-26208 Supports revoke @ns specified permission
1 parent 5cf728d commit 06104a9

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def help
3434
hbase> revoke 'bobsmith'
3535
hbase> revoke '@admins'
3636
hbase> revoke 'bobsmith', '@ns1'
37+
hbase> revoke 'bobsmith', '@ns1', 'RWXCA'
3738
hbase> revoke 'bobsmith', 't1', 'f1', 'col1'
3839
hbase> revoke 'bobsmith', 'ns1:t1', 'f1', 'col1'
3940
EOF

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@ def teardown
7878
assert(found_permission, "Permission for user test_grant_revoke was not found.")
7979
end
8080

81+
define_test "Grant and revoke should set access rights appropriately" do
82+
drop_test_table(@test_name)
83+
create_test_table(@test_name)
84+
table = table(@test_name)
85+
test_grant_revoke_user = org.apache.hadoop.hbase.security.User.createUserForTesting(
86+
$TEST_CLUSTER.getConfiguration, "test_grant_revoke", []).getName()
87+
88+
security_admin.grant(test_grant_revoke_user,"RWXCA", @test_name)
89+
security_admin.revoke(test_grant_revoke_user, @test_name, "CA")
90+
found_permission = false
91+
security_admin.user_permission(@test_name) do |user, permission|
92+
if user == "test_grant_revoke"
93+
assert_match(eval("/READ/"), permission.to_s)
94+
assert_match(eval("/WRITE/"), permission.to_s)
95+
assert_match(eval("/EXEC/"), permission.to_s)
96+
assert_no_match(eval("/CREATE/"), permission.to_s)
97+
assert_no_match(eval("/ADMIN/"), permission.to_s)
98+
found_permission = true
99+
end
100+
end
101+
assert(found_permission, "Permission for user test_grant_revoke was not found.")
102+
end
103+
81104
define_test 'Grant and revoke global permission should set access rights appropriately' do
82105
global_user_name = 'test_grant_revoke_global'
83106
security_admin.grant(global_user_name, 'W')

0 commit comments

Comments
 (0)