Skip to content

box: fix misleading errors on privilege revoke from admin#11699

Merged
sergepetrenko merged 1 commit intotarantool:masterfrom
sergepetrenko:gh-11526-privilege-misleading-error
Jul 23, 2025
Merged

box: fix misleading errors on privilege revoke from admin#11699
sergepetrenko merged 1 commit intotarantool:masterfrom
sergepetrenko:gh-11526-privilege-misleading-error

Conversation

@sergepetrenko
Copy link
Collaborator

Trying to revoke privileges from an admin user or a super role results in misleading errors:

error: 'Tuple field 5 (privilege) type does not match one required by operation:
    expected unsigned, got integer'

The reason is that privileges use bit module for privilege grant/revoke, and this module operates 32-bit signed integers (see https://bitop.luajit.org/semantics.html#range for details). So any bit operation on a privilege set greater than 2^31 (for example, box.priv.ALL == 2^32 - 1) results in a negative number:

tarantool> bit.band(box.priv.ALL, bit.bnot(box.priv.W))
---
- -3
...

Fortunately, this can be fixed by casting one of the operands to a uint64_t type, so let's cast all granted or revoked privileges prior to calculating the resulting privilege set.

Closes #11526

NO_DOC=bugfix

@sergepetrenko sergepetrenko self-assigned this Jul 22, 2025
@sergepetrenko sergepetrenko requested a review from a team as a code owner July 22, 2025 11:51
@sergepetrenko sergepetrenko force-pushed the gh-11526-privilege-misleading-error branch from 41d4245 to 52abba1 Compare July 22, 2025 11:58
@sergepetrenko sergepetrenko added backport/3.2 Automatically create a 3.2 backport PR backport/3.3 Automatically create a 3.3 backport PR backport/3.4 Automatically create a 3.4 backport PR labels Jul 22, 2025
@coveralls
Copy link

coveralls commented Jul 22, 2025

Coverage Status

coverage: 87.571% (+0.02%) from 87.553%
when pulling 481bd5d on sergepetrenko:gh-11526-privilege-misleading-error
into 8c7cfb1
on tarantool:master
.

@Totktonada Totktonada removed their assignment Jul 22, 2025
@Totktonada
Copy link
Contributor

I would also consider a more general solution (separately from the fix of this particular problem): priv_and, priv_or and priv_not logical function that do the proper type cast on its own. This way anywhere we meet box.priv.ALL, we handle it correctly.

@sergepetrenko sergepetrenko self-assigned this Jul 23, 2025
Trying to revoke privileges from an admin user or a super role results
in misleading errors:
```
error: 'Tuple field 5 (privilege) type does not match one required by operation:
    expected unsigned, got integer'
```

The reason is that privileges use bit module for privilege grant/revoke,
and this module operates 32-bit **signed** integers (see
https://bitop.luajit.org/semantics.html#range for details). So any bit
operation on a privilege set greater than 2^31 (for example,
box.priv.ALL == 2^32 - 1) results in a negative number:

```lua
tarantool> bit.band(box.priv.ALL, bit.bnot(box.priv.W))
---
- -3
...

```

Fortunately, this can be fixed by casting one of the operands to a
uint64_t type, so let's cast all granted or revoked privileges prior to
calculating the resulting privilege set.

Closes tarantool#11526

NO_DOC=bugfix
@sergepetrenko sergepetrenko force-pushed the gh-11526-privilege-misleading-error branch from 52abba1 to 481bd5d Compare July 23, 2025 08:39
@sergepetrenko sergepetrenko added full-ci Enables all tests for a pull request and removed full-ci Enables all tests for a pull request labels Jul 23, 2025
@sergepetrenko sergepetrenko merged commit 8de5bae into tarantool:master Jul 23, 2025
76 of 77 checks passed
@TarantoolBot
Copy link
Collaborator

Successfully created backport PR for release/3.2:

@TarantoolBot
Copy link
Collaborator

Successfully created backport PR for release/3.3:

@TarantoolBot
Copy link
Collaborator

Successfully created backport PR for release/3.4:

@TarantoolBot
Copy link
Collaborator

Backport summary

@sergepetrenko sergepetrenko deleted the gh-11526-privilege-misleading-error branch October 8, 2025 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/3.2 Automatically create a 3.2 backport PR backport/3.3 Automatically create a 3.3 backport PR backport/3.4 Automatically create a 3.4 backport PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

box.schema.user.disable('admin') reports an obscure error

5 participants