Skip to content

Commit 5ccdb23

Browse files
authored
Clarify info in the box.session module (#5065)
- Update description in `box.session.su()`, `box.session.user()`, `box.session.uid()`, and `box.session.euid()` - Add `box.session.effective_user()` page Fixes #5062
1 parent 18071dd commit 5ccdb23

File tree

7 files changed

+116
-58
lines changed

7 files changed

+116
-58
lines changed

doc/reference/reference_lua/box_session.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ Below is a list of all ``box.session`` functions and members.
3939
* - :doc:`./box_session/user`
4040
- Get the current user's name
4141

42+
* - :doc:`./box_session/effective_user`
43+
- Get the current effective user's name
44+
4245
* - :doc:`./box_session/type`
4346
- Get the connection type or cause of action
4447

@@ -49,7 +52,7 @@ Below is a list of all ``box.session`` functions and members.
4952
- Get the current user's ID
5053

5154
* - :doc:`./box_session/euid`
52-
- Get the current effective user's ID
55+
- Get the current effective user's ID
5356

5457
* - :doc:`./box_session/storage`
5558
- Table with session-specific names and values
@@ -61,10 +64,10 @@ Below is a list of all ``box.session`` functions and members.
6164
- Define a disconnect trigger
6265

6366
* - :doc:`./box_session/on_auth`
64-
- Define an authentication trigger
67+
- Define an authentication trigger
6568

6669
* - :doc:`./box_session/on_access_denied`
67-
- Define a trigger to report restricted actions
70+
- Define a trigger to report restricted actions
6871

6972
* - :doc:`./box_session/push`
7073
- (Deprecated) Send an out-of-band message
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.. _box_session-effective_user:
2+
3+
box.session.effective_user()
4+
============================
5+
6+
.. module:: box.session
7+
8+
.. function:: effective_user()
9+
10+
Return the name of the *effective user* -- this user determines the process's permissions at any given moment.
11+
If the :ref:`current user <authentication-users>` is changed temporarily using the :ref:`box.session.su() <box_session-su>` method,
12+
`box.session.effective_user()` shows this change.
13+
14+
See also: :ref:`box.session.euid() <box_session-euid>`
15+
16+
:return: the current effective user's name
17+
18+
:rtype: string

doc/reference/reference_lua/box_session/euid.rst

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1+
.. _box_session-euid:
12

2-
.. _box_session-euid:
3-
4-
================================================================================
53
box.session.euid()
6-
================================================================================
4+
==================
75

86
.. module:: box.session
97

108
.. function:: euid()
119

12-
:return: the effective user ID of the :ref:`current user <authentication-users>`.
10+
:return: the :ref:`effective user <box_session-effective_user>` ID of the :ref:`current user <authentication-users>`.
1311

12+
The system uses the effective user ID to determine the process's permissions at any given moment.
1413
This is the same as :doc:`/reference/reference_lua/box_session/uid`, except
15-
in two cases:
14+
two cases:
1615

17-
* The first case: if the call to ``box.session.euid()`` is within
16+
* ``box.session.euid()`` is called within
1817
a function invoked by
19-
:doc:`box.session.su(user-name, function-to-execute) </reference/reference_lua/box_session/su>`
20-
-- in that case, ``box.session.euid()`` returns the ID of the changed user
21-
(the user who is specified by the ``user-name`` parameter of the ``su``
22-
function) but ``box.session.uid()`` returns the ID of the original user
23-
(the user who is calling the ``su`` function).
18+
:doc:`box.session.su() </reference/reference_lua/box_session/su>`.
19+
In this case:
20+
21+
- ``box.session.euid()`` returns the ID of the changed user
22+
(the user who is specified by the ``user-name`` parameter of the ``box.session.su()`` function).
23+
- ``box.session.uid()`` returns the ID of the original user
24+
(the user who calls the ``box.session.su()`` function).
2425

25-
* The second case: if the call to ``box.session.euid()`` is within
26+
* ``box.session.euid()`` is called within
2627
a function specified with
2728
:doc:`box.schema.func.create(function-name, {setuid= true}) </reference/reference_lua/box_schema/func_create>`
28-
and the binary protocol is in use
29-
-- in that case, ``box.session.euid()`` returns the ID of the user who
30-
created "function-name" but ``box.session.uid()`` returns the ID of the
31-
the user who is calling "function-name".
29+
and the binary protocol is in use.
30+
In this case:
31+
32+
- ``box.session.euid()`` returns the ID of the user who created ``function-name``.
33+
- ``box.session.uid()`` returns the ID of the user who calls ``function-name``.
3234

3335
:rtype: number
3436

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,75 @@
1+
.. _box_session-su:
12

2-
.. _box_session-su:
3-
4-
================================================================================
53
box.session.su()
6-
================================================================================
4+
================
75

8-
.. module:: box.session
6+
.. module:: box.session
97

10-
.. function:: su(user-name [, function-to-execute])
8+
.. function:: su(user-name [, function-to-execute])
119

1210
Change Tarantool's :ref:`current user <authentication-users>` --
1311
this is analogous to the Unix command ``su``.
1412

15-
Or, if function-to-execute is specified,
16-
change Tarantool's :ref:`current user <authentication-users>`
17-
temporarily while executing the function --
13+
Or, if the ``function-to-execute`` option is specified,
14+
change Tarantool's current user temporarily while executing the function --
1815
this is analogous to the Unix command ``sudo``.
16+
If the user is changed temporarily:
17+
18+
- :ref:`box.session.user() <box_session-user>` ignores this change.
19+
- :ref:`box.session.effective_user() <box_session-effective_user>` shows this change.
20+
1921

2022
:param string user-name: name of a target user
21-
:param function-to-execute: name of a function, or definition of a function.
23+
:param function-to-execute: a function object.
2224
Additional parameters may be passed to
23-
``box.session.su``, they will be interpreted
24-
as parameters of function-to-execute.
25+
``box.session.su()``, they will be interpreted
26+
as parameters of ``function-to-execute``.
27+
28+
**Example 1**
29+
30+
Change Tarantool's current user to ``guest``:
31+
32+
.. code-block:: tarantoolsession
33+
34+
app:instance001> box.session.su('guest')
35+
---
36+
...
37+
38+
**Example 2**
39+
40+
Change Tarantool's current user to ``temporary_user`` temporarily:
2541

26-
**Example:**
42+
.. code-block:: tarantoolsession
2743
28-
.. code-block:: tarantoolsession
44+
app:instance001> function get_current_user() return box.session.user() end
45+
---
46+
...
47+
48+
app:instance001> function get_effective_user() return box.session.effective_user() end
49+
---
50+
...
51+
52+
app:instance001> get_current_user()
53+
---
54+
- admin
55+
...
56+
57+
app:instance001> box.session.su('temporary_user', get_current_user)
58+
---
59+
- admin
60+
...
2961
30-
tarantool> function f(a) return box.session.user() .. a end
62+
app:instance001> box.session.su('temporary_user', get_effective_user)
3163
---
64+
- temporary_user
3265
...
3366
34-
tarantool> box.session.su('guest', f, '-xxx')
67+
app:instance001> box.session.su('temporary_user', get_effective_user, '-xxx')
3568
---
36-
- guest-xxx
69+
- temporary_user-xxx
3770
...
3871
39-
tarantool> box.session.su('guest',function(...) return ... end,1,2)
72+
app:instance001> box.session.su('temporary_user', function(...) return box.session.user() end)
4073
---
41-
- 1
42-
- 2
74+
- admin
4375
...

doc/reference/reference_lua/box_session/uid.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1+
.. _box_session-uid:
12

2-
.. _box_session-uid:
3-
4-
================================================================================
53
box.session.uid()
6-
================================================================================
4+
=================
75

86
.. module:: box.session
97

doc/reference/reference_lua/box_session/user.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
.. _box_session-user:
12

2-
.. _box_session-user:
3-
4-
================================================================================
53
box.session.user()
6-
================================================================================
4+
==================
5+
6+
.. module:: box.session
7+
8+
.. function:: user()
79

8-
.. module:: box.session
10+
Return the name of the :ref:`current Tarantool user <authentication-users>`.
11+
If the current user is changed temporarily using the :ref:`box.session.su() <box_session-su>` method,
12+
`box.session.user()` ignores this change.
13+
In this case, ``box.session.user()`` returns the initial current user (the user who calls the ``box.session.su()`` function).
914

10-
.. function:: user()
15+
See also: :ref:`box.session.uid() <box_session-uid>`
1116

1217
:return: the name of the :ref:`current user <authentication-users>`
1318

locale/ru/LC_MESSAGES/reference/reference_lua/box_session/su.po

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ msgstr ""
1010
" аналогично Unix-команде ``su``."
1111

1212
msgid ""
13-
"Or, if function-to-execute is specified, change Tarantool's :ref:`current "
13+
"Or, if the `function-to-execute` option is specified, change Tarantool's :ref:`current "
1414
"user <authentication-users>` temporarily while executing the function -- "
1515
"this is analogous to the Unix command ``sudo``."
1616
msgstr ""
17-
"Или, если указана выполняемая функция (function-to-execute), временное "
17+
"Или, если указана выполняемая функция (`function-to-execute`), временное "
1818
"изменение :ref:`текущего пользователя <authentication-users>` Tarantool во"
1919
" время выполнения функции – аналогично Unix-команде ``sudo``."
2020

@@ -26,15 +26,15 @@ msgstr "целевое имя пользователя"
2626

2727
msgid ""
2828
"name of a function, or definition of a function. Additional parameters may "
29-
"be passed to ``box.session.su``, they will be interpreted as parameters of "
30-
"function-to-execute."
29+
"be passed to ``box.session.su()``, they will be interpreted as parameters of "
30+
"`function-to-execute`."
3131
msgstr ""
32-
"имя функции или определение функции. Дополнительные параметры могут "
33-
"передаваться в ``box.session.su``, они будут интерпретироваться как "
32+
"имя функции или определение функции. Дополнительные параметры, переданные "
33+
"в ``box.session.su``, интерпретируются как "
3434
"параметры выполняемой функции."
3535

36-
msgid "**Example:**"
37-
msgstr "**Пример:**"
36+
msgid "**Examples:**"
37+
msgstr "**Примеры:**"
3838

3939
msgid ""
4040
"tarantool> function f(a) return box.session.user() .. a end\n"

0 commit comments

Comments
 (0)