Skip to content

Commit 090b2da

Browse files
committed
Clarify info in the box.session module
- 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 090b2da

File tree

7 files changed

+107
-57
lines changed

7 files changed

+107
-57
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.
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: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
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

1412
This is the same as :doc:`/reference/reference_lua/box_session/uid`, except
1513
in two cases:
1614

17-
* The first case: if the call to ``box.session.euid()`` is within
15+
* The call to ``box.session.euid()`` is within
1816
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).
17+
:doc:`box.session.su() </reference/reference_lua/box_session/su>`.
18+
In this case:
19+
20+
- ``box.session.euid()`` returns the ID of the changed user
21+
(the user who is specified by the ``user-name`` parameter of the ``box.session.su()`` function).
22+
- ``box.session.uid()`` returns the ID of the original user
23+
(the user who calls the ``box.session.su()`` function).
2424

25-
* The second case: if the call to ``box.session.euid()`` is within
25+
* The call to ``box.session.euid()`` is within
2626
a function specified with
2727
: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".
28+
and the binary protocol is in use.
29+
In this case:
30+
31+
- ``box.session.euid()`` returns the ID of the user who created ``function-name``.
32+
- ``box.session.uid()`` returns the ID of the user who calls ``function-name``.
3233

3334
:rtype: number
3435

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,68 @@
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+
- :ref:`box.session.user() <box_session-user>` ignores this change
18+
- :ref:`box.session.effective_user() <box_session-effective_user>` shows this change.
1919

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

26-
**Example:**
40+
.. code-block:: tarantoolsession
2741
28-
.. code-block:: tarantoolsession
42+
app:instance001> function get_current_user() return box.session.user() end
43+
---
44+
...
45+
46+
app:instance001> function get_effective_user() return box.session.effective_user() end
47+
---
48+
...
49+
50+
app:instance001> box.session.su('temporary_user', get_current_user)
51+
---
52+
- admin
53+
...
2954
30-
tarantool> function f(a) return box.session.user() .. a end
55+
app:instance001> box.session.su('temporary_user', get_effective_user)
3156
---
57+
- temporary_user
3258
...
3359
34-
tarantool> box.session.su('guest', f, '-xxx')
60+
app:instance001> box.session.su('temporary_user', get_effective_user, '-xxx')
3561
---
36-
- guest-xxx
62+
- temporary_user-xxx
3763
...
3864
39-
tarantool> box.session.su('guest',function(...) return ... end,1,2)
65+
app:instance001> box.session.su('temporary_user', function(...) return box.session.user() end)
4066
---
41-
- 1
42-
- 2
67+
- admin
4368
...

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)