如何重置丢失的Cassandra管理员用户';谁的密码?
我可以完全访问Cassandra安装文件和在如何重置丢失的Cassandra管理员用户';谁的密码?,cassandra,cassandra-2.0,Cassandra,Cassandra 2.0,我可以完全访问Cassandra安装文件和在Cassandra.yaml中配置的密码验证器。如何重置丢失的管理员用户密码,同时保持现有数据库的完整性?从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;
Cassandra.yaml
中配置的密码验证器。如何重置丢失的管理员用户密码,同时保持现有数据库的完整性?从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
使用列表用户验证现有用户代码>
编辑
哦,孩子,这是gona,一定很有趣!所以,我找到了一种黑客方式,但它需要更改源代码
首先是高级别概述:
编辑源,以便可以更改system_auth.credentials列族
将验证器更改为AllowAllAuthenticator
开始C*
使用cqlsh登录,无需密码
更新cassandra用户的哈希密码
撤消源更改并更改回PasswordAuthenticator
步骤1-编辑源代码
打开C*源代码,进入packageorg.apache.cassandra.service.ClientState
;
找到validateLogin()
和ensurentanonymous()
函数,并对其中包含的所有函数进行注释,从而得出以下结论:
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");
}
步骤2-在cassandra.yaml中更改为AllowAllAuthenticator
步骤3和步骤4-简单!
步骤5-从cqlsh执行此insert语句:
insert into system_auth.credentials (username, options, salted_hash)
VALUES ('cassandra', null, '$2a$10$vbfmLdkQdUz3Rmw.fF7Ygu6GuphqHndpJKTvElqAciUJ4SZ3pwquu');
注*假设已创建名为“cassandra”的用户,则步骤5将起作用。如果您创建了另一个用户,只需切换要插入的用户名(此过程重置密码,不会添加新用户)
步骤6通过取消注释validateLogin()
和ensurentanonymous()
来修复源代码,并切换回cassandra.yaml中的密码验证器,您现在应该可以通过./cqlsh-u cassandra-p cassandra访问cqlsh,通过以下步骤解决:
将cassandra.yaml中的验证器更改为AllowAllAuthenticator并重新启动cassandra
cqlsh
updatesystem_auth.credentials set salt_hash='$2a$10$vbfmLdkQdUz3Rmw.ff7ygu6guphqhndpjktvelqaciuj4sz3pwqu'其中username='cassandra'代码>
退出cqlsh
将authenticator更改回PasswordAuthenticator并重新启动Cassandra
现在您可以使用登录
cqlsh -u cassandra -p cassandra
并将密码更改为其他密码。Cassandra 2.1的哈希值已更改:
切换到身份验证程序:AllowAllAuthenticator
重启卡桑德拉
UPDATE system_auth.credentials SET salt_hash='$2a$10$H46haNkcbxlbamyj0OYZr.v4e5L08WTiQ1scrTs9Q3NYy.6B..x4O'其中username='cassandra'代码>
切换回验证器:PasswordAuthenticator
重启卡桑德拉
以cassandra/cassandra身份登录
创建用户并根据您的心意更改用户
ALTER USER
不是一个选项,因为管理员密码已丢失,并且我无法访问cqlsh控制台。另外,将验证器更改为AllowAllAuthenticator也没有帮助,因为在这种情况下,ALTER USER
即使我可以访问控制台也不起作用。@EemeliKantola抱歉,我错误地认为您具有管理员权限访问cqlsh!我发布了一个修复程序,但遗憾的是它需要更改源代码。标题中说明了管理员密码丢失的情况,但为了清晰起见,我编辑了问题正文以重新声明。问题以更简单的方式解决,无需修改代码。我收到以下消息:InvalidRequest:code=2200[无效查询]消息=“未配置的表凭据”
我得到以下信息:InvalidRequest:code=2200[无效查询]消息=“未配置的表凭据”