hanxi commented on PR #3294:
URL: https://github.com/apache/kvrocks/pull/3294#issuecomment-3668996729

   > Maybe we can make sure that in this mode AUTH will reject any password 
rather than the admin password. (e.g. when namespaces are stored in rocksdb we 
cannot detect if there's no namespace in the startup.)
   
   Is it like this?
   ```c
   class CommandAuth : public Commander {
    public:
     Status Execute([[maybe_unused]] engine::Context &ctx, Server *srv, 
Connection *conn, std::string *output) override {
       auto &user_password = args_[1];
       std::string ns;
       AuthResult result = srv->AuthenticateUser(user_password, &ns);
       switch (result) {
         case AuthResult::NO_REQUIRE_PASS:
           return {Status::RedisExecErr, "Client sent AUTH, but no password is 
set"};
         case AuthResult::INVALID_PASSWORD:
           return {Status::RedisExecErr, "Invalid password"};
         case AuthResult::IS_USER: {
           Config *config = srv->GetConfig();
           if (config->redis_databases > 0) {
             return {Status::RedisExecErr, "namespace AUTH command is not 
allowed when redis-databases > 0"};
           }
           conn->BecomeUser();
           break;
         }
         case AuthResult::IS_ADMIN:
           conn->BecomeAdmin();
           break;
       }
       conn->SetNamespace(ns);
       *output = redis::RESP_OK;
       return Status::OK();
     }
   };
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to