Repository navigation
Conversation
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 <madelyneolson@gmail.com>
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 <madelyneolson@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If a client deletes its own ACL user inside a transaction, with
MULTI,ACL DELUSER <self>, ...,EXEC, the rest of theEXECruns as thedefaultuser without its password. Deleting the user moves the client todefault, unauthenticated, and closes it after the reply, butEXECkeeps going and rechecks each remaining command againstdefault. Scripts andSORT BY/GETcheck ACLs again while they run, so they getdefault's permissions, for example writing or copying keys outside the deleted user's key patterns.EXECnow refuses the remaining commands withNOAUTHonce the client needs to authenticate again, the same check every command outside a transaction gets. Affects 7.2 and every later release.AI generated details
Problem
ACLFreeUserAndKillClients()switches every client of the deleted user toDefaultUserwithauthenticated = 0and callsfreeClientOrCloseLater()(src/acl.c:590-593).ACL LOADdoes the same for a client whose user is missing from the new file (src/acl.c:3336-3337). For the client running the command, that only setsclose_after_command.The
NOAUTHcheck lives inprocessCommand()(src/server.c:4744), whichEXECdoes not go through for its queued commands.execCommand()only rerunsACLCheckAllPerm(c, ...)(src/multi.c:380), andc->useris nowdefault. A queued command already passed its queue-time check as the original user.EVAL'sserver.call(throughVM_Call,src/module.c:6967) andSORT ... BY/GET(src/sort.c:215) check again at run time, against the client's current user, which isdefault. The replies are dropped because the client is closing, but writes land.SORT ... GET <pattern> STORE <key>copies keys the user cannot read into a key it can.The existing tests didn't catch this. "Delete a user that the client is using" in
tests/unit/acl.tclonly checks that the connection closes. It doesn't run anything after the delete.Introduced by ec1aee0 ("ACL: implement DELUSER", 2019) together with the
EXECrecheck from f4d3717 (2019), so it is in every Valkey release. TheACL LOADvariant came with valkey-io#3800 (9.2.0, and backported to 8.0.10, 8.1.8, 9.0.5 and 9.1.1).defaulthas a passwordACL DELUSER <self>, thenEVALwriting outside the user's patternsNOAUTH, key unchanged (test)ACL DELUSER <self>, thenSORT ... GET secret* STORE app:outapp:outNOAUTH,app:outnot created (test)ACL LOADdropping self, thenEVALwriting outside the patternsNOAUTH, key unchanged (test)ACL DELUSER <self>, thenAUTH other ..., then a write asotherMULTIin the AOF, loaded withrequirepasssetWhen
defaultisnopass,authRequired()is false and the rest of the transaction still runs asdefault. That is unchanged. Any new connection gets the same permissions without a password, so the client gains nothing.Fix
In the
EXECloop, a command that runs after the client needs to authenticate getsNOAUTH, asprocessCommand()would give it.AUTHandHELLOare exempt there and here, so a queuedAUTHstill logs the client in. Clients with no user skip the check. The AOF client hasuser == NULLandauthenticated = 0whenrequirepassis set, so without thec->userguard every transaction in the AOF would fail to load. The newtests/unit/multi.tcltest covers that. With the guard removed it fails onDEBUG LOADAOFwithI/O error reading reply.Alternative considered
default. That fixesEXECtoo, but it changesACL WHOAMI,CLIENT LIST,ACL LOGand module-visible state for every client being closed. The client is unauthenticated, andNOAUTHis the existing answer for that.close_after_reply). Clients get marked to close for reasons that have nothing to do with authentication. SomeACL SETUSERchannel changes andACL LOADclose pub/sub clients without changing their user, so this would refuse commands that are still allowed. The check should match what is actually wrong.Testing
With
src/multi.creverted toa808a77aaand the tests kept,--loops 5:This was generated by AI but verified, with love, by a human.