Skip to content

Commit

Permalink
schema: add "_vcollation" sysview
Browse files Browse the repository at this point in the history
Add "_vcollation" sysview to read it from net.box. This
sysview is always readable, exept when the user doesn't have
"public" role.

Needed for #3941
  • Loading branch information
romanhabibov committed May 28, 2019
1 parent 0891b15 commit 5eab44d
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 13 deletions.
Binary file modified src/box/bootstrap.snap
Binary file not shown.
2 changes: 2 additions & 0 deletions src/box/lua/space.cc
Expand Up @@ -525,6 +525,8 @@ box_lua_space_init(struct lua_State *L)
lua_setfield(L, -2, "FUNC_ID");
lua_pushnumber(L, BOX_COLLATION_ID);
lua_setfield(L, -2, "COLLATION_ID");
lua_pushnumber(L, BOX_VCOLLATION_ID);
lua_setfield(L, -2, "VCOLLATION_ID");
lua_pushnumber(L, BOX_VFUNC_ID);
lua_setfield(L, -2, "VFUNC_ID");
lua_pushnumber(L, BOX_PRIV_ID);
Expand Down
25 changes: 25 additions & 0 deletions src/box/lua/upgrade.lua
Expand Up @@ -737,6 +737,30 @@ local function upgrade_to_2_1_3()
end
end

local function create_vcollation_space()
local _collation = box.space._collation
local format = _collation:format()
create_sysview(box.schema.COLLATION_ID, box.schema.VCOLLATION_ID)
box.space[box.schema.VCOLLATION_ID]:format(format)
end

local function upgrade_to_2_1_4()
local _collation = box.space._collation
local _index = box.space._index

-- System space format usually is in order "id, owner, name...".
-- The fields "name", "owner" are swapped in "_collation" format,
-- due to the field "owner" was added after the "_collation" creation.
box.space._index:delete{276, 1}
log.info("update index name on _collation")
box.space._index:insert{_collation.id, 2, 'name', 'tree', {unique = true},
{{1, 'string'}}}
log.info("create index owner on _collation")
box.space._index:insert{_collation.id, 1, 'owner', 'tree', {unique = false},
{{2, 'unsigned'}}}
create_vcollation_space()
end

local function get_version()
local version = box.space._schema:get{'version'}
if version == nil then
Expand Down Expand Up @@ -768,6 +792,7 @@ local function upgrade(options)
{version = mkversion(2, 1, 1), func = upgrade_to_2_1_1, auto = true},
{version = mkversion(2, 1, 2), func = upgrade_to_2_1_2, auto = true},
{version = mkversion(2, 1, 3), func = upgrade_to_2_1_3, auto = true},
{version = mkversion(2, 1, 4), func = upgrade_to_2_1_4, auto = true}
}

for _, handler in ipairs(handlers) do
Expand Down
2 changes: 2 additions & 0 deletions src/box/schema_def.h
Expand Up @@ -72,6 +72,8 @@ enum {
BOX_SCHEMA_ID = 272,
/** Space id of _collation. */
BOX_COLLATION_ID = 276,
/** Space id of _vcollation. */
BOX_VCOLLATION_ID = 277,
/** Space id of _space. */
BOX_SPACE_ID = 280,
/** Space id of _vspace view. */
Expand Down
13 changes: 13 additions & 0 deletions src/box/sysview.c
Expand Up @@ -402,6 +402,14 @@ vsequence_filter(struct space *source, struct tuple *tuple)
((PRIV_WRDA | PRIV_X) & effective);
}

static bool
vcollation_filter(struct space *source, struct tuple *tuple)
{
(void) source;
(void) tuple;
return true;
}

static struct index *
sysview_space_create_index(struct space *space, struct index_def *def)
{
Expand Down Expand Up @@ -448,6 +456,11 @@ sysview_space_create_index(struct space *space, struct index_def *def)
source_index_id = def->iid;
filter = vsequence_filter;
break;
case BOX_VCOLLATION_ID:
source_space_id = BOX_COLLATION_ID;
source_index_id = def->iid;
filter = vcollation_filter;
break;
default:
diag_set(ClientError, ER_MODIFY_INDEX,
def->name, space_name(space),
Expand Down
4 changes: 2 additions & 2 deletions test/app-tap/tarantoolctl.test.lua
Expand Up @@ -405,8 +405,8 @@ do
check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 1", "\n", 3)
check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 1 --replica 2", "\n", 3)
check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 2", "\n", 0)
check_ctlcat_snap(test_i, dir, "--space=280", "---\n", 21)
check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 47)
check_ctlcat_snap(test_i, dir, "--space=280", "---\n", 22)
check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 51)
end)
end)

