【发布时间】:2013-08-26 06:40:42
【问题描述】:
我可以完全访问 Cassandra 安装文件和在 cassandra.yaml 中配置的 PasswordAuthenticator。在保持现有数据库完好无损的情况下,如何重置丢失的管理员用户密码?
【问题讨论】:
我可以完全访问 Cassandra 安装文件和在 cassandra.yaml 中配置的 PasswordAuthenticator。在保持现有数据库完好无损的情况下,如何重置丢失的管理员用户密码?
【问题讨论】:
Cassandra 2.1 的哈希值已更改:
UPDATE system_auth.credentials SET salted_hash = '$2a$10$H46haNkcbxlbamyj0OYZr.v4e5L08WTiQ1scrTs9Q3NYy.6B..x4O' WHERE username='cassandra';【讨论】:
通过以下步骤解决:
cassandra.yaml 中的验证器更改为 AllowAllAuthenticator 并重新启动 Cassandracqlshupdate system_auth.credentials set salted_hash='$2a$10$vbfmLdkQdUz3Rmw.fF7Ygu6GuphqHndpJKTvElqAciUJ4SZ3pwquu' where username='cassandra';cqlsh
现在你可以登录了
cqlsh -u cassandra -p cassandra
并将密码更改为其他密码。
【讨论】:
InvalidRequest: code=2200 [Invalid query] message="unconfigured table credentials"
从 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;验证您的现有用户
编辑
哦,男孩,这会很有趣!所以,我找到了一种 hacktastic 方法,但它需要更改源代码。
首先是高级概述:
第 1 步 - 编辑源代码
打开 C* 源并转到包org.apache.cassandra.service.ClientState;
找到 validateLogin() 和 ensureNotAnonymous() 函数并注释掉所有包含的代码,最终得到:
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");
}
Step2 - 在 cassandra.yaml 中更改为 AllowAllAuthenticator 第 3 步和第 4 步 - 简单! 第 5 步 - 从 cqlsh 执行此插入语句:
insert into system_auth.credentials (username, options, salted_hash)
VALUES ('cassandra', null, '$2a$10$vbfmLdkQdUz3Rmw.fF7Ygu6GuphqHndpJKTvElqAciUJ4SZ3pwquu');
注意* 步骤 5 将在假设已创建名为“cassandra”的用户的情况下工作。如果您创建了另一个用户,只需切换您要插入的用户名(此过程会重置密码,它不会添加新用户)。
第 6 步 通过取消注释 validateLogin() 和 ensureNotAnonymous() 来修复源代码并切换回 cassandra.yaml 中的 PasswordAuthenticator,您现在应该可以通过 ./cqlsh -u cassandra - 访问 cqlsh - p卡桑德拉
【讨论】:
ALTER USER 不是一个选项,因为管理员密码丢失并且我无权访问 cqlsh 控制台。将身份验证器更改为 AllowAllAuthenticator 也无济于事,因为在这种情况下 ALTER USER 即使我可以访问控制台也不起作用。