From 64633eea8c53b672548ede873af314592d2d5800 Mon Sep 17 00:00:00 2001 From: Madelyn Olson Date: Sat, 5 Dec 2026 00:08:16 +0000 Subject: [PATCH 1/2] Refuse queued commands in EXEC once the client is logged out ACL DELUSER of the calling user, or an ACL LOAD that drops it, moves the client to the default user unauthenticated and closes it after the reply. Inside MULTI, EXEC kept running the rest of the queued commands, and its per-command ACL recheck was made against the default user. Commands queued as the deleted user passed their queue-time check, but scripts and SORT BY/GET check ACLs again while they run, so they acted with the default user's permissions, for example writing keys outside the deleted user's key patterns. EXEC now replies NOAUTH to the remaining commands once the client needs to authenticate, the same check processCommand() makes. Clients without a user, like the AOF client, are not subject to it. Signed-off-by: Madelyn Olson --- src/multi.c | 7 ++++- tests/unit/acl.tcl | 73 ++++++++++++++++++++++++++++++++++++++++++++ tests/unit/multi.tcl | 10 ++++++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/src/multi.c b/src/multi.c index fcfe7ae3319..b274dc9ad72 100644 --- a/src/multi.c +++ b/src/multi.c @@ -378,7 +378,12 @@ void execCommand(client *c) { * they were changed after the commands were queued. */ int acl_errpos; int acl_retval = ACLCheckAllPerm(c, &acl_errpos); - if (acl_retval != ACL_OK) { + /* An earlier command may have logged the client out, e.g. ACL DELUSER of + * its own user, so check authentication as processCommand() does. + * Clients without a user, like the AOF client, skip this. */ + if (c->user && authRequired(c) && !(c->cmd->flags & CMD_NO_AUTH)) { + addReplyErrorObject(c, shared.noautherr); + } else if (acl_retval != ACL_OK) { char *reason; switch (acl_retval) { case ACL_DENIED_CMD: reason = "no permission to execute the command or subcommand"; break; diff --git a/tests/unit/acl.tcl b/tests/unit/acl.tcl index e0310368628..decefa1700a 100644 --- a/tests/unit/acl.tcl +++ b/tests/unit/acl.tcl @@ -1752,3 +1752,76 @@ start_server [list overrides [list "dir" $server_path "aclfile" "user.acl"] tags } } } + +set server_path [tmpdir "server.acl-logout"] +set fd [open [file join $server_path "user.acl"] w] +puts $fd "user default on >defpass ~* &* +@all" +close $fd +start_server [list overrides [list "dir" $server_path "aclfile" "user.acl" "requirepass" "defpass"] tags [list "acl external:skip"]] { + test {Commands queued after ACL DELUSER of the calling user do not run as the default user} { + r AUTH default defpass + r SET secret topsecret + r RPUSH app:l 1 + r ACL SETUSER app on >pw ~app:* +@all + test_defer {r DEL secret app:l app:out} + + set rr [valkey [srv "host"] [srv "port"] 0 $::tls] + test_defer {$rr close} + $rr AUTH app pw + assert_error {*ACL failure in script*} {$rr EVAL {return server.call('SET','secret','changed')} 0} + assert_error {*GET option of SORT denied*} {$rr SORT app:l BY nosort GET secret* STORE app:out} + + $rr MULTI + $rr ACL DELUSER app + $rr EVAL {return server.call('SET','secret','changed')} 0 + $rr SORT app:l BY nosort GET secret* STORE app:out + # The client is closed after the ACL DELUSER reply, so EXEC reads EOF. + catch {$rr EXEC} + + assert_equal {topsecret 0} [list [r GET secret] [r EXISTS app:out]] + } + + test {AUTH queued after ACL DELUSER of the calling user still runs} { + r AUTH default defpass + r ACL SETUSER app on >pw ~other:* +@all + r ACL SETUSER other on >pw2 ~other:* +@all + test_defer {r ACL DELUSER app other; r DEL other:k} + + set rr [valkey [srv "host"] [srv "port"] 0 $::tls] + test_defer {$rr close} + $rr AUTH app pw + $rr MULTI + $rr ACL DELUSER app + $rr AUTH other pw2 + $rr SET other:k v + catch {$rr EXEC} + + assert_equal v [r GET other:k] + } + + test {Commands queued after ACL LOAD removes the calling user do not run as the default user} { + r AUTH default defpass + r SET secret topsecret + test_defer {r DEL secret} + set aclfile [file join $server_path "user.acl"] + set fd [open $aclfile w] + puts $fd "user default on >defpass ~* &* +@all" + puts $fd "user app on >pw ~app:* +@all" + close $fd + r ACL LOAD + + set rr [valkey [srv "host"] [srv "port"] 0 $::tls] + test_defer {$rr close} + $rr AUTH app pw + set fd [open $aclfile w] + puts $fd "user default on >defpass ~* &* +@all" + close $fd + + $rr MULTI + $rr ACL LOAD + $rr EVAL {return server.call('SET','secret','changed')} 0 + catch {$rr EXEC} + + assert_equal topsecret [r GET secret] + } +} diff --git a/tests/unit/multi.tcl b/tests/unit/multi.tcl index 4f917ebd54e..c702e362065 100644 --- a/tests/unit/multi.tcl +++ b/tests/unit/multi.tcl @@ -1163,6 +1163,16 @@ start_server {overrides {appendonly {yes} appendfilename {appendonly.aof} append } r get foo } {} + + test {MULTI in AOF is loaded when the default user requires a password} { + test_config_set r requirepass foobar + r multi + r set foo bar + r set foo2 bar2 + r exec + r debug loadaof + r mget foo foo2 + } {bar bar2} } start_cluster 1 0 {tags {"external:skip cluster"}} { From 105e257037d9570567d63d258c1383473292c16b Mon Sep 17 00:00:00 2001 From: Madelyn Olson Date: Fri, 4 Dec 2026 16:50:41 -0800 Subject: [PATCH 2/2] Skip the logout tests on external servers tags [list "acl external:skip"] is a single tag, so the block was not skipped and CONFIG SET aclfile failed on the external server. Signed-off-by: Madelyn Olson --- tests/unit/acl.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/acl.tcl b/tests/unit/acl.tcl index decefa1700a..6d6b4755d14 100644 --- a/tests/unit/acl.tcl +++ b/tests/unit/acl.tcl @@ -1757,7 +1757,7 @@ set server_path [tmpdir "server.acl-logout"] set fd [open [file join $server_path "user.acl"] w] puts $fd "user default on >defpass ~* &* +@all" close $fd -start_server [list overrides [list "dir" $server_path "aclfile" "user.acl" "requirepass" "defpass"] tags [list "acl external:skip"]] { +start_server [list overrides [list "dir" $server_path "aclfile" "user.acl" "requirepass" "defpass"] tags {"acl external:skip"}] { test {Commands queued after ACL DELUSER of the calling user do not run as the default user} { r AUTH default defpass r SET secret topsecret