如何授予用户仅在Tarantool中执行特定功能的功能

问题描述

现在的挑战是:有2个功能。有一个用户只能执行其中一个。问题是怎么做? 如果您只写:Box.schema.user.grant(“用户”,“执行”,“函数”,“ dima”,nil,{if_not_exists = true}),则用户用户”根本无法连接。显示错误消息:用户'user'拒绝执行对Universe的执行。如何正确提供访问权限?

        Box.once("schema",function()
        Box.schema.user.create('superuser',{password = '11111111'})
        Box.schema.user.create('user',{password = '11111111'})
        Box.schema.user.grant('superuser','read,write,execute','universe',nil,{if_not_exists = true})
        Box.schema.user.grant('user','execute','function','dima',{if_not_exists = true})
        end)
        function reload(proc)
            package.loaded[proc]=nil return require(proc)
                end
        ws = reload('project/init')

功能dima:

local obj={}

function obj.open()
    return 'dima'
end

return obj

功能dima2:

local obj={}

function obj.open()
    return 'dima2'
end

return obj

Init.lua:

obj = {}
  collectgarbage('collect')
  net   = require('net.Box')
  fiber = require('fiber')
  uuid  = require('uuid')
  -- modules
  obj.dima  = reload('project/dima')
  obj.dima2 = reload('project/dima2')
return obj

解决方法

要仅授予一项功能,您可以执行以下操作:

valueData

然后打开一个单独的tarantool提示符(不是下面的tarantoolctl!解释)并输入以下内容:

box.cfg({listen=3301})

foo = function() print("bar") end

box.schema.user.create('myuser',{if_not_exists=true,password = 'secret'})

-- setuid is required here so that the function,when called by user with
-- restricted rights,will have access to everything
box.schema.func.create('foo',setuid=true})

box.schema.user.grant('myuser','execute','function','foo',{if_not_exists=true})

然后,您将在第一个控制台中看到“栏”。

看到“对用户'user'拒绝执行对Universe的执行”的原因是因为您尝试与tarantoolctl连接,这需要对整个数据库的读取访问权限。通过连接器或net.box调用会很好。