Skip to content

Commit

Permalink
feat(cmd): add the auth flag for authentication checking (apache#2669)
Browse files Browse the repository at this point in the history
  • Loading branch information
PragmaTwice authored Nov 16, 2024
1 parent cc4f63d commit eb4de5c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/commands/cmd_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ class CommandPollUpdates : public Commander {
Format format_ = Format::Raw;
};

REDIS_REGISTER_COMMANDS(Server, MakeCmdAttr<CommandAuth>("auth", 2, "read-only ok-loading", NO_KEY),
REDIS_REGISTER_COMMANDS(Server, MakeCmdAttr<CommandAuth>("auth", 2, "read-only ok-loading auth", NO_KEY),
MakeCmdAttr<CommandPing>("ping", -1, "read-only", NO_KEY),
MakeCmdAttr<CommandSelect>("select", 2, "read-only", NO_KEY),
MakeCmdAttr<CommandInfo>("info", -1, "read-only ok-loading", NO_KEY),
Expand All @@ -1354,7 +1354,7 @@ REDIS_REGISTER_COMMANDS(Server, MakeCmdAttr<CommandAuth>("auth", 2, "read-only o
MakeCmdAttr<CommandTime>("time", 1, "read-only ok-loading", NO_KEY),
MakeCmdAttr<CommandDisk>("disk", 3, "read-only", 2, 2, 1),
MakeCmdAttr<CommandMemory>("memory", 3, "read-only", 2, 2, 1),
MakeCmdAttr<CommandHello>("hello", -1, "read-only ok-loading", NO_KEY),
MakeCmdAttr<CommandHello>("hello", -1, "read-only ok-loading auth", NO_KEY),
MakeCmdAttr<CommandRestore>("restore", -4, "write", 1, 1, 1),

MakeCmdAttr<CommandCompact>("compact", 1, "read-only no-script", NO_KEY),
Expand Down
4 changes: 4 additions & 0 deletions src/commands/commander.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ enum CommandFlags : uint64_t {
// "blocking" flag, for commands that don't perform db ops immediately,
// but block and wait for some event to happen before performing db ops
kCmdBlocking = 1ULL << 14,
// "auth" flag, for commands used for authentication
kCmdAuth = 1ULL << 15,
};

enum class CommandCategory : uint8_t {
Expand Down Expand Up @@ -328,6 +330,8 @@ inline uint64_t ParseCommandFlags(const std::string &description, const std::str
flags |= kCmdNoDBSizeCheck;
else if (flag == "slow")
flags |= kCmdSlow;
else if (flag == "auth")
flags |= kCmdAuth;
else if (flag == "blocking") {
flags |= kCmdBlocking;

Expand Down
2 changes: 1 addition & 1 deletion src/server/redis_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ void Connection::ExecuteCommands(std::deque<CommandTokens> *to_process_cmds) {

if (GetNamespace().empty()) {
if (!password.empty()) {
if (cmd_name != "auth" && cmd_name != "hello") {
if (!(cmd_flags & kCmdAuth)) {
Reply(redis::Error({Status::RedisNoAuth, "Authentication required."}));
continue;
}
Expand Down

0 comments on commit eb4de5c

Please sign in to comment.