Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
73 changes: 73 additions & 0 deletions tests/unit/acl.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {"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]
}
}
10 changes: 10 additions & 0 deletions tests/unit/multi.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"}} {
Expand Down
Loading