Skip to content

Commit

Permalink
drivers: add grant method for all driver spaces
Browse files Browse the repository at this point in the history
There was a bug that grant for a user didn't work for spaces with
`_ready_buffer` suffix.

After the patch the `grant` method was added for each driver that
accounts the `grant` for all spaces.

Closes #237
  • Loading branch information
themilchenko committed Oct 9, 2024
1 parent 3bfd1e2 commit 24d0e1a
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 2 deletions.
2 changes: 1 addition & 1 deletion queue/abstract.lua
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ function tube.grant(self, user, args)
tube_grant_space(user, '_queue', 'read')
tube_grant_space(user, '_queue_consumers')
tube_grant_space(user, '_queue_taken_2')
tube_grant_space(user, self.name)
self.raw:grant(user, {if_not_exists = true})
session.grant(user)

if args.call then
Expand Down
5 changes: 5 additions & 0 deletions queue/abstract/driver/fifo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ function tube.new(space, on_task_change)
return self
end

-- method.grant grants provided user to all spaces of driver.
function method.grant(self, user, opts)
box.schema.user.grant(user, 'read,write', 'space', self.space.name, opts)
end

-- normalize task: cleanup all internal fields
function method.normalize_task(self, task)
return task
Expand Down
5 changes: 5 additions & 0 deletions queue/abstract/driver/fifottl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ function tube.new(space, on_task_change, opts)
return self
end

-- method.grant grants provided user to all spaces of driver.
function method.grant(self, user, opts)
box.schema.user.grant(user, 'read,write', 'space', self.space.name, opts)
end

-- cleanup internal fields in task
function method.normalize_task(self, task)
return task and task:transform(3, 5)
Expand Down
8 changes: 8 additions & 0 deletions queue/abstract/driver/utube.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ function tube.new(space, on_task_change, opts)
return self
end

-- method.grant grants provided user to all spaces of driver.
function method.grant(self, user, opts)
box.schema.user.grant(user, 'read,write', 'space', self.space.name, opts)
if self.space_ready_buffer ~= nil then
box.schema.user.grant(user, 'read,write', 'space', self.space_ready_buffer.name, opts)
end
end

-- normalize task: cleanup all internal fields
function method.normalize_task(self, task)
return task and task:transform(3, 1)
Expand Down
8 changes: 8 additions & 0 deletions queue/abstract/driver/utubettl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ function tube.new(space, on_task_change, opts)
return self
end

-- method.grant grants provided user to all spaces of driver.
function method.grant(self, user, opts)
box.schema.user.grant(user, 'read,write', 'space', self.space.name, opts)
if self.space_ready_buffer ~= nil then
box.schema.user.grant(user, 'read,write', 'space', self.space_ready_buffer.name, opts)
end
end

-- cleanup internal fields in task
function method.normalize_task(self, task)
return task and task:transform(i_next_event, i_data - i_next_event)
Expand Down
64 changes: 63 additions & 1 deletion t/090-grant-check.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env tarantool
local test = require('tap').test()
test:plan(3)
test:plan(9)

local test_user = 'test'
local test_pass = '1234'
Expand All @@ -21,6 +21,68 @@ local engine = os.getenv('ENGINE') or 'memtx'

local qc = require('queue.compat')

local test_drivers_grant_cases = {
{
name = 'fifo',
queue_type = 'fifo',
},
{
name = 'fifottl',
queue_type = 'fifottl',
},
{
name = 'utube_default',
queue_type = 'utube',
storage_mode = 'default',
},
{
name = 'utube_ready_buffer',
queue_type = 'utube',
storage_mode = 'ready_buffer',
},
{
name = 'utubettl_default',
queue_type = 'utubettl',
storage_mode = 'default',
},
{
name = 'utubettl_ready_buffer',
queue_type = 'utubettl',
storage_mode = 'ready_buffer',
},
}

for _, tc in pairs(test_drivers_grant_cases) do
test:test('test dirvers grant ' .. tc.name, function(test)
local queue = require('queue')
box.schema.user.create(test_user, { password = test_pass })

test:plan(2)

local tube_opts = { engine = engine }
if tc.storage_mode ~= nil and tc.storage_mode ~= 'default' then
tube_opts.storage_mode = tc.storage_mode
tube_opts.engine = 'memtx'
end
local tube = queue.create_tube('test', tc.queue_type, tube_opts)
tube:put('help')

tube:grant(test_user)

box.session.su(test_user)
local a = tube:take()
test:is(a[1], 0, 'we aren\'t getting any error')

local c = tube:ack(a[1])
test:is(c[1], 0, 'we aren\'t getting any error')

box.session.su('admin')

box.schema.user.drop(test_user)
tube:drop()
end)
end

test:test('check for space grants', function(test)
-- prepare for tests
local queue = require('queue')
Expand Down

0 comments on commit 24d0e1a

Please sign in to comment.