1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
-- test-run result file version 2
netbox = require('net.box')
| ---
| ...
fiber = require('fiber')
| ---
| ...
--
-- gh-2763: when credentials of a user are updated, it should be
-- reflected in all his sessions and objects.
--
box.schema.user.create('test_user', {password = '1'})
| ---
| ...
function test1() return 'success' end
| ---
| ...
conns = {}
| ---
| ...
for i = 1, 10 do \
local c \
if i % 2 == 0 then \
c = netbox.connect( \
box.cfg.listen, {user = 'test_user', password = '1'}) \
else \
c = netbox.connect(box.cfg.listen) \
end \
local ok, err = pcall(c.call, c, 'test1') \
assert(not ok and err.code == box.error.ACCESS_DENIED) \
table.insert(conns, c) \
end
| ---
| ...
box.schema.user.grant('test_user', 'execute', 'universe')
| ---
| ...
box.schema.user.grant('guest', 'execute', 'universe')
| ---
| ...
-- Succeeds without a reconnect.
for _, c in pairs(conns) do \
assert(c:call('test1') == 'success') \
c:close() \
end
| ---
| ...
box.schema.user.revoke('guest', 'execute', 'universe')
| ---
| ...
box.schema.user.drop('test_user')
| ---
| ...
--
-- Box.session.su() credentials are updated even when su-ed
-- function is still in progress.
--
-- Create a persistent function, because normal Lua functions
-- does not check 'execute' locally.
box.schema.func.create("test2", { \
language = 'LUA', returns = 'string', \
body = 'function () return "success" end', \
is_deterministic = true, param_list = {} \
})
| ---
| ...
do_wait = true
| ---
| ...
ok, err = nil
| ---
| ...
function call_wait_call() \
ok, err = pcall(box.func.test2.call, box.func.test2) \
while do_wait do fiber.yield() end \
ok, err = pcall(box.func.test2.call, box.func.test2) \
end
| ---
| ...
f = fiber.create(box.session.su, 'guest', call_wait_call)
| ---
| ...
while ok == nil do fiber.yield() end
| ---
| ...
-- Error, 'guest' does not have access to 'test2'.
ok, err
| ---
| - false
| - Execute access to function 'test2' is denied for user 'guest'
| ...
box.schema.user.grant('guest', 'execute', 'universe')
| ---
| ...
do_wait = false
| ---
| ...
while f:status() ~= 'dead' do fiber.yield() end
| ---
| ...
-- Should be ok even though su() was still in progress.
ok, err
| ---
| - true
| - success
| ...
box.schema.user.revoke('guest', 'execute', 'universe')
| ---
| ...
--
-- Setuid functions initialize their credentials on demand. And
-- these credentials should be up to date.
--
box.schema.user.grant('guest', 'read, write', 'space', '_func')
| ---
| ...
box.schema.user.grant('guest', 'create', 'function')
| ---
| ...
box.session.su('guest')
| ---
| ...
box.schema.func.create("test3", { \
language = 'LUA', returns = 'string', \
body = 'function () return box.func.test2:call() end', \
is_deterministic = true, param_list = {}, setuid = true \
})
| ---
| ...
box.session.su('admin')
| ---
| ...
-- Error, guest does not have access to 'test2' called from
-- 'test3'.
box.func.test3:call()
| ---
| - error: Execute access to function 'test2' is denied for user 'guest'
| ...
box.schema.user.grant('guest', 'execute', 'universe')
| ---
| ...
-- Now the function owner's credentials should be updated, and
-- anyone called test3 should have updated rights.
box.func.test3:call()
| ---
| - success
| ...
box.func.test3:drop()
| ---
| ...
box.func.test2:drop()
| ---
| ...
box.schema.user.revoke('guest', 'create', 'function')
| ---
| ...
box.schema.user.revoke('guest', 'read, write', 'space', '_func')
| ---
| ...
box.schema.user.revoke('guest', 'execute', 'universe')
| ---
| ...
|