代码之家  ›  专栏  ›  技术社区  ›  Eemeli Kantola

如何重置丢失的Cassandra管理员用户密码?

  •  15
  • Eemeli Kantola  · 技术社区  · 12 年前

    我可以完全访问Cassandra安装文件和中配置的PasswordAuthenticator cassandra.yaml 。我该怎么做才能重置丢失的管理员用户密码,同时保持现有数据库的完整性?

    3 回复  |  直到 12 年前
        1
  •  9
  •   Gerard de Visser    10 年前

    Cassandra 2.1的哈希已更改:

    1. 切换到验证器:AllowAllAuthenticator
    2. 重新启动cassandra
    3. UPDATE system_auth.credentials SET salted_hash = '$2a$10$H46haNkcbxlbamyj0OYZr.v4e5L08WTiQ1scrTs9Q3NYy.6B..x4O' WHERE username='cassandra';
    4. 切换回验证器:PasswordAuthenticator
    5. 重新启动cassandra
    6. 以cassandra/casandra身份登录
    7. 尽情创建USER和ALTER USER。
        2
  •  8
  •   Eemeli Kantola    12 年前

    通过以下步骤解决:

    1. 更改中的身份验证程序 cassandra.yaml 以AllowAllAuthenticator并重新启动Cassandra
    2. cqlsh
    3. update system_auth.credentials set salted_hash='$2a$10$vbfmLdkQdUz3Rmw.fF7Ygu6GuphqHndpJKTvElqAciUJ4SZ3pwquu' where username='cassandra';
    4. 出口 cqlsh公司
    5. 将authenticator更改回PasswordAuthenticator并重新启动Cassandra

    现在您可以使用登录

    cqlsh -u cassandra -p cassandra
    

    并将密码更改为其他密码。

        3
  •  5
  •   Lyuben Todorov    12 年前

    自cassandra 2.0起

    ALTER USER cassandra WITH PASSWORD 'password';
    

    如果要添加用户。

    // CREATE USER uname WITH PASSWORD 'password'; // add new user
    // GRANT all ON ALL KEYSPACES to uname;    // grant permissions to new user
    

    使用验证您的现有用户 LIST USERS;

    编辑

    哦,天哪,这太有趣了!所以,我找到了一种破解的方法,但它需要更改源代码。

    首先是高级别概述:

    1. 编辑源,以便可以更改system_auth.credentials列族
    2. 将验证器更改为AllowAllAuthenticator
    3. 启动C*
    4. 使用cqlsh登录,无需密码
    5. 更新cassandra用户的哈希密码
    6. 撤消源更改并更改回PasswordAuthenticator。

    步骤1 -编辑来源

    打开C*源代码并转到程序包 org.apache.cassandra.service.ClientState ; 查找 validateLogin() ensureNotAnonymous() 函数和注释都包含coude out,所以您最终会得到:

    public void validateLogin() throws UnauthorizedException
    {
        // if (user == null)
        //    throw new UnauthorizedException("You have not logged in");
    }
    
    public void ensureNotAnonymous() throws UnauthorizedException
    {
        validateLogin();
        // if (user.isAnonymous())
        //    throw new UnauthorizedException("You have to be logged in and not anonymous to perform this request");
    } 
    

    步骤二 -更改为cassandra.yaml中的AllowAllAuthenticator 步骤3&4. -简单! 步骤5 -从cqlsh执行此插入语句:

    insert into system_auth.credentials (username, options, salted_hash) 
    VALUES ('cassandra', null, '$2a$10$vbfmLdkQdUz3Rmw.fF7Ygu6GuphqHndpJKTvElqAciUJ4SZ3pwquu');
    

    注意*假设已经创建了名为“cassandra”的用户,则步骤5将起作用。如果您创建了另一个用户,只需切换您正在插入的用户名(此过程会重置密码,不会添加新用户)。

    步骤6 通过取消注释修复源 验证登录() 确保无匿名() 并切换回cassandra.yaml中的PasswordAuthenticator,您现在应该可以通过访问cqlsh/cqlsh-u卡桑德拉-p卡桑德拉