Expand Down
13 changes: 11 additions & 2 deletions test/box-py/bootstrap.result
Expand Up @@ -4,7 +4,7 @@ box.internal.bootstrap()
box.space._schema:select{}
---
- - ['max_id', 511]
- ['version', 2, 1, 3]
- ['version', 2, 1, 4]
...
box.space._cluster:select{}
---
Expand All @@ -21,6 +21,10 @@ box.space._space:select{}
'name': 'name', 'type': 'string'}, {'name': 'owner', 'type': 'unsigned'},
{'name': 'type', 'type': 'string'}, {'name': 'locale', 'type': 'string'}, {
'name': 'opts', 'type': 'map'}]]
- [277, 1, '_vcollation', 'sysview', 0, {}, [{'name': 'id', 'type': 'unsigned'},
{'name': 'name', 'type': 'string'}, {'name': 'owner', 'type': 'unsigned'}, {
'name': 'type', 'type': 'string'}, {'name': 'locale', 'type': 'string'}, {
'name': 'opts', 'type': 'map'}]]
- [280, 1, '_space', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'owner',
'type': 'unsigned'}, {'name': 'name', 'type': 'string'}, {'name': 'engine',
'type': 'string'}, {'name': 'field_count', 'type': 'unsigned'}, {'name': 'flags',
Expand Down Expand Up @@ -83,7 +87,11 @@ box.space._index:select{}
---
- - [272, 0, 'primary', 'tree', {'unique': true}, [[0, 'string']]]
- [276, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]]
- [276, 1, 'name', 'tree', {'unique': true}, [[1, 'string']]]
- [276, 1, 'owner', 'tree', {'unique': false}, [[2, 'unsigned']]]
- [276, 2, 'name', 'tree', {'unique': true}, [[1, 'string']]]
- [277, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]]
- [277, 1, 'owner', 'tree', {'unique': false}, [[2, 'unsigned']]]
- [277, 2, 'name', 'tree', {'unique': true}, [[1, 'string']]]
- [280, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]]
- [280, 1, 'owner', 'tree', {'unique': false}, [[1, 'unsigned']]]
- [280, 2, 'name', 'tree', {'unique': true}, [[2, 'string']]]
Expand Down Expand Up @@ -150,6 +158,7 @@ box.space._priv:select{}
- [1, 1, 'universe', 0, 4294967295]
- [1, 2, 'function', 1, 4]
- [1, 2, 'space', 276, 2]
- [1, 2, 'space', 277, 1]
- [1, 2, 'space', 281, 1]
- [1, 2, 'space', 286, 1]
- [1, 2, 'space', 289, 1]
Expand Down
4 changes: 4 additions & 0 deletions test/box/access_misc.result
Expand Up @@ -761,6 +761,10 @@ box.space._space:select()
'name': 'name', 'type': 'string'}, {'name': 'owner', 'type': 'unsigned'},
{'name': 'type', 'type': 'string'}, {'name': 'locale', 'type': 'string'}, {
'name': 'opts', 'type': 'map'}]]
- [277, 1, '_vcollation', 'sysview', 0, {}, [{'name': 'id', 'type': 'unsigned'},
{'name': 'name', 'type': 'string'}, {'name': 'owner', 'type': 'unsigned'}, {
'name': 'type', 'type': 'string'}, {'name': 'locale', 'type': 'string'}, {
'name': 'opts', 'type': 'map'}]]
- [280, 1, '_space', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'owner',
'type': 'unsigned'}, {'name': 'name', 'type': 'string'}, {'name': 'engine',
'type': 'string'}, {'name': 'field_count', 'type': 'unsigned'}, {'name': 'flags',
Expand Down
92 changes: 85 additions & 7 deletions test/box/access_sysview.result
Expand Up @@ -74,6 +74,10 @@ session.su('guest')
---
- true
...
#box.space._vspace.index[2]:select('_vcollation') ~= 0
---
- true
...
#box.space._vindex:select(box.space._vspace.id) > 0
---
- true
Expand All @@ -94,6 +98,10 @@ session.su('guest')
---
- true
...
#box.space._vindex:select(box.space._vcollation.id) > 0
---
- true
...
box.session.su('admin')
---
...
Expand Down Expand Up @@ -127,6 +135,10 @@ box.session.su('guest')
---
- error: Read access to space '_vsequence' is denied for user 'guest'
...
#box.space._vcollation:select{}
---
- error: Read access to space '_vcollation' is denied for user 'guest'
...
box.session.su('admin')
---
...
Expand All @@ -138,11 +150,15 @@ box.session.su('guest')
...
#box.space._vspace:select{}
---
- 8
- 9
...
#box.space._vindex:select{}
---
- 20
- 24
...
#box.space._vcollation:select{}
---
- 277
...
box.session.su('admin')
---
Expand Down Expand Up @@ -230,24 +246,28 @@ box.session.su('guest')
...
#box.space._vspace:select{}
---
- 22
- 23
...
#box.space._vindex:select{}
---
- 48
- 52
...
#box.space._vuser:select{}
---
- 5
...
#box.space._vpriv:select{}
---
- 15
- 16
...
#box.space._vfunc:select{}
---
- 1
...
#box.space._vcollation:select{}
---
- 277
...
box.session.su('admin')
---
...
Expand All @@ -262,15 +282,15 @@ box.session.su('guest')
...
#box.space._vindex:select{}
---
- 48
- 52
...
#box.space._vuser:select{}
---
- 5
...
#box.space._vpriv:select{}
---
- 15
- 16
...
#box.space._vfunc:select{}
---
Expand All @@ -280,6 +300,10 @@ box.session.su('guest')
---
- 0
...
#box.space._vcollation:select{}
---
- 277
...
box.session.su('admin')
---
...
Expand Down Expand Up @@ -631,6 +655,60 @@ seq:drop()
---
...
--
-- _vcollation
--
box.session.su('admin')
---
...
box.internal.collation.create('test', 'ICU', 'ru-RU')
---
...
-- Only admin can create collation.
coll_cnt = #box.space._collation:select{}
---
...
box.schema.user.grant("guest", "read, write, alter, execute", "space", "_collation")
---
...
box.session.su("guest")
---
...
box.internal.collation.create('guest0', 'ICU', 'ru-RU')
---
- error: Create access to collation 'guest0' is denied for user 'guest'
...
box.space._vcollation:select{0}
---
- - [0, 'none', 1, 'BINARY', '', {}]
...
#box.space._vcollation:select{} == coll_cnt
---
- true
...
box.session.su('admin')
---
...
-- _vcollation is readable anyway.
box.schema.user.revoke("guest", "read", "space", "_collation")
---
...
box.session.su("guest")
---
...
#box.space._vcollation:select{}
---
- 278
...
session.su('admin')
---
...
box.internal.collation.drop('test')
---
...
box.internal.collation.drop('guest0')
---
...
--
-- view:alter() tests
--
box.space._vspace.index[1]:alter({parts = { 2, 'string' }})
Expand Down
30 changes: 30 additions & 0 deletions test/box/access_sysview.test.lua
Expand Up @@ -31,12 +31,14 @@ session.su('guest')
#box.space._vspace.index[2]:select('_vuser') ~= 0
#box.space._vspace.index[2]:select('_vfunc') ~= 0
#box.space._vspace.index[2]:select('_vpriv') ~= 0
#box.space._vspace.index[2]:select('_vcollation') ~= 0

#box.space._vindex:select(box.space._vspace.id) > 0
#box.space._vindex:select(box.space._vindex.id) > 0
#box.space._vindex:select(box.space._vuser.id) > 0
#box.space._vindex:select(box.space._vfunc.id) > 0
#box.space._vindex:select(box.space._vpriv.id) > 0
#box.space._vindex:select(box.space._vcollation.id) > 0

box.session.su('admin')
box.schema.user.revoke('guest', 'public')
Expand All @@ -48,13 +50,15 @@ box.session.su('guest')
#box.space._vpriv:select{}
#box.space._vfunc:select{}
#box.space._vsequence:select{}
#box.space._vcollation:select{}

box.session.su('admin')
box.schema.user.grant('guest', 'public')
box.session.su('guest')

#box.space._vspace:select{}
#box.space._vindex:select{}
#box.space._vcollation:select{}

box.session.su('admin')
s = box.schema.space.create('test')
Expand Down Expand Up @@ -96,6 +100,7 @@ box.session.su('guest')
#box.space._vuser:select{}
#box.space._vpriv:select{}
#box.space._vfunc:select{}
#box.space._vcollation:select{}

box.session.su('admin')
box.schema.user.revoke('guest', 'read', 'universe')
Expand All @@ -107,6 +112,7 @@ box.session.su('guest')
#box.space._vpriv:select{}
#box.space._vfunc:select{}
#box.space._vsequence:select{}
#box.space._vcollation:select{}

box.session.su('admin')
box.schema.user.revoke('guest', 'write', 'universe')
Expand Down Expand Up @@ -264,6 +270,30 @@ box.session.su("guest")
session.su('admin')
seq:drop()

--
-- _vcollation
--

box.session.su('admin')
box.internal.collation.create('test', 'ICU', 'ru-RU')

-- Only admin can create collation.
coll_cnt = #box.space._collation:select{}
box.schema.user.grant("guest", "read, write, alter, execute", "space", "_collation")
box.session.su("guest")
box.internal.collation.create('guest0', 'ICU', 'ru-RU')
box.space._vcollation:select{0}
#box.space._vcollation:select{} == coll_cnt
box.session.su('admin')

-- _vcollation is readable anyway.
box.schema.user.revoke("guest", "read", "space", "_collation")
box.session.su("guest")
#box.space._vcollation:select{}
session.su('admin')
box.internal.collation.drop('test')
box.internal.collation.drop('guest0')

--
-- view:alter() tests
--
Expand Down

0 comments on commit 5eab44d

Please sign in to comment.