Skip to content
This repository was archived by the owner on Oct 25, 2026. It is now read-only.

Allow EXEC without conditions from a database the user cannot access - #99

Closed
madolson wants to merge 1 commit into
upstream-unstable-8f67ab136from
fix-exec-acl-db-without-conditions
Closed

madolson wants to merge 1 commit into
upstream-unstable-8f67ab136from
fix-exec-acl-db-without-conditions

Conversation

@madolson

@madolson madolson commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

This is a regression from #4019, first released in 9.2.0-rc1. A user whose ACL only allows db=1 can no longer run MULTI / SELECT 1 / SET x 1 / EXEC from a connection that starts in DB 0, which works in 9.1. EXEC now fails with EXECABORT ... NOPERM No permissions to access database. #4019 gave EXEC key-specs for its new condition keys, so the ACL check treats every EXEC as a keyed command and requires access to the pre-transaction DB, even a bare EXEC that reads nothing from it. Each queued command is still checked against its own DB when it runs, so this only applies the DB check to EXEC when it has arguments.

AI generated details

Problem

ACLSelectorCheckCmd denies any command for which shouldRestrictCmd() is true when the selector cannot access dbid (src/acl.c:2296). shouldRestrictCmd() includes doesCommandHaveKeys(cmd). Before 0adf657 (#4019), EXEC had no key-specs and only the SLOW and TRANSACTION categories, so it was never DB-restricted. #4019 added a key-spec for the IFEQ/IFNE/NX/XX keys, and changed ACLCheckAllPerm to pass c->db->id for EXEC (src/acl.c:2541). That is the DB the client was in before MULTI, because queued SELECTs have not run yet. That DB is correct for condition keys, since checkExecConditions reads them from c->db (src/multi.c:286). It is wrong for a bare EXEC, which reads nothing there. The queued commands are re-checked against their own DB as they run (src/multi.c:380).

The existing #4019 test passes a condition key, so it never checks an EXEC without one.

Affected: 9.2.0-rc1 and the 9.2 branch. In 9.1 and earlier, exec.json has no key-specs and the same transaction succeeds.

Behavior for user db=1 +@all ~*, connection starting in DB 0:

Input Before After
MULTI / SELECT 1 / SET x 1 / EXEC EXECABORT ... NOPERM ... database OK OK
MULTI / EXEC EXECABORT ... NOPERM ... database empty array
EXEC without MULTI EXECABORT ... NOPERM ... database ERR EXEC without MULTI
MULTI / SELECT 1 / SET x 1 / EXEC XX x EXECABORT ... NOPERM ... database unchanged
MULTI / SELECT 1 / SET x 1 / EXEC foo (malformed) EXECABORT ... NOPERM ... database unchanged
SELECT 1 / MULTI / SET x 1 / EXEC OK unchanged

With selectors (db=1 +@all ~*) (db=0 +@all ~public*), EXEC IFEQ secret v from DB 0 is still NOPERM ... key.

Fix

Skip the active-DB check only when the command is EXEC and argc == 1. With any arguments, EXEC stays restricted to the active DB, including malformed ones, which keeps the base behavior.

Alternative considered

Only DB-restrict NO_MANDATORY_KEYS commands when the invocation actually has keys. That would also lift the DB restriction on EVAL, EVALSHA, and FCALL with zero keys, which are DB-restricted today. That is an ACL change to commands this regression does not touch, and it needs its own review.

Testing

New test in tests/unit/acl-v2.tcl. It also checks that EXEC XX <key> from DB 0 is still denied. With only the src/acl.c hunk reverted:

[ok]: EXEC conditions require read permission (4 ms)
[ok]: EXEC condition keys check permissions on the active database (2 ms)
[exception]: Executing test client: EXECABORT Transaction discarded because of: NOPERM No permissions to access database.
 in valkey::__dispatch__ at tests/support/valkey.tcl:116
 in $r2 at tests/unit/acl-v2.tcl:169

Dropping the argc == 1 guard, so that every EXEC skips the check, fails both this test and the existing #4019 test:

[err]: EXEC condition keys check permissions on the active database in tests/unit/acl-v2.tcl
Expected '' to match '*NOPERM*key*'
[err]: EXEC without conditions is not restricted to the active database in tests/unit/acl-v2.tcl
Expected '' to match '*NOPERM*database*'

Based on upstream/unstable 8f67ab136, so the base branch here is upstream-unstable-8f67ab136.

This was generated by AI but verified, with love, by a human.

EXEC gained key-specs for its IFEQ/IFNE/NX/XX condition keys, which makes
the ACL selector check treat it as a keyed command and require access to
the active database. That database is the one the client was in before
MULTI, since queued SELECTs have not run yet. A user restricted to db=1
whose connection starts in DB 0 can therefore no longer run
MULTI / SELECT 1 / ... / EXEC: the EXEC is rejected even though it reads
nothing from DB 0.

Only require access to the active database when EXEC carries arguments.
Condition keys are read from that database and stay restricted, and the
queued commands are still checked against their own database as they run.

Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
@madolson madolson added the promoted Change has been promoted upstream label Oct 25, 2026
@madolson madolson closed this Oct 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

promoted Change has been promoted upstream

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant