Reputation: 5557
I have full access to the Cassandra installation files and a PasswordAuthenticator configured in cassandra.yaml
. What do I have to do to reset admin user's password that has been lost, while keeping the existing databases intact?
Upvotes: 15
Views: 16396
Reputation: 187
Update for Cassandra 4:
Comment out the following lines
authenticator: PasswordAuthenticator
authorizer: CassandraAuthorizer
and uncomment
#authenticator: AllowAllAuthenticator
#authorizer: AllowAllAuthorizer
UPDATE system_auth.roles SET salted_hash = '$2a$10$H46haNkcbxlbamyj0OYZr.v4e5L08WTiQ1scrTs9Q3NYy.6B..x4O' WHERE role='cassandra';
Upvotes: 4
Reputation: 178
The hash has changed for Cassandra 2.1:
UPDATE system_auth.credentials SET salted_hash = '$2a$10$H46haNkcbxlbamyj0OYZr.v4e5L08WTiQ1scrTs9Q3NYy.6B..x4O' WHERE username='cassandra';
Upvotes: 9
Reputation: 5557
Solved with the following steps:
cassandra.yaml
to AllowAllAuthenticator and restart Cassandracqlsh
update system_auth.credentials set salted_hash='$2a$10$vbfmLdkQdUz3Rmw.fF7Ygu6GuphqHndpJKTvElqAciUJ4SZ3pwquu' where username='cassandra';
cqlsh
Now you can log in with
cqlsh -u cassandra -p cassandra
and change the password to something else.
Upvotes: 8
Reputation: 14173
As of cassandra 2.0
ALTER USER cassandra WITH PASSWORD 'password';
If you want to add a user.
// CREATE USER uname WITH PASSWORD 'password'; // add new user
// GRANT all ON ALL KEYSPACES to uname; // grant permissions to new user
Verify your existing users with LIST USERS;
EDIT
Oh boy, this is gona be fun! So, I found one hacktastic way but it requires changing sourcecode.
First a high level overview:
Step 1 - edit source
Open the C* source and go to package org.apache.cassandra.service.ClientState
;
Find the validateLogin()
and ensureNotAnonymous()
functions and comment all contained coude out so you end up with:
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 - Change to AllowAllAuthenticator in cassandra.yaml Step3 & 4 - Simple! Step 5 - Execute this insert statement from cqlsh:
insert into system_auth.credentials (username, options, salted_hash)
VALUES ('cassandra', null, '$2a$10$vbfmLdkQdUz3Rmw.fF7Ygu6GuphqHndpJKTvElqAciUJ4SZ3pwquu');
Note* step 5 will work assuming the user named 'cassandra' has already been created. If you have another user created just switch the username you are inserting (this procedure resets a password, it doesn't add a new user).
Step 6 Fix the source by uncommenting validateLogin()
and ensureNotAnonymous()
and switch back to the PasswordAuthenticator in cassandra.yaml, you should now have access to cqlsh via ./cqlsh -u cassandra -p cassandra
Upvotes: 